-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into option-to-hide-bff-endpoints-docs
- Loading branch information
Showing
5 changed files
with
63 additions
and
8 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
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
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
40 changes: 40 additions & 0 deletions
40
packages/worker/src/transformers/string.transformer.spec.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,40 @@ | ||
import { stringTransformer } from "./string.transformer"; | ||
|
||
describe("stringTransformer", () => { | ||
describe("to", () => { | ||
it("returns null for null input", () => { | ||
const result = stringTransformer.to(null); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it("returns empty string for empty string input", () => { | ||
const result = stringTransformer.to(""); | ||
expect(result).toBe(""); | ||
}); | ||
|
||
it("returns a string as it is if there are no 0 bytes", () => { | ||
const str = "abcABCaAbBcC"; | ||
const result = stringTransformer.to(str); | ||
expect(result).toBe(str); | ||
}); | ||
|
||
it("returns a string with 0 bytes removed if there are 0 bytes in string", () => { | ||
const str = "abc\u0000A\u0000BCaAbBcC"; | ||
const result = stringTransformer.to(str); | ||
expect(result).toBe("abcABCaAbBcC"); | ||
}); | ||
}); | ||
|
||
describe("from", () => { | ||
it("returns null for null input", () => { | ||
const result = stringTransformer.from(null); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it("returns input string", () => { | ||
const str = "abcABCaAbBcC"; | ||
const result = stringTransformer.from(str); | ||
expect(result).toStrictEqual(str); | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
import { ValueTransformer } from "typeorm"; | ||
|
||
export const stringTransformer: ValueTransformer = { | ||
to(str: string | null): string | null { | ||
if (!str) { | ||
return str; | ||
} | ||
// remove zero bytes as postgres can't store them in string | ||
return str.replace(/\0/g, ""); | ||
}, | ||
from(str: string): string { | ||
return str; | ||
}, | ||
}; |