@prismakit/cli 3.1.0 → 3.2.0
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismakit/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "CLI for PrismaKit — generate modules, validate compose, install agent skills",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"engines": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"README.md"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@prismakit/core": "3.
|
|
32
|
+
"@prismakit/core": "3.2.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@prismakit/core": ">=3.
|
|
35
|
+
"@prismakit/core": ">=3.2.0 <4"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "^5.9.2",
|
|
@@ -52,8 +52,9 @@ Helpers may inject repositories — never the Prisma client.
|
|
|
52
52
|
| Existence / uniqueness / auth | `getFirst` — **no** `setCache` |
|
|
53
53
|
| List | `getMany` + `setCache: true` + optional `cacheTags` |
|
|
54
54
|
| Paginated list | `getManyPaginate` |
|
|
55
|
-
| Large / infinite list | `getManyCursor` |
|
|
55
|
+
| Large / infinite list | `getManyCursor` (with `cursor` → default `skip: 1`) |
|
|
56
56
|
| Count / exists check | `count` / `exists` (no `setCache` on auth paths) |
|
|
57
|
+
| Composite PK row | `id: { a, b }` object — kit maps to Prisma `a_b: { a, b }` |
|
|
57
58
|
| Aggregations | `aggregate` / `groupBy` |
|
|
58
59
|
| Create / update / delete | matching mutation; default invalidation is enough outside tx |
|
|
59
60
|
| Multi-step write | one transaction; pass `tx` into every repo call |
|
|
@@ -124,7 +125,9 @@ await users.getFirst({
|
|
|
124
125
|
| `count` / `exists` | `{ count }` / `{ exists }` |
|
|
125
126
|
| `aggregate` / `groupBy` | Prisma delegate results |
|
|
126
127
|
|
|
127
|
-
`id` is `string` or `Record<string, string>` for composite PKs.
|
|
128
|
+
`id` is `string` or `Record<string, string>` for composite PKs (object form for `@@id([a,b])`).
|
|
129
|
+
|
|
130
|
+
`getManyCursor`: when `cursor` is set, default `skip` is `1` so the cursor row is not repeated. Pass `skip: 0` only for inclusive semantics.
|
|
128
131
|
|
|
129
132
|
## Writes
|
|
130
133
|
|
|
@@ -234,6 +237,11 @@ export default [prismakit.configs.recommended];
|
|
|
234
237
|
|
|
235
238
|
Allowed Prisma usage: `**/repositories/**`, `**/infrastructure/prisma/**`. Rules: `no-prisma-service-outside-repos`, `no-direct-prisma-delegate`, `require-transaction-service`, `require-cached-repo-provider`.
|
|
236
239
|
|
|
240
|
+
## Observability
|
|
241
|
+
|
|
242
|
+
- Core: `setTelemetry({ enabled, onEvent })` or Nest `telemetry` / `queryLog.slowThreshold`.
|
|
243
|
+
- Optional: `@prismakit/opentelemetry` → `createPrismaKitTelemetry({ slowThreshold })`.
|
|
244
|
+
|
|
237
245
|
## Clean code
|
|
238
246
|
|
|
239
247
|
- One repository per Prisma model, file `*.repository.ts` under `repositories/`.
|
|
@@ -241,6 +249,7 @@ Allowed Prisma usage: `**/repositories/**`, `**/infrastructure/prisma/**`. Rules
|
|
|
241
249
|
- Named TTL constants (`const DAY = 86_400`), not magic numbers scattered in call sites.
|
|
242
250
|
- Pass `tx` into **every** repo call in a unit of work. Do not mix cached reads with half-committed writes.
|
|
243
251
|
- Tests: `@prismakit/memory` `MemoryCacheAdapter`. Production: `@prismakit/redis`.
|
|
252
|
+
- Library CI proves PG+Redis paths under `FORCE_INTEGRATION=1` (CRUD, compose, locks, stampede, fail-open).
|
|
244
253
|
|
|
245
254
|
## Anti-patterns (BAD → GOOD)
|
|
246
255
|
|
|
@@ -9,16 +9,18 @@ API surface for `@prismakit/core` 3.x. Read [SKILL.md](SKILL.md) first.
|
|
|
9
9
|
| `@prismakit/core` | `createRepository`, AutoComposer, locks, pagination, `CacheAdapter` |
|
|
10
10
|
| `@prismakit/redis` | `RedisCacheAdapter` |
|
|
11
11
|
| `@prismakit/memory` | `MemoryCacheAdapter` (tests / local) |
|
|
12
|
+
| `@prismakit/opentelemetry` | Map telemetry → OTel metrics/spans |
|
|
12
13
|
| `@prismakit/cli` | `prismakit generate / validate / skills` |
|
|
13
14
|
| `@prismakit/eslint-plugin` | Repository-only data-access rules |
|
|
14
15
|
|
|
15
|
-
Node ≥ 20. Install:
|
|
16
|
+
Node ≥ 20. Line **3.2.x**. Install:
|
|
16
17
|
|
|
17
18
|
```bash
|
|
18
19
|
pnpm add @prismakit/core
|
|
19
20
|
pnpm add @prismakit/redis ioredis # optional production cache
|
|
20
21
|
pnpm add -D @prismakit/eslint-plugin @prismakit/cli
|
|
21
22
|
# tests: pnpm add -D @prismakit/memory
|
|
23
|
+
# optional: pnpm add @prismakit/opentelemetry @opentelemetry/api
|
|
22
24
|
```
|
|
23
25
|
|
|
24
26
|
## Factory
|
|
@@ -40,7 +42,7 @@ Aliases: `defineRepository`, `createPrismaRepository`.
|
|
|
40
42
|
| `cache` | `CacheOptions \| true` | `true` → `{ ttl: 86400, sensitiveFields: ['password'] }`. |
|
|
41
43
|
| `lock` | `true \| string \| RepositoryLockConfig` | `true` / client key / Pascal name / `@@map` table. |
|
|
42
44
|
| `schemaPath` | `string` | Lock/schema helpers when global meta is missing. |
|
|
43
|
-
| `primaryKey` | `string \| string[]` | `*ById` + row locks. Default: meta PK or `id`. |
|
|
45
|
+
| `primaryKey` | `string \| string[]` | `*ById` + row locks. Default: meta PK or `id`. Composite → Prisma `a_b: { a, b }` where. |
|
|
44
46
|
| `getDelegate` | `(client) => delegate` | Default `(c) => c[model]`. |
|
|
45
47
|
| `toPayload` | `(data) => payload` | Default identity. Prefer typed factories over this. |
|
|
46
48
|
|
|
@@ -59,7 +61,7 @@ All methods accept optional `tx`. Cached repos also accept cache fields (see bel
|
|
|
59
61
|
| `getFirst` | `where?`, `select?`, `lock?`, `setCache?`, `cacheTags?` | `T \| null` |
|
|
60
62
|
| `getMany` | `where?`, `select?`, `orderBy?`, `take?`, `skip?`, `lock?`, `setCache?`, `cacheTags?` | `T[]` |
|
|
61
63
|
| `getManyPaginate` | `where?`, `select?`, `orderBy?`, `page?`, `pageSize?`, `setCache?`, `cacheTags?` | `PaginatedResult<T>` |
|
|
62
|
-
| `getManyCursor` | `where?`, `select?`, `orderBy?`, `cursor?`, `take?`, `skip?`, `setCache?`, `cacheTags?` | `CursorPage<T
|
|
64
|
+
| `getManyCursor` | `where?`, `select?`, `orderBy?`, `cursor?`, `take?`, `skip?`, `setCache?`, `cacheTags?` | `CursorPage<T>`; with `cursor`, default `skip: 1` |
|
|
63
65
|
| `count` | `where?`, `select?`, `setCache?`, `cacheTags?` | `{ count: number }` |
|
|
64
66
|
| `exists` | `where?`, `setCache?`, `cacheTags?` | `{ exists: boolean }` |
|
|
65
67
|
| `aggregate` | Prisma aggregate args + `setCache?`, `cacheTags?` | delegate result |
|
|
@@ -196,8 +196,8 @@ Repository `cache` is the source of truth. Omit `cacheModels` (fail-open). Pass
|
|
|
196
196
|
| `validateCompose: true` | Assert compose-safe selects on boot |
|
|
197
197
|
| `strictCachedRepos` | Fail boot if a `cache` repo class is not in Nest `providers` (default `true`) |
|
|
198
198
|
| `compose` | `{ maxDepth, parallel, setCache }` |
|
|
199
|
-
| `telemetry` | `{ enabled: true, onEvent }` |
|
|
200
|
-
| `queryLog` | `{ slowThreshold, onSlowQuery }` — enables telemetry |
|
|
199
|
+
| `telemetry` | `{ enabled: true, onEvent }` or `createPrismaKitTelemetry()` from `@prismakit/opentelemetry` |
|
|
200
|
+
| `queryLog` | `{ slowThreshold, onSlowQuery }` — enables telemetry / `query.slow` |
|
|
201
201
|
| `autoRegisterModels` | `true` or `string[]` — stub repos for compose-only models |
|
|
202
202
|
|
|
203
203
|
## Scaffolding
|
|
@@ -205,12 +205,15 @@ Repository `cache` is the source of truth. Omit `cacheModels` (fail-open). Pass
|
|
|
205
205
|
```bash
|
|
206
206
|
npx prismakit generate product --cache
|
|
207
207
|
npx prismakit generate product --cache --full --route products
|
|
208
|
+
npx prismakit skills # refresh .cursor/skills after upgrades
|
|
208
209
|
```
|
|
209
210
|
|
|
210
211
|
Repo-only: add the class to feature `providers`. `--full`: import `*Module` in `AppModule`. Then `npx prismakit validate`.
|
|
211
212
|
|
|
212
213
|
Enable ESLint `prismakit.configs.recommended` (see skill `prismakit`).
|
|
213
214
|
|
|
215
|
+
Reference app: [starter-prismakit-nestjs](https://github.com/fikiap23/starter-prismakit-nestjs) (Nest 11 + Prisma 7 + Redis).
|
|
216
|
+
|
|
214
217
|
## Clean code (Nest)
|
|
215
218
|
|
|
216
219
|
- One `defineRepo` binder under `src/infrastructure/prisma/`. Do not call `createDefineRepo` per feature.
|