Skip to content

Commit dbe1ef1

Browse files
committed
chore: remove unused code
1 parent ae2ed44 commit dbe1ef1

File tree

2 files changed

+1
-104
lines changed

2 files changed

+1
-104
lines changed

packages/shared/filter-commons/src/__tests__/condition-utils.spec.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,9 @@ jest.mock("mendix/filters/builders");
22

33
import { AndCondition, FilterCondition } from "mendix/filters";
44
import { equals, literal } from "mendix/filters/builders";
5-
import {
6-
compactArray,
7-
fromCompactArray,
8-
reduceArray,
9-
reduceMap,
10-
restoreArray,
11-
restoreMap,
12-
tag
13-
} from "../condition-utils";
5+
import { reduceArray, reduceMap, restoreArray, restoreMap, tag } from "../condition-utils";
146

157
describe("condition-utils", () => {
16-
describe("compactArray", () => {
17-
it("returns 'tag' condition for zero array", () => {
18-
const result = compactArray([]);
19-
expect(result).toMatchObject({
20-
name: "!=",
21-
type: "function",
22-
arg1: { value: "[0,[]]", valueType: "String" }
23-
});
24-
});
25-
26-
it("returns 'tag' condition for array of undefined", () => {
27-
const result = compactArray([undefined, undefined, undefined]);
28-
expect(result).toMatchObject({
29-
name: "!=",
30-
type: "function",
31-
arg1: { value: "[3,[]]", valueType: "String" }
32-
});
33-
});
34-
35-
it("returns 'and' condition with 3 args", () => {
36-
const result = compactArray([tag("0"), undefined, tag("2")]);
37-
expect(result).toMatchObject({ name: "and", type: "function" });
38-
expect((result as AndCondition).args).toHaveLength(3);
39-
});
40-
});
41-
42-
describe("fromCompactArray", () => {
43-
it("unpack condition created with compactArray", () => {
44-
const input = [
45-
equals(literal("1"), literal("1")),
46-
undefined,
47-
equals(literal("foo"), literal("bar")),
48-
undefined,
49-
undefined,
50-
equals(literal(new Date("2024-09-17T14:00:00.000Z")), literal(new Date("2024-09-17T14:00:00.000Z")))
51-
];
52-
const cond = compactArray(input);
53-
expect(cond).toBeDefined();
54-
const result = fromCompactArray(cond!);
55-
expect(result).toEqual(input);
56-
});
57-
});
58-
598
describe("reduceMap", () => {
609
it("returns undefined condition and correct metadata for map with undefined values", () => {
6110
const input = { x: undefined, y: undefined };

packages/shared/filter-commons/src/condition-utils.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,10 @@ export function isTag(cond: FilterCondition): cond is TagCond {
7373

7474
type ArrayMeta = readonly [len: number, indexes: number[]];
7575

76-
function arrayTag(meta: ArrayMeta): string {
77-
return JSON.stringify(meta);
78-
}
79-
80-
function fromArrayTag(tag: string): ArrayMeta | undefined {
81-
let len: ArrayMeta[0];
82-
let indexes: ArrayMeta[1];
83-
try {
84-
[len, indexes] = JSON.parse(tag);
85-
} catch {
86-
return undefined;
87-
}
88-
if (typeof len !== "number" || !Array.isArray(indexes) || !indexes.every(x => typeof x === "number")) {
89-
return undefined;
90-
}
91-
return [len, indexes];
92-
}
93-
9476
function shrink<T>(array: Array<T | undefined>): [indexes: number[], items: T[]] {
9577
return [array.flatMap((x, i) => (x === undefined ? [] : [i])), array.filter((x): x is T => x !== undefined)];
9678
}
9779

98-
export function compactArray(input: Array<FilterCondition | undefined>): FilterCondition {
99-
const [indexes, items] = shrink(input);
100-
const metaTag = tag(arrayTag([input.length, indexes] as const));
101-
102-
if (items.length === 0) {
103-
return metaTag;
104-
}
105-
106-
return and(metaTag, ...items);
107-
}
108-
10980
export function reduceArray(
11081
input: Array<FilterCondition | undefined>
11182
): [cond: FilterCondition | undefined, meta: string] {
@@ -203,29 +174,6 @@ export function restoreMap(
203174
return result;
204175
}
205176

206-
export function fromCompactArray(cond: FilterCondition): Array<FilterCondition | undefined> {
207-
const tag = isAnd(cond) ? cond.args[0] : cond;
208-
209-
const arrayMeta = isTag(tag) ? fromArrayTag(tag.arg1.value) : undefined;
210-
211-
if (!arrayMeta) {
212-
return [];
213-
}
214-
215-
const [length, indexes] = arrayMeta;
216-
const arr: Array<FilterCondition | undefined> = Array(length).fill(undefined);
217-
218-
if (!isAnd(cond)) {
219-
return arr;
220-
}
221-
222-
cond.args.slice(1).forEach((cond, i) => {
223-
arr[indexes[i]] = cond;
224-
});
225-
226-
return arr;
227-
}
228-
229177
export function inputStateFromCond<Fn, V>(
230178
cond: FilterCondition,
231179
fn: (func: FilterFunction | "between" | "empty" | "notEmpty") => Fn,

0 commit comments

Comments
 (0)