@zingage/postgres-multi-tenant-ids
Version:
PostgreSQL IDs for secure multi-tenant applications
18 lines (17 loc) • 840 B
JavaScript
import { z } from "zod/v4";
import { stringIsUnscopedId } from "./id-kind-implementations/cross-tenant-entity-ids.js";
import { stringIsTenantId } from "./id-kind-implementations/tenant-ids.js";
import { stringIsScopedId } from "./id-kind-implementations/tenant-scoped-entity-ids.js";
export function makeZodSchemas(_entityConfigs) {
return {
tenantIdSchema: z.custom((val) => typeof val === "string" && stringIsTenantId(val), { message: "Invalid id" }),
unscopedIdSchemaOfType: () => {
return z.custom((val) => typeof val === "string" &&
stringIsUnscopedId(val), { message: "Invalid id" });
},
scopedIdSchemaOfType: () => {
return z.custom((val) => typeof val === "string" &&
stringIsScopedId(val), { message: "Invalid id" });
},
};
}