@pextran/db 0.0.3 → 0.0.5
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/README.md +55 -0
- package/package.json +2 -2
- package/src/README.md +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# `@pextran/db`
|
|
2
|
+
|
|
3
|
+
Database-facing helpers for Pextran: Prisma client typing, auth claims resolution, and repository-style APIs for **approvals** and **media**. Built on `@pextran/core` for DTOs, responses, and shared types.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
In a workspace that already uses the peer stack (Next.js, NextAuth v5, React 18, Zustand 4):
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @pextran/db
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Peers:** `next` ^14, `next-auth` 5.0.0-beta.4, `react` / `react-dom` ^18, `zustand` ^4.
|
|
14
|
+
|
|
15
|
+
**Runtime deps:** `@pextran/core`, `jsonwebtoken`, `pdf-lib`.
|
|
16
|
+
|
|
17
|
+
## How it works
|
|
18
|
+
|
|
19
|
+
The package does **not** create its own Prisma client. It exports an [`IPrisma`](./src/prisma.ts) interface describing the client surface area these modules need (`employee`, `tenant`, `organization`, `role`, `department`, `media`, `approval`, `resourceApproval`, …). Your app’s generated `PrismaClient` satisfies this when passed into the functions.
|
|
20
|
+
|
|
21
|
+
## Public API (barrel: `src/index.ts`)
|
|
22
|
+
|
|
23
|
+
| Area | Exports | Role |
|
|
24
|
+
|------|---------|------|
|
|
25
|
+
| **Prisma typing** | `IPrisma` | Structural type for injectable Prisma used by all helpers below. |
|
|
26
|
+
| **Employees / auth** | `getEmployeeClaims` | Load employee, department, tenant, org, roles; build `AuthClaims` for session/JWT (optionally via org logo from `getOrgLogo`). |
|
|
27
|
+
| **Approvals** | `findApprovalById`, `findApprovalByResourceType`, `getApprovalsForTenant`, `getResourceApprovalsForResource` | Read approval configs and resource-approval rows; return `NexiResponse<…>` from `@pextran/core`. |
|
|
28
|
+
| **Media** | `upsertMedia`, `upsertMedias`, `getOrgLogo`, `moveAndDeleteMedia`, `findMediasForResourceId`, `findMediasForTypeAndResourceId`, `findMediasForTypeAndResourceIdAndCategory`, `findMediaById`, `getMediasForQuery`, `deleteMedia`, `getDeletedMedias`, `hardDeleteMedia` | CRUD/soft-delete and queries for media rows keyed by tenant and resource. |
|
|
29
|
+
|
|
30
|
+
## Usage sketch
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { PrismaClient } from '@prisma/client'
|
|
34
|
+
import { getEmployeeClaims, getOrgLogo, upsertMedia } from '@pextran/db'
|
|
35
|
+
|
|
36
|
+
const prisma = new PrismaClient()
|
|
37
|
+
|
|
38
|
+
// Pass prisma as IPrisma; wrap getOrgLogo for claims:
|
|
39
|
+
const claims = await getEmployeeClaims(
|
|
40
|
+
prisma,
|
|
41
|
+
tenantId,
|
|
42
|
+
email,
|
|
43
|
+
activeRole,
|
|
44
|
+
(orgId) => getOrgLogo(prisma, orgId)
|
|
45
|
+
)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Scripts
|
|
49
|
+
|
|
50
|
+
- `pnpm run build` — Typecheck (`tsc --noEmit`).
|
|
51
|
+
- `pnpm run patch` — Version bump, publish, and tag (maintainer workflow; see `package.json`).
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pextran/db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "pextran DB Utilities",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"access": "restricted"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@pextran/core": "^0.0.
|
|
44
|
+
"@pextran/core": "^0.0.15",
|
|
45
45
|
"jsonwebtoken": "^9.0.2",
|
|
46
46
|
"pdf-lib": "^1.17.1"
|
|
47
47
|
}
|
package/src/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pextran DB Package
|