Download packages/api/src/lib/ownership.ts from Atmint/cpns: direct link, hf CLI and curl.
- Browser
- Download file 550 Bytes
-
https://huggingface.co/spaces/Atmint/cpns/resolve/main/packages/api/src/lib/ownership.ts
- Command line
-
hf download hf://spaces/Atmint/cpns/packages/api/src/lib/ownership.ts
-
curl -L -o ownership.ts https://huggingface.co/spaces/Atmint/cpns/resolve/main/packages/api/src/lib/ownership.ts
550 Bytes
| import { eq } from "drizzle-orm"; | |
| import { throwForbidden, throwNotFound } from "./errors"; | |
| interface OwnedRow { | |
| creatorUserId: string | null; | |
| } | |
| export function assertOwnership(row: OwnedRow | null | undefined, userId: string, resource = "Resource"): void { | |
| if (!row) throwNotFound(resource); | |
| if (row.creatorUserId !== userId) throwForbidden(); | |
| } | |
| export function ownershipFilter<TTable extends Record<string, any>>( | |
| table: TTable, | |
| userId: string, | |
| creatorColumn: keyof TTable, | |
| ) { | |
| return eq(table[creatorColumn as string], userId); | |
| } | |