@valentinkolb/cloud 0.5.3 → 0.5.4
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
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { err, fail, ok, type Result } from "@valentinkolb/stdlib";
|
|
2
2
|
import { sql } from "bun";
|
|
3
|
+
import { toPgUuidArray } from "../../services/postgres";
|
|
3
4
|
|
|
4
5
|
// ==========================
|
|
5
6
|
// Permission Levels
|
|
@@ -85,14 +86,6 @@ type DbAccessUser = {
|
|
|
85
86
|
// Helper Functions
|
|
86
87
|
// ==========================
|
|
87
88
|
|
|
88
|
-
/**
|
|
89
|
-
* Converts UUID strings into a PostgreSQL uuid[] literal for relation queries.
|
|
90
|
-
*/
|
|
91
|
-
const toPgUuidArray = (values: string[] | null | undefined): string => {
|
|
92
|
-
if (!Array.isArray(values) || values.length === 0) return "{}";
|
|
93
|
-
return `{${values.join(",")}}`;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
89
|
const uniqueIds = (values: string[] | null | undefined): string[] => [...new Set((values ?? []).filter(Boolean))];
|
|
97
90
|
|
|
98
91
|
const escapeLikePattern = (value: string): string => value.replace(/[\\%_]/g, (match) => `\\${match}`);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { toPgTextArray as serializePgTextArray } from "../../../services/postgres";
|
|
2
|
+
|
|
1
3
|
export class IpaError extends Error {
|
|
2
4
|
constructor(
|
|
3
5
|
message: string,
|
|
@@ -54,7 +56,4 @@ export const mapIpaErrorCode = (code: number): 400 | 401 | 403 => {
|
|
|
54
56
|
return 400;
|
|
55
57
|
};
|
|
56
58
|
|
|
57
|
-
export const toPgTextArray =
|
|
58
|
-
if (!Array.isArray(values) || values.length === 0) return "{}";
|
|
59
|
-
return `{${values.map((value) => `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`).join(",")}}`;
|
|
60
|
-
};
|
|
59
|
+
export const toPgTextArray = serializePgTextArray;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { toPgTextArray, toPgUuidArray } from "./postgres";
|
|
3
|
+
|
|
4
|
+
describe("Postgres array helpers", () => {
|
|
5
|
+
test("serializes UUID arrays and treats non-arrays as empty arrays", () => {
|
|
6
|
+
expect(toPgUuidArray(["11111111-1111-4111-8111-111111111111", "22222222-2222-4222-8222-222222222222"])).toBe(
|
|
7
|
+
"{11111111-1111-4111-8111-111111111111,22222222-2222-4222-8222-222222222222}",
|
|
8
|
+
);
|
|
9
|
+
expect(toPgUuidArray([])).toBe("{}");
|
|
10
|
+
expect(toPgUuidArray("{}" as unknown as string[])).toBe("{}");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("serializes text arrays with escaping and treats non-arrays as empty arrays", () => {
|
|
14
|
+
expect(toPgTextArray(["alpha", "has space", 'has "quote"', "has\\slash"])).toBe('{"alpha","has space","has \\"quote\\"","has\\\\slash"}');
|
|
15
|
+
expect(toPgTextArray([])).toBe("{}");
|
|
16
|
+
expect(toPgTextArray("{}" as unknown as string[])).toBe("{}");
|
|
17
|
+
});
|
|
18
|
+
});
|