@webiny/db-utils 6.6.0-alpha.0 → 6.6.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -8
- package/__tests__/valueFilter/__mocks/registry.ts +0 -8
- package/__tests__/valueFilter/andIn.test.ts +0 -56
- package/__tests__/valueFilter/between.test.ts +0 -62
- package/__tests__/valueFilter/contains.test.ts +0 -74
- package/__tests__/valueFilter/eq.test.ts +0 -42
- package/__tests__/valueFilter/fuzzy.test.ts +0 -30
- package/__tests__/valueFilter/gt.test.ts +0 -47
- package/__tests__/valueFilter/gte.test.ts +0 -50
- package/__tests__/valueFilter/in.test.ts +0 -54
- package/__tests__/valueFilter/lt.test.ts +0 -47
- package/__tests__/valueFilter/lte.test.ts +0 -49
- package/__tests__/valueFilter/startsWith.test.ts +0 -58
- package/dist/package.json +0 -24
- package/src/index.ts +0 -4
- package/src/valueFilter/ValueFilterRegistry.ts +0 -21
- package/src/valueFilter/abstractions/ValueFilter.ts +0 -29
- package/src/valueFilter/abstractions/ValueFilterRegistry.ts +0 -15
- package/src/valueFilter/abstractions/index.ts +0 -2
- package/src/valueFilter/feature.ts +0 -31
- package/src/valueFilter/filters/AndInFilter.ts +0 -36
- package/src/valueFilter/filters/BetweenFilter.ts +0 -37
- package/src/valueFilter/filters/ContainsFilter.ts +0 -87
- package/src/valueFilter/filters/EqFilter.ts +0 -32
- package/src/valueFilter/filters/FuzzyFilter.ts +0 -42
- package/src/valueFilter/filters/GtFilter.ts +0 -22
- package/src/valueFilter/filters/GteFilter.ts +0 -22
- package/src/valueFilter/filters/InFilter.ts +0 -36
- package/src/valueFilter/filters/LtFilter.ts +0 -22
- package/src/valueFilter/filters/LteFilter.ts +0 -22
- package/src/valueFilter/filters/StartsWithFilter.ts +0 -44
- package/src/valueFilter/index.ts +0 -3
- package/tsconfig.build.json +0 -21
- package/tsconfig.json +0 -18
- package/vitest.config.ts +0 -5
- package/webiny.config.js +0 -8
- /package/{dist/LICENSE → LICENSE} +0 -0
- /package/{dist/README.md → README.md} +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/valueFilter → valueFilter}/ValueFilterRegistry.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/ValueFilterRegistry.js +0 -0
- /package/{dist/valueFilter → valueFilter}/ValueFilterRegistry.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/ValueFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/ValueFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/ValueFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/ValueFilterRegistry.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/ValueFilterRegistry.js +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/ValueFilterRegistry.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/index.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/abstractions/index.js +0 -0
- /package/{dist/valueFilter → valueFilter}/feature.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/feature.js +0 -0
- /package/{dist/valueFilter → valueFilter}/feature.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/AndInFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/AndInFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/AndInFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/BetweenFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/BetweenFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/BetweenFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/ContainsFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/ContainsFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/ContainsFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/EqFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/EqFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/EqFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/FuzzyFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/FuzzyFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/FuzzyFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/GtFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/GtFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/GtFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/GteFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/GteFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/GteFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/InFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/InFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/InFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/LtFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/LtFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/LtFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/LteFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/LteFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/LteFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/StartsWithFilter.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/StartsWithFilter.js +0 -0
- /package/{dist/valueFilter → valueFilter}/filters/StartsWithFilter.js.map +0 -0
- /package/{dist/valueFilter → valueFilter}/index.d.ts +0 -0
- /package/{dist/valueFilter → valueFilter}/index.js +0 -0
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
export interface IValueFilterCanUseParams<TValue = any, TCompareValue = any> {
|
|
4
|
-
value: TValue;
|
|
5
|
-
compareValue: TCompareValue;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface IValueFilterMatchesParams<TValue = any, TCompareValue = any> {
|
|
9
|
-
value: TValue;
|
|
10
|
-
compareValue: TCompareValue;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type IValueFilterMatchesResult = boolean;
|
|
14
|
-
|
|
15
|
-
export interface IValueFilter<TValue = any, TCompareValue = any> {
|
|
16
|
-
readonly operation: string;
|
|
17
|
-
is(operation: string): boolean;
|
|
18
|
-
canUse(params: IValueFilterCanUseParams): boolean;
|
|
19
|
-
matches(params: IValueFilterMatchesParams<TValue, TCompareValue>): IValueFilterMatchesResult;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const ValueFilter = createAbstraction<IValueFilter>("Db/ValueFilter");
|
|
23
|
-
|
|
24
|
-
export namespace ValueFilter {
|
|
25
|
-
export type Interface<TValue = any, TCompareValue = any> = IValueFilter<TValue, TCompareValue>;
|
|
26
|
-
export type CanUseParams = IValueFilterCanUseParams;
|
|
27
|
-
export type MatchesParams = IValueFilterMatchesParams;
|
|
28
|
-
export type Result = IValueFilterMatchesResult;
|
|
29
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
import type { ValueFilter } from "./ValueFilter.js";
|
|
3
|
-
|
|
4
|
-
export interface IValueFilterRegistry {
|
|
5
|
-
get(operation: string): ValueFilter.Interface | undefined;
|
|
6
|
-
getAll(): ValueFilter.Interface[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const ValueFilterRegistry =
|
|
10
|
-
createAbstraction<IValueFilterRegistry>("Db/ValueFilterRegistry");
|
|
11
|
-
|
|
12
|
-
export namespace ValueFilterRegistry {
|
|
13
|
-
export type Interface = IValueFilterRegistry;
|
|
14
|
-
export type Filter = ValueFilter.Interface;
|
|
15
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createFeature } from "@webiny/feature/api";
|
|
2
|
-
import { EqFilter } from "./filters/EqFilter.js";
|
|
3
|
-
import { GtFilter } from "./filters/GtFilter.js";
|
|
4
|
-
import { GteFilter } from "./filters/GteFilter.js";
|
|
5
|
-
import { LtFilter } from "./filters/LtFilter.js";
|
|
6
|
-
import { LteFilter } from "./filters/LteFilter.js";
|
|
7
|
-
import { BetweenFilter } from "./filters/BetweenFilter.js";
|
|
8
|
-
import { InFilter } from "./filters/InFilter.js";
|
|
9
|
-
import { AndInFilter } from "./filters/AndInFilter.js";
|
|
10
|
-
import { ContainsFilter } from "./filters/ContainsFilter.js";
|
|
11
|
-
import { FuzzyFilter } from "./filters/FuzzyFilter.js";
|
|
12
|
-
import { StartsWithFilter } from "./filters/StartsWithFilter.js";
|
|
13
|
-
import { ValueFilterRegistry } from "./ValueFilterRegistry.js";
|
|
14
|
-
|
|
15
|
-
export const ValueFilterFeature = createFeature({
|
|
16
|
-
name: "Db/ValueFilterFeature",
|
|
17
|
-
register: container => {
|
|
18
|
-
container.register(EqFilter);
|
|
19
|
-
container.register(GtFilter);
|
|
20
|
-
container.register(GteFilter);
|
|
21
|
-
container.register(LtFilter);
|
|
22
|
-
container.register(LteFilter);
|
|
23
|
-
container.register(BetweenFilter);
|
|
24
|
-
container.register(InFilter);
|
|
25
|
-
container.register(AndInFilter);
|
|
26
|
-
container.register(ContainsFilter);
|
|
27
|
-
container.register(FuzzyFilter);
|
|
28
|
-
container.register(StartsWithFilter);
|
|
29
|
-
container.register(ValueFilterRegistry);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { WebinyError } from "@webiny/error";
|
|
2
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
3
|
-
|
|
4
|
-
class AndInFilterImpl implements ValueFilter.Interface {
|
|
5
|
-
public readonly operation = "and_in";
|
|
6
|
-
|
|
7
|
-
public is(operation: string): boolean {
|
|
8
|
-
return this.operation === operation;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public canUse(): boolean {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
16
|
-
if (!compareValue || Array.isArray(compareValue) === false) {
|
|
17
|
-
throw new WebinyError(
|
|
18
|
-
`The value given as "compareValue" must be an array!`,
|
|
19
|
-
"COMPARE_VALUE_ERROR",
|
|
20
|
-
{
|
|
21
|
-
value,
|
|
22
|
-
compareValue
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(value) === true) {
|
|
27
|
-
return compareValue.every((c: any) => value.includes(c));
|
|
28
|
-
}
|
|
29
|
-
return compareValue.includes(value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const AndInFilter = ValueFilter.createImplementation({
|
|
34
|
-
implementation: AndInFilterImpl,
|
|
35
|
-
dependencies: []
|
|
36
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { WebinyError } from "@webiny/error";
|
|
2
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
3
|
-
|
|
4
|
-
class BetweenFilterImpl implements ValueFilter.Interface {
|
|
5
|
-
public readonly operation = "between";
|
|
6
|
-
|
|
7
|
-
public is(operation: string): boolean {
|
|
8
|
-
return this.operation === operation;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public canUse(): boolean {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
16
|
-
if (Array.isArray(compareValue)) {
|
|
17
|
-
if (compareValue.length !== 2) {
|
|
18
|
-
throw new WebinyError(
|
|
19
|
-
"When comparing between and you give an array, there must be two items in it.",
|
|
20
|
-
"FILTER_ERROR",
|
|
21
|
-
{
|
|
22
|
-
value,
|
|
23
|
-
compareValue
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
const [from, to] = compareValue;
|
|
28
|
-
return value >= from && value <= to;
|
|
29
|
-
}
|
|
30
|
-
return value >= compareValue && value <= compareValue;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const BetweenFilter = ValueFilter.createImplementation({
|
|
35
|
-
implementation: BetweenFilterImpl,
|
|
36
|
-
dependencies: []
|
|
37
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
-
|
|
3
|
-
const createValues = (initialValue: string | string[] | object): string[] => {
|
|
4
|
-
if (typeof initialValue === "string") {
|
|
5
|
-
return [initialValue];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (Array.isArray(initialValue)) {
|
|
9
|
-
return initialValue
|
|
10
|
-
.flat()
|
|
11
|
-
.map(v => v.toString())
|
|
12
|
-
.filter(Boolean);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const result: string[] = [];
|
|
16
|
-
|
|
17
|
-
const traverse = (node: any): void => {
|
|
18
|
-
if (node == null) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (typeof node === "string" || typeof node === "number") {
|
|
22
|
-
result.push(node.toString());
|
|
23
|
-
} else if (Array.isArray(node)) {
|
|
24
|
-
node.forEach(traverse);
|
|
25
|
-
} else if (typeof node === "object") {
|
|
26
|
-
Object.values(node).forEach(traverse);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
traverse(initialValue);
|
|
31
|
-
|
|
32
|
-
return result.filter(Boolean);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const escapeRegex = (value: string): string => {
|
|
36
|
-
return value.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&");
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const createCompareValues = (value: string) => {
|
|
40
|
-
return value
|
|
41
|
-
.replace(/\s+/g, " ")
|
|
42
|
-
.trim()
|
|
43
|
-
.replace(/:/g, "")
|
|
44
|
-
.split(" ")
|
|
45
|
-
.filter(val => {
|
|
46
|
-
return val.length > 0;
|
|
47
|
-
})
|
|
48
|
-
.map(escapeRegex);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
class ContainsFilterImpl implements ValueFilter.Interface {
|
|
52
|
-
public readonly operation = "contains";
|
|
53
|
-
|
|
54
|
-
public is(operation: string): boolean {
|
|
55
|
-
return this.operation === operation;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public canUse(): boolean {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public matches({
|
|
63
|
-
value: initialValue,
|
|
64
|
-
compareValue: initialCompareValue
|
|
65
|
-
}: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
66
|
-
if (!initialValue || (Array.isArray(initialValue) && initialValue.length === 0)) {
|
|
67
|
-
return false;
|
|
68
|
-
} else if (initialCompareValue === undefined || initialCompareValue === null) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
const values = createValues(initialValue);
|
|
72
|
-
const compareValues = createCompareValues(initialCompareValue);
|
|
73
|
-
if (compareValues.length === 0) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
return values.some(target => {
|
|
77
|
-
return compareValues.every(compareValue => {
|
|
78
|
-
return target.match(new RegExp(compareValue, "gi")) !== null;
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const ContainsFilter = ValueFilter.createImplementation({
|
|
85
|
-
implementation: ContainsFilterImpl,
|
|
86
|
-
dependencies: []
|
|
87
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
-
|
|
3
|
-
class EqFilterImpl implements ValueFilter.Interface {
|
|
4
|
-
public readonly operation = "eq";
|
|
5
|
-
|
|
6
|
-
public is(operation: string): boolean {
|
|
7
|
-
return this.operation === operation;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public canUse(): boolean {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
15
|
-
/* Possibility that either input value or one from the system is array. */
|
|
16
|
-
if (Array.isArray(value) === true) {
|
|
17
|
-
return value.some((v: string) => {
|
|
18
|
-
return Array.isArray(compareValue) ? compareValue.includes(v) : compareValue === v;
|
|
19
|
-
});
|
|
20
|
-
} else if (Array.isArray(compareValue) === true) {
|
|
21
|
-
return compareValue.every((v: string) => {
|
|
22
|
-
return value == v;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return value == compareValue;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const EqFilter = ValueFilter.createImplementation({
|
|
30
|
-
implementation: EqFilterImpl,
|
|
31
|
-
dependencies: []
|
|
32
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import Fuse from "fuse.js";
|
|
2
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
3
|
-
|
|
4
|
-
class FuzzyFilterImpl implements ValueFilter.Interface<string | null | undefined> {
|
|
5
|
-
public readonly operation = "fuzzy";
|
|
6
|
-
|
|
7
|
-
public is(operation: string): boolean {
|
|
8
|
-
return this.operation === operation;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public canUse(): boolean {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public matches({
|
|
16
|
-
value: initialValue,
|
|
17
|
-
compareValue: initialCompareValue
|
|
18
|
-
}: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
19
|
-
if (typeof initialValue !== "string" || typeof initialCompareValue !== "string") {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
const value = initialValue.replaceAll("/", " ");
|
|
23
|
-
const compareValue = initialCompareValue.replaceAll("/", " ");
|
|
24
|
-
|
|
25
|
-
const f = new Fuse([value], {
|
|
26
|
-
includeScore: true,
|
|
27
|
-
minMatchCharLength: 3,
|
|
28
|
-
threshold: 0.5,
|
|
29
|
-
isCaseSensitive: false,
|
|
30
|
-
findAllMatches: true,
|
|
31
|
-
ignoreLocation: true
|
|
32
|
-
});
|
|
33
|
-
const result = f.search(compareValue);
|
|
34
|
-
|
|
35
|
-
return result.length > 0;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const FuzzyFilter = ValueFilter.createImplementation({
|
|
40
|
-
implementation: FuzzyFilterImpl,
|
|
41
|
-
dependencies: []
|
|
42
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
-
|
|
3
|
-
class GtFilterImpl implements ValueFilter.Interface {
|
|
4
|
-
public readonly operation = "gt";
|
|
5
|
-
|
|
6
|
-
public is(operation: string): boolean {
|
|
7
|
-
return this.operation === operation;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public canUse(): boolean {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
15
|
-
return value > compareValue;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const GtFilter = ValueFilter.createImplementation({
|
|
20
|
-
implementation: GtFilterImpl,
|
|
21
|
-
dependencies: []
|
|
22
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
-
|
|
3
|
-
class GteFilterImpl implements ValueFilter.Interface {
|
|
4
|
-
public readonly operation = "gte";
|
|
5
|
-
|
|
6
|
-
public is(operation: string): boolean {
|
|
7
|
-
return this.operation === operation;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public canUse(): boolean {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
15
|
-
return value >= compareValue;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const GteFilter = ValueFilter.createImplementation({
|
|
20
|
-
implementation: GteFilterImpl,
|
|
21
|
-
dependencies: []
|
|
22
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { WebinyError } from "@webiny/error";
|
|
2
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
3
|
-
|
|
4
|
-
class InFilterImpl implements ValueFilter.Interface {
|
|
5
|
-
public readonly operation = "in";
|
|
6
|
-
|
|
7
|
-
public is(operation: string): boolean {
|
|
8
|
-
return this.operation === operation;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public canUse(): boolean {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
16
|
-
if (!compareValue || Array.isArray(compareValue) === false) {
|
|
17
|
-
throw new WebinyError(
|
|
18
|
-
`The value given as "compareValue" must be an array!`,
|
|
19
|
-
"COMPARE_VALUE_ERROR",
|
|
20
|
-
{
|
|
21
|
-
value,
|
|
22
|
-
compareValue
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(value) === true) {
|
|
27
|
-
return compareValue.some((c: any) => value.includes(c));
|
|
28
|
-
}
|
|
29
|
-
return compareValue.includes(value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const InFilter = ValueFilter.createImplementation({
|
|
34
|
-
implementation: InFilterImpl,
|
|
35
|
-
dependencies: []
|
|
36
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
-
|
|
3
|
-
class LtFilterImpl implements ValueFilter.Interface {
|
|
4
|
-
public readonly operation = "lt";
|
|
5
|
-
|
|
6
|
-
public is(operation: string): boolean {
|
|
7
|
-
return this.operation === operation;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public canUse(): boolean {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
15
|
-
return value < compareValue;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const LtFilter = ValueFilter.createImplementation({
|
|
20
|
-
implementation: LtFilterImpl,
|
|
21
|
-
dependencies: []
|
|
22
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
-
|
|
3
|
-
class LteFilterImpl implements ValueFilter.Interface {
|
|
4
|
-
public readonly operation = "lte";
|
|
5
|
-
|
|
6
|
-
public is(operation: string): boolean {
|
|
7
|
-
return this.operation === operation;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public canUse(): boolean {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
15
|
-
return value <= compareValue;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const LteFilter = ValueFilter.createImplementation({
|
|
20
|
-
implementation: LteFilterImpl,
|
|
21
|
-
dependencies: []
|
|
22
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
-
|
|
3
|
-
class StartsWithFilterImpl implements ValueFilter.Interface {
|
|
4
|
-
public readonly operation = "startsWith";
|
|
5
|
-
|
|
6
|
-
public is(operation: string): boolean {
|
|
7
|
-
return this.operation === operation;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public canUse({ compareValue }: ValueFilter.CanUseParams): boolean {
|
|
11
|
-
if (compareValue === "" || compareValue === null || compareValue === undefined) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {
|
|
18
|
-
/* Match null/undefined values. */
|
|
19
|
-
if (
|
|
20
|
-
(value === null && compareValue === null) ||
|
|
21
|
-
(value === undefined && compareValue === undefined)
|
|
22
|
-
) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
/* We do "case-insensitive" comparison. */
|
|
26
|
-
const compareValueInLowerCase = compareValue.toLowerCase();
|
|
27
|
-
|
|
28
|
-
if (typeof value !== "string") {
|
|
29
|
-
if (Array.isArray(value) === true) {
|
|
30
|
-
return value.some((v: string) => {
|
|
31
|
-
return v.toLowerCase().startsWith(compareValueInLowerCase);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return value.toLowerCase().startsWith(compareValueInLowerCase);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const StartsWithFilter = ValueFilter.createImplementation({
|
|
42
|
-
implementation: StartsWithFilterImpl,
|
|
43
|
-
dependencies: []
|
|
44
|
-
});
|
package/src/valueFilter/index.ts
DELETED
package/tsconfig.build.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.build.json",
|
|
3
|
-
"include": ["src"],
|
|
4
|
-
"references": [
|
|
5
|
-
{ "path": "../error/tsconfig.build.json" },
|
|
6
|
-
{ "path": "../feature/tsconfig.build.json" }
|
|
7
|
-
],
|
|
8
|
-
"compilerOptions": {
|
|
9
|
-
"rootDir": "./src",
|
|
10
|
-
"outDir": "./dist",
|
|
11
|
-
"declarationDir": "./dist",
|
|
12
|
-
"paths": {
|
|
13
|
-
"~/*": ["./src/*"],
|
|
14
|
-
"~tests/*": ["./__tests__/*"],
|
|
15
|
-
"@webiny/error/*": ["../error/src/*"],
|
|
16
|
-
"@webiny/error": ["../error/src"],
|
|
17
|
-
"@webiny/feature/*": ["../feature/src/*"],
|
|
18
|
-
"@webiny/feature": ["../feature/src"]
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"include": ["src", "__tests__"],
|
|
4
|
-
"references": [{ "path": "../error" }, { "path": "../feature" }],
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"rootDirs": ["./src", "./__tests__"],
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"declarationDir": "./dist",
|
|
9
|
-
"paths": {
|
|
10
|
-
"~/*": ["./src/*"],
|
|
11
|
-
"~tests/*": ["./__tests__/*"],
|
|
12
|
-
"@webiny/error/*": ["../error/src/*"],
|
|
13
|
-
"@webiny/error": ["../error/src"],
|
|
14
|
-
"@webiny/feature/*": ["../feature/src/*"],
|
|
15
|
-
"@webiny/feature": ["../feature/src"]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
package/vitest.config.ts
DELETED
package/webiny.config.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|