-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TS - add flat, flatten, form, formparse, isnull
- Loading branch information
Showing
18 changed files
with
492 additions
and
41 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
50 changes: 50 additions & 0 deletions
50
javascript/json-transform/src/__tests__/functions/TransformerFunctionFlat.test.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,50 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionFlat", () => { | ||
test("object", async () => { | ||
const arr = ["a", "b", "c"]; | ||
const arr2 = ["d", "e", "f"]; | ||
const arr3 = [arr, arr2]; | ||
const flatCombined = arr3.flatMap(x => x); | ||
const flatArr = arr.slice(); | ||
await assertTransformation( | ||
arr3, | ||
{ | ||
$$flat: ["$[0]", "$[1]"], | ||
}, | ||
flatCombined, | ||
); | ||
await assertTransformation( | ||
arr3, | ||
{ | ||
$$flat: ["$[0]", "$.pointingToNowhere"], | ||
}, | ||
flatArr, | ||
); | ||
await assertTransformation( | ||
arr3, | ||
{ | ||
$$flat: [ | ||
["a", "b", "c"], | ||
["d", "e", "f"], | ||
], | ||
}, | ||
flatCombined, | ||
); | ||
await assertTransformation( | ||
arr, | ||
{ | ||
$$flat: [["a", "b", "c"], []], | ||
}, | ||
flatArr, | ||
); | ||
await assertTransformation( | ||
arr, | ||
{ | ||
$$flat: [["a", "b", "c"], null], | ||
}, | ||
flatArr, | ||
); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
javascript/json-transform/src/__tests__/functions/TransformerFunctionFlatten.test.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,36 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionFlat", () => { | ||
test("object", async () => { | ||
const arr = { value: "bbb" }; | ||
await assertTransformation( | ||
arr, | ||
{ | ||
$$flatten: { a: { a1: 123, a2: [1, 2, 3, { c: true }] }, b: "$.value" }, | ||
array_prefix: "\\$", | ||
}, | ||
{ "a.a1": 123, "a.a2.$0": 1, "a.a2.$1": 2, "a.a2.$2": 3, "a.a2.$3.c": true, b: "bbb" }, | ||
); | ||
|
||
await assertTransformation( | ||
arr, | ||
{ | ||
$$flatten: { a: { a1: 123, a2: [1, 2, 3, { c: true }] }, b: "$.value" }, | ||
prefix: "xxx", | ||
array_prefix: "", | ||
}, | ||
{ "xxx.a.a1": 123, "xxx.a.a2.0": 1, "xxx.a.a2.1": 2, "xxx.a.a2.2": 3, "xxx.a.a2.3.c": true, "xxx.b": "bbb" }, | ||
); | ||
|
||
await assertTransformation( | ||
arr, | ||
{ | ||
$$flatten: { a: { a1: 123, a2: [1, 2, 3, { c: true }] }, b: "$.value" }, | ||
prefix: "xxx", | ||
array_prefix: "#null", | ||
}, | ||
{ "xxx.a.a1": 123, "xxx.a.a2": [1, 2, 3, { c: true }], "xxx.b": "bbb" }, | ||
); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
javascript/json-transform/src/__tests__/functions/TransformerFunctionForm.test.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,48 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionCsv", () => { | ||
test("inline", async () => { | ||
await assertTransformation( | ||
{ | ||
a: 1, | ||
b: "B", | ||
c: true, | ||
}, | ||
"$$form:$", | ||
"a=1&b=B&c=true", | ||
); | ||
|
||
// arrays | ||
await assertTransformation( | ||
{ | ||
a: [1, 2], | ||
c: true, | ||
}, | ||
"$$form:$", | ||
"a=1&a=2&c=true", | ||
); | ||
}); | ||
|
||
test("object", async () => { | ||
await assertTransformation( | ||
{ | ||
a: 1, | ||
b: "B", | ||
c: true, | ||
}, | ||
{ $$form: "$" }, | ||
"a=1&b=B&c=true", | ||
); | ||
|
||
// arrays | ||
await assertTransformation( | ||
{ | ||
a: [1, 2], | ||
c: true, | ||
}, | ||
{ $$form: "$" }, | ||
"a=1&a=2&c=true", | ||
); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
javascript/json-transform/src/__tests__/functions/TransformerFunctionFormParse.test.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,46 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionCsv", () => { | ||
test("inline", async () => { | ||
await assertTransformation("a=1&b=B&c", "$$formparse:$", { | ||
a: "1", | ||
a$$: ["1"], | ||
b: "B", | ||
b$$: ["B"], | ||
c: "true", | ||
c$$: ["true"], | ||
}); | ||
|
||
// arrays | ||
await assertTransformation("a=1&a=2", "$$formparse:$", { | ||
a: "1", | ||
a$$: ["1", "2"], | ||
}); | ||
}); | ||
|
||
test("object", async () => { | ||
await assertTransformation( | ||
"a=1&b=B&c", | ||
{ $$formparse: "$" }, | ||
{ | ||
a: "1", | ||
a$$: ["1"], | ||
b: "B", | ||
b$$: ["B"], | ||
c: "true", | ||
c$$: ["true"], | ||
}, | ||
); | ||
|
||
// arrays | ||
await assertTransformation( | ||
"a=1&a=2", | ||
{ $$formparse: "$" }, | ||
{ | ||
a: "1", | ||
a$$: ["1", "2"], | ||
}, | ||
); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
javascript/json-transform/src/__tests__/functions/TransformerFunctionIsNull.test.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,12 @@ | ||
import { describe, test } from "vitest"; | ||
import { assertTransformation } from "../BaseTransformationTest"; | ||
|
||
describe("TransformerFunctionIsNull", () => { | ||
test("nullTest", async () => { | ||
await assertTransformation(null, "$$isnull:$", true); | ||
await assertTransformation(undefined, "$$isnull:$", true); | ||
await assertTransformation(0, "$$isnull():$", false); | ||
await assertTransformation("", "$$isnull:$", false); | ||
await assertTransformation(false, "$$isnull:$", false); | ||
}); | ||
}); |
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,3 +1,3 @@ | ||
export interface FormatDeserializer { | ||
deserialize(input: string): Record<string, any>; | ||
} | ||
deserialize(input: string | null): any; | ||
} |
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,3 +1,3 @@ | ||
export interface FormatSerializer { | ||
serialize(payload: any): string; | ||
} | ||
serialize(payload: any): string | null; | ||
} |
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.