@prisma-next/cli 0.7.0 → 0.8.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/dist/cli.mjs +5 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/exports/init-output.mjs +1 -1
- package/dist/{init-BRKnARU6.mjs → init-B-k3a1Qw.mjs} +337 -205
- package/dist/init-B-k3a1Qw.mjs.map +1 -0
- package/dist/{output-B16Kefzx.mjs → output-BVj6a971.mjs} +3 -3
- package/dist/{output-B16Kefzx.mjs.map → output-BVj6a971.mjs.map} +1 -1
- package/package.json +19 -19
- package/src/commands/init/agent-skill-install.ts +130 -0
- package/src/commands/init/errors.ts +32 -0
- package/src/commands/init/exit-codes.ts +10 -0
- package/src/commands/init/index.ts +9 -1
- package/src/commands/init/init.ts +73 -7
- package/src/commands/init/inputs.ts +23 -0
- package/src/commands/init/output.ts +2 -2
- package/src/commands/init/templates/code-templates.ts +4 -1
- package/dist/agent-skill-mongo.md +0 -138
- package/dist/agent-skill-postgres.md +0 -106
- package/dist/init-BRKnARU6.mjs.map +0 -1
- package/src/commands/init/templates/agent-skill-mongo.md +0 -138
- package/src/commands/init/templates/agent-skill-postgres.md +0 -106
- package/src/commands/init/templates/agent-skill.ts +0 -41
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# Prisma Next — project skill
|
|
2
|
-
|
|
3
|
-
This project uses **Prisma Next** with **PostgreSQL** via `@prisma-next/postgres`. Prisma Next lets the user define data models in a contract file and query them with a fully typed ORM.
|
|
4
|
-
|
|
5
|
-
## Files
|
|
6
|
-
|
|
7
|
-
- **Contract**: `{{schemaPath}}` ({{authoringLabel}} authoring) — the user's data models. Edit this to add or change models.
|
|
8
|
-
- **Config**: `prisma-next.config.ts` — tells the CLI where the contract is and how to connect to the database. Loads `.env` via `dotenv/config`.
|
|
9
|
-
- **Database client**: `{{schemaDir}}/db.ts` — `import { db } from '{{dbImportPath}}'`. This is the entry point for all queries.
|
|
10
|
-
- **Generated files** (do not edit by hand):
|
|
11
|
-
- `{{schemaDir}}/contract.json` — compiled contract, used at runtime
|
|
12
|
-
- `{{schemaDir}}/contract.d.ts` — TypeScript types for the contract, used for autocomplete and type checking
|
|
13
|
-
|
|
14
|
-
## Commands
|
|
15
|
-
|
|
16
|
-
- `{{pkgRun}} contract emit` — regenerate `contract.json` and `contract.d.ts` after changing the contract
|
|
17
|
-
- `{{pkgRun}} db init` — bootstrap a database to match the contract (creates tables, indexes, constraints). Additive only — won't drop existing structures.
|
|
18
|
-
- `{{pkgRun}} db update` — update the database to match the current contract. Prompts for confirmation on destructive changes. Use `--dry-run` to preview.
|
|
19
|
-
- `{{pkgRun}} migration plan` — create a new migration from contract changes (offline, no database needed). Use `--name <slug>` to name it.
|
|
20
|
-
- `{{pkgRun}} migration apply` — apply pending migrations to the database
|
|
21
|
-
- `{{pkgRun}} migration status` — show which migrations are applied and which are pending
|
|
22
|
-
- `{{pkgRun}} migration show <name>` — show details of a specific migration
|
|
23
|
-
|
|
24
|
-
## How to write queries
|
|
25
|
-
|
|
26
|
-
Always use the ORM (`db.orm`). Only fall back to `db.sql` if the user explicitly asks for raw SQL or the ORM doesn't support the operation.
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
import { db } from '{{dbImportPath}}';
|
|
30
|
-
|
|
31
|
-
// Find one record
|
|
32
|
-
const user = await db.orm.User
|
|
33
|
-
.where(user => user.email.eq('alice@example.com'))
|
|
34
|
-
.first();
|
|
35
|
-
// Returns { id: number; email: string; ... } | null
|
|
36
|
-
|
|
37
|
-
// Find multiple records
|
|
38
|
-
const users = await db.orm.User
|
|
39
|
-
.select('id', 'email')
|
|
40
|
-
.take(10)
|
|
41
|
-
.all();
|
|
42
|
-
// Returns Array<{ id: number; email: string }>
|
|
43
|
-
|
|
44
|
-
// Filter, order, limit
|
|
45
|
-
const recentPosts = await db.orm.Post
|
|
46
|
-
.where(post => post.authorId.eq(userId))
|
|
47
|
-
.orderBy(post => post.createdAt.desc())
|
|
48
|
-
.select('id', 'title', 'createdAt')
|
|
49
|
-
.take(50)
|
|
50
|
-
.all();
|
|
51
|
-
|
|
52
|
-
// Include relations
|
|
53
|
-
const usersWithPosts = await db.orm.User
|
|
54
|
-
.select('id', 'email')
|
|
55
|
-
.include('posts', post =>
|
|
56
|
-
post.select('id', 'title').orderBy(p => p.createdAt.desc()).take(5)
|
|
57
|
-
)
|
|
58
|
-
.take(10)
|
|
59
|
-
.all();
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Key ORM methods
|
|
63
|
-
|
|
64
|
-
- `.where(predicate)` — filter records. Predicate receives a model accessor with `.eq()`, `.neq()`, `.ilike()`, `.lt()`, `.gt()`, etc.
|
|
65
|
-
- `.select('field1', 'field2', ...)` — pick which fields to return
|
|
66
|
-
- `.orderBy(accessor => accessor.field.asc()` or `.desc())` — sort results
|
|
67
|
-
- `.take(n)` — limit number of results
|
|
68
|
-
- `.all()` — execute and return all matching records as an array
|
|
69
|
-
- `.first()` — execute and return the first matching record, or `null`
|
|
70
|
-
- `.first({ id: value })` — find a single record by primary key, or `null`
|
|
71
|
-
- `.include('relation', builder => ...)` — eager-load a relation
|
|
72
|
-
|
|
73
|
-
## Rules
|
|
74
|
-
|
|
75
|
-
- **Never hand-edit** `contract.json` or `contract.d.ts`. Always regenerate them with `contract emit`.
|
|
76
|
-
- **Always emit after contract changes.** When you modify `{{schemaPath}}`, run `{{pkgRun}} contract emit` before writing any code that depends on the new or changed models.
|
|
77
|
-
- **Don't restructure `db.ts`.** It's scaffolded by init and works as-is.
|
|
78
|
-
- **Use `db.orm` for queries**, not `db.sql`. The ORM is the primary query surface.
|
|
79
|
-
- **Connection string** is `DATABASE_URL` in `.env`. If the user reports connection errors, check this value and the `.env` file.
|
|
80
|
-
|
|
81
|
-
## Workflow for common tasks
|
|
82
|
-
|
|
83
|
-
**User wants to add a new model or field:**
|
|
84
|
-
1. Edit `{{schemaPath}}`
|
|
85
|
-
2. Run `{{pkgRun}} contract emit`
|
|
86
|
-
3. Write query code using `db.orm.ModelName`
|
|
87
|
-
|
|
88
|
-
**User wants to query data:**
|
|
89
|
-
1. Import `db` from `{{dbImportPath}}`
|
|
90
|
-
2. Use `db.orm.ModelName` with `.where()`, `.select()`, `.all()`, `.first()`, etc.
|
|
91
|
-
|
|
92
|
-
**User wants to set up or change the database connection:**
|
|
93
|
-
1. Edit `DATABASE_URL` in `.env`
|
|
94
|
-
2. The config file (`prisma-next.config.ts`) reads it automatically via `dotenv/config`
|
|
95
|
-
|
|
96
|
-
**User wants to set up the database for the first time:**
|
|
97
|
-
1. Run `{{pkgRun}} db init`
|
|
98
|
-
|
|
99
|
-
**User wants to update the database after changing the contract:**
|
|
100
|
-
1. Quick path: `{{pkgRun}} db update` — compares the database to the contract and applies changes directly
|
|
101
|
-
2. Migration path (for production workflows):
|
|
102
|
-
- `{{pkgRun}} migration plan --name describe-the-change` — creates a migration
|
|
103
|
-
- `{{pkgRun}} migration apply` — applies pending migrations
|
|
104
|
-
|
|
105
|
-
**User wants to check what migrations need to be applied:**
|
|
106
|
-
1. Run `{{pkgRun}} migration status`
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { dirname } from 'pathe';
|
|
2
|
-
import type { AuthoringId, TargetId } from './code-templates';
|
|
3
|
-
import { renderTemplate } from './render';
|
|
4
|
-
|
|
5
|
-
export const variables = [
|
|
6
|
-
'schemaPath',
|
|
7
|
-
'schemaDir',
|
|
8
|
-
'dbImportPath',
|
|
9
|
-
'pkgRun',
|
|
10
|
-
'authoringLabel',
|
|
11
|
-
] as const;
|
|
12
|
-
|
|
13
|
-
type TemplateVars = Record<(typeof variables)[number], string>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Renders the per-project agent skill (FR5.2). The skill template is
|
|
17
|
-
* target-specific (Postgres vs Mongo query syntax differs); the authoring
|
|
18
|
-
* style enters via:
|
|
19
|
-
*
|
|
20
|
-
* - `schemaPath` — already routed through {@link agentSkillMd}'s caller
|
|
21
|
-
* (the AC says a TS-authoring scaffold must reference `prisma/contract.ts`).
|
|
22
|
-
* - `authoringLabel` — a short human-readable note (`PSL` / `TypeScript`)
|
|
23
|
-
* the skill template uses when describing the contract file.
|
|
24
|
-
*/
|
|
25
|
-
export function agentSkillMd(
|
|
26
|
-
target: TargetId,
|
|
27
|
-
authoring: AuthoringId,
|
|
28
|
-
schemaPath: string,
|
|
29
|
-
pkgRun: string,
|
|
30
|
-
): string {
|
|
31
|
-
const schemaDir = dirname(schemaPath);
|
|
32
|
-
const vars: TemplateVars = {
|
|
33
|
-
schemaPath,
|
|
34
|
-
schemaDir,
|
|
35
|
-
dbImportPath: `./${schemaDir}/db`,
|
|
36
|
-
pkgRun,
|
|
37
|
-
authoringLabel: authoring === 'typescript' ? 'TypeScript' : 'PSL',
|
|
38
|
-
};
|
|
39
|
-
const templateFile = `agent-skill-${target}.md`;
|
|
40
|
-
return renderTemplate(templateFile, variables, vars);
|
|
41
|
-
}
|