@prismakit/cli 3.2.0 → 3.2.1
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 +11 -11
- package/skills/prismakit/SKILL.md +7 -6
- package/skills/prismakit-nestjs/SKILL.md +41 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismakit/cli",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "CLI for PrismaKit — generate modules, validate compose, install agent skills",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"engines": {
|
|
@@ -28,8 +28,15 @@
|
|
|
28
28
|
"LICENSE",
|
|
29
29
|
"README.md"
|
|
30
30
|
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
35
|
+
"lint": "tsc -p tsconfig.json --noEmit",
|
|
36
|
+
"clean": "rm -rf dist"
|
|
37
|
+
},
|
|
31
38
|
"dependencies": {
|
|
32
|
-
"@prismakit/core": "
|
|
39
|
+
"@prismakit/core": "workspace:*"
|
|
33
40
|
},
|
|
34
41
|
"peerDependencies": {
|
|
35
42
|
"@prismakit/core": ">=3.2.0 <4"
|
|
@@ -56,12 +63,5 @@
|
|
|
56
63
|
"prismakit",
|
|
57
64
|
"cursor",
|
|
58
65
|
"skills"
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
"build": "tsup",
|
|
62
|
-
"test": "vitest run",
|
|
63
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
64
|
-
"lint": "tsc -p tsconfig.json --noEmit",
|
|
65
|
-
"clean": "rm -rf dist"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
@@ -64,7 +64,7 @@ Helpers may inject repositories — never the Prisma client.
|
|
|
64
64
|
## Create a repository (core)
|
|
65
65
|
|
|
66
66
|
```typescript
|
|
67
|
-
import {
|
|
67
|
+
import { PrismaClient } from '@prisma/client';
|
|
68
68
|
import { createRepository } from '@prismakit/core';
|
|
69
69
|
import { RedisCacheAdapter } from '@prismakit/redis';
|
|
70
70
|
|
|
@@ -72,9 +72,8 @@ const DAY = 86_400;
|
|
|
72
72
|
|
|
73
73
|
const UserRepoClass = createRepository({
|
|
74
74
|
model: 'user',
|
|
75
|
-
scalarFields: Prisma.UserScalarFieldEnum,
|
|
76
75
|
cache: { ttl: DAY, nullTtl: 60, sensitiveFields: ['password'] },
|
|
77
|
-
lock: true, // table + columns from Prisma meta
|
|
76
|
+
lock: true, // table + columns resolved from Prisma schema meta
|
|
78
77
|
});
|
|
79
78
|
|
|
80
79
|
const prisma = new PrismaClient();
|
|
@@ -84,14 +83,16 @@ export const users = new UserRepoClass({ prisma, cache });
|
|
|
84
83
|
|
|
85
84
|
`defineRepository` and `createPrismaRepository` are aliases of `createRepository`.
|
|
86
85
|
|
|
86
|
+
**NestJS apps:** use `createDefineRepo` / `defineAppRepo` with app-wide cache defaults instead — see skill `prismakit-nestjs`.
|
|
87
|
+
|
|
87
88
|
| Option | Description |
|
|
88
89
|
|--------|-------------|
|
|
89
90
|
| `model` | Prisma client key (`prisma.user` → `'user'`). Needed for cache + compose. |
|
|
90
|
-
| `scalarFields` | Usually `Prisma.XScalarFieldEnum`.
|
|
91
|
-
| `cache` | `CacheOptions` or `true`
|
|
91
|
+
| `scalarFields` | Usually `Prisma.XScalarFieldEnum`. **Optional** when `schemaPath` / DMMF meta is loaded (default since 3.1). |
|
|
92
|
+
| `cache` | `CacheOptions` or `true` (uses app defaults when bound via `createDefineRepo`). |
|
|
92
93
|
| `lock` | `true` / client key / `@@map` table / `{ tableName, columns }`. |
|
|
93
94
|
| `primaryKey` | Override only. Defaults to schema `@id` / `@@id` (composite `string[]`) or `id`. |
|
|
94
|
-
| `schemaPath` | Path to `schema.prisma` when meta is not loaded globally. |
|
|
95
|
+
| `schemaPath` | Path to `schema.prisma` when meta is not loaded globally. Default: `prisma/schema.prisma`. |
|
|
95
96
|
| `getDelegate` | Optional. Defaults to `(c) => c[model]`. |
|
|
96
97
|
|
|
97
98
|
Put files under `**/repositories/**`. Keep Prisma client construction under `**/infrastructure/prisma/**`.
|
|
@@ -45,37 +45,65 @@ export class AppModule {}
|
|
|
45
45
|
|
|
46
46
|
## Factory (one default)
|
|
47
47
|
|
|
48
|
-
Bind `Prisma.TypeMap` once, then define repos with
|
|
48
|
+
Bind `Prisma.TypeMap` once with app-wide cache defaults, then define repos with per-model overrides only.
|
|
49
49
|
|
|
50
50
|
```typescript
|
|
51
|
-
// src/infrastructure/prisma/define-repo.ts
|
|
51
|
+
// src/infrastructure/prisma/define-app-repo.ts
|
|
52
52
|
import { createDefineRepo } from '@prismakit/nestjs';
|
|
53
|
-
import type { Prisma } from '@prisma/client';
|
|
53
|
+
import type { Prisma } from '@prisma/client'; // or generated client path
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const DAY = 86_400;
|
|
56
|
+
|
|
57
|
+
export const defineAppRepo = createDefineRepo<Prisma.TypeMap>({
|
|
58
|
+
cache: {
|
|
59
|
+
ttl: DAY,
|
|
60
|
+
nullTtl: 60,
|
|
61
|
+
defaultSetCache: true,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
56
64
|
```
|
|
57
65
|
|
|
58
66
|
```typescript
|
|
59
67
|
// src/modules/users/repositories/user.repository.ts
|
|
60
|
-
import {
|
|
61
|
-
import { defineRepo } from '../../../infrastructure/prisma/define-repo';
|
|
68
|
+
import { defineAppRepo } from 'src/infrastructure/prisma/define-app-repo';
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export class UserRepository extends defineRepo({
|
|
70
|
+
export class UserRepository extends defineAppRepo({
|
|
66
71
|
model: 'user',
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
cache: {
|
|
73
|
+
defaultSetCache: false, // auth lookups pass setCache explicitly
|
|
74
|
+
sensitiveFields: ['password'],
|
|
75
|
+
methods: { getFirst: { enabled: false } },
|
|
76
|
+
},
|
|
77
|
+
}) {}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// src/modules/category/repositories/category.repository.ts
|
|
82
|
+
import { defineAppRepo } from 'src/infrastructure/prisma/define-app-repo';
|
|
83
|
+
|
|
84
|
+
export class CategoryRepository extends defineAppRepo({
|
|
85
|
+
model: 'category',
|
|
86
|
+
cache: true, // inherits app-wide defaults (ttl, nullTtl, defaultSetCache)
|
|
70
87
|
}) {}
|
|
71
88
|
```
|
|
72
89
|
|
|
90
|
+
```typescript
|
|
91
|
+
// Uncached repo — TypeScript omits setCache / invalidateCache
|
|
92
|
+
import { defineAppRepo } from 'src/infrastructure/prisma/define-app-repo';
|
|
93
|
+
|
|
94
|
+
export class AuditLogRepository extends defineAppRepo({
|
|
95
|
+
model: 'auditLog',
|
|
96
|
+
}) {}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`scalarFields` is **optional** when `schemaPath` or DMMF meta is loaded (default since 3.1). Omit it in new repos.
|
|
100
|
+
|
|
73
101
|
Escape hatches (do not use as the app default):
|
|
74
102
|
|
|
75
103
|
- `defineInjectableRepository` from `@prismakit/nestjs` (package alias `defineRepository`) — phantoms + payload HKT when TypeMap is unavailable.
|
|
76
104
|
- `createInjectableRepository` without a types bag — thin, results are `unknown`. Alias: `createPrismaRepository`.
|
|
77
105
|
|
|
78
|
-
Do not import `defineRepo` from `@prismakit/nestjs` in apps that already bind `createDefineRepo` as `
|
|
106
|
+
Do not import `defineRepo` from `@prismakit/nestjs` in apps that already bind `createDefineRepo` as `defineAppRepo`.
|
|
79
107
|
|
|
80
108
|
## Register and inject
|
|
81
109
|
|