caspian-utils 0.0.6 → 0.0.8
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/docs/commands.md +16 -5
- package/dist/docs/components.md +34 -0
- package/dist/docs/database.md +24 -11
- package/dist/docs/index.md +1 -1
- package/dist/docs/project-structure.md +2 -0
- package/package.json +1 -1
package/dist/docs/commands.md
CHANGED
|
@@ -21,7 +21,7 @@ The current workspace includes a local `prisma` binary, but it does not include
|
|
|
21
21
|
Use Caspian CLI commands for three main tasks:
|
|
22
22
|
|
|
23
23
|
- Create a new application.
|
|
24
|
-
-
|
|
24
|
+
- Regenerate Node and Python ORM code from your Prisma schema.
|
|
25
25
|
- Update framework-managed project files.
|
|
26
26
|
|
|
27
27
|
Before running update commands, review `caspian.config.json` because it controls overwrite behavior.
|
|
@@ -60,15 +60,23 @@ Common scaffold flags include:
|
|
|
60
60
|
|
|
61
61
|
## Code Generation
|
|
62
62
|
|
|
63
|
-
When
|
|
63
|
+
When `prisma/schema.prisma` changes in this workspace, use this command flow:
|
|
64
64
|
|
|
65
65
|
```bash
|
|
66
|
+
npx prisma migrate dev
|
|
67
|
+
|
|
68
|
+
# If the change requires refreshed seed data:
|
|
66
69
|
npx prisma generate
|
|
70
|
+
npx prisma db seed
|
|
71
|
+
|
|
72
|
+
npx ppy generate
|
|
67
73
|
```
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
Use `npx prisma migrate dev` first so the development database and migration history stay aligned. If the updated schema affects seed data, run `npx prisma generate` before `npx prisma db seed` so Node-side tooling such as `prisma/seed.ts` uses the current generated client.
|
|
76
|
+
|
|
77
|
+
Always finish with `npx ppy generate`. That is the required way to refresh the Python ORM classes used by the app after a schema change.
|
|
70
78
|
|
|
71
|
-
This workspace already includes an app-owned Python database layer in `src/lib/prisma/`, so reuse that package for Python-side database access instead of creating a second helper.
|
|
79
|
+
This workspace already includes an app-owned Python database layer in `src/lib/prisma/`, so reuse that package for Python-side database access instead of creating a second helper. Do not hand-edit generated ORM classes.
|
|
72
80
|
|
|
73
81
|
See `database.md` for the full Prisma workflow, including `.env`, `prisma.config.ts`, migrations, and async usage patterns.
|
|
74
82
|
|
|
@@ -113,7 +121,10 @@ If an AI agent is deciding which command flow to use, apply these rules first.
|
|
|
113
121
|
- Use `npx create-caspian-app@latest` when the user is creating a new project.
|
|
114
122
|
- Use `npx casp update project` only for an existing Caspian project.
|
|
115
123
|
- Read `caspian.config.json` before running update commands.
|
|
116
|
-
-
|
|
124
|
+
- When `prisma/schema.prisma` changes, run `npx prisma migrate dev` first.
|
|
125
|
+
- If the change requires seed data, run `npx prisma generate` and then `npx prisma db seed`.
|
|
126
|
+
- Run `npx ppy generate` after every Prisma schema change to refresh the Python ORM classes.
|
|
127
|
+
- Never hand-edit generated Prisma or Python ORM classes.
|
|
117
128
|
- Check `database.md` when the task involves Prisma setup, schema updates, or the current workspace's schema, migration, and seed tooling.
|
|
118
129
|
- Check [routing.md](./routing.md) before generating or modifying route folders under `src/app/`.
|
|
119
130
|
- Check [project-structure.md](./project-structure.md) before placing generated files into the project.
|
package/dist/docs/components.md
CHANGED
|
@@ -70,6 +70,8 @@ Treat `<!-- @import ... -->` as a file-level directive, not as rendered markup.
|
|
|
70
70
|
- `<!-- @import Container from "../components" -->` resolves `Container.py` from that folder.
|
|
71
71
|
- The component function name should match the tag name you render, such as `Container` for `<Container />`.
|
|
72
72
|
- Grouped imports and aliases are also supported, for example `<!-- @import { Button, Card as UserCard } from "../components/ui" -->`.
|
|
73
|
+
- If one Python file exports several `@component` functions, point `from` at that exact file instead of assuming one file per tag.
|
|
74
|
+
- In that case, prefer one grouped import so every rendered tag resolves back to the same Python module.
|
|
73
75
|
|
|
74
76
|
Good:
|
|
75
77
|
|
|
@@ -92,6 +94,38 @@ Bad:
|
|
|
92
94
|
</section>
|
|
93
95
|
```
|
|
94
96
|
|
|
97
|
+
### Same-File Component Exports
|
|
98
|
+
|
|
99
|
+
Caspian does not require one Python file per component. A single file can export a main component plus related subcomponents.
|
|
100
|
+
|
|
101
|
+
If `Breadcrumb.py` defines `Breadcrumb`, `BreadcrumbList`, `BreadcrumbItem`, `BreadcrumbLink`, `BreadcrumbPage`, and `BreadcrumbSeparator`, import those names from `Breadcrumb.py` itself.
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<!-- @import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "../maddex/Breadcrumb.py" -->
|
|
105
|
+
|
|
106
|
+
<div class="dashboard-topbar">
|
|
107
|
+
<Breadcrumb class="dashboard-breadcrumbs" aria-label="Dashboard breadcrumbs">
|
|
108
|
+
<BreadcrumbList class="dashboard-breadcrumbs__list">
|
|
109
|
+
<BreadcrumbItem class="dashboard-breadcrumbs__item">
|
|
110
|
+
<BreadcrumbLink href="/dashboard">Dashboard</BreadcrumbLink>
|
|
111
|
+
</BreadcrumbItem>
|
|
112
|
+
<BreadcrumbSeparator class="dashboard-breadcrumbs__separator" />
|
|
113
|
+
<BreadcrumbItem class="dashboard-breadcrumbs__item">
|
|
114
|
+
<BreadcrumbPage class="dashboard-breadcrumbs__page">Reports</BreadcrumbPage>
|
|
115
|
+
</BreadcrumbItem>
|
|
116
|
+
</BreadcrumbList>
|
|
117
|
+
</Breadcrumb>
|
|
118
|
+
</div>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
If you only need one component from that file, keep the same file path:
|
|
122
|
+
|
|
123
|
+
```html
|
|
124
|
+
<!-- @import Breadcrumb from "../maddex/Breadcrumb.py" -->
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Do not invent folder-level imports for symbols that do not have their own file. If `BreadcrumbItem` lives inside `Breadcrumb.py`, import it from `Breadcrumb.py`, not from `../maddex` as if `BreadcrumbItem.py` existed.
|
|
128
|
+
|
|
95
129
|
## Template-Backed Components
|
|
96
130
|
|
|
97
131
|
When a component includes richer UI or PulsePoint behavior, keep the Python file focused on props or server-side preparation and move the markup into a same-name HTML file.
|
package/dist/docs/database.md
CHANGED
|
@@ -22,9 +22,10 @@ The standard Prisma flow in Caspian is:
|
|
|
22
22
|
|
|
23
23
|
1. Define models in `prisma/schema.prisma`.
|
|
24
24
|
2. Configure `DATABASE_URL` in `.env`.
|
|
25
|
-
3. Run `npx prisma
|
|
26
|
-
4.
|
|
27
|
-
5.
|
|
25
|
+
3. Run `npx prisma migrate dev` after schema changes so the development database and migration history stay aligned.
|
|
26
|
+
4. If the change requires seed data, run `npx prisma generate` and then `npx prisma db seed`.
|
|
27
|
+
5. Run `npx ppy generate` so the Python ORM classes stay aligned with the updated schema.
|
|
28
|
+
6. Reuse the shared Python database layer in `src/lib/prisma/` when Python route or RPC code needs database access, and never hand-edit generated ORM classes.
|
|
28
29
|
|
|
29
30
|
Use this workflow instead of writing raw SQL first. Drop to raw SQL only when a query cannot be expressed clearly with the generated client.
|
|
30
31
|
|
|
@@ -99,22 +100,30 @@ model Post {
|
|
|
99
100
|
}
|
|
100
101
|
```
|
|
101
102
|
|
|
102
|
-
After changing the schema,
|
|
103
|
+
After changing the schema, use this order in the current workspace:
|
|
104
|
+
|
|
105
|
+
1. Run `npx prisma migrate dev`.
|
|
106
|
+
2. If seed data or the seed script needs the new schema, run `npx prisma generate` and then `npx prisma db seed`.
|
|
107
|
+
3. Run `npx ppy generate` to refresh the generated Python ORM classes.
|
|
108
|
+
|
|
109
|
+
Do not hand-edit generated Prisma or Python ORM output. Treat `prisma/schema.prisma` as the source of truth and regenerate from it.
|
|
103
110
|
|
|
104
111
|
## Command Reference
|
|
105
112
|
|
|
106
113
|
Use these commands for the normal Prisma lifecycle in Caspian:
|
|
107
114
|
|
|
108
|
-
- `npx prisma
|
|
109
|
-
- `npx prisma
|
|
115
|
+
- `npx prisma migrate dev` creates and applies a development migration. This is the first command to run after changing `prisma/schema.prisma`.
|
|
116
|
+
- `npx prisma generate` compiles `schema.prisma` into the generated Node Prisma client. Run it before `npx prisma db seed` when the updated seed flow depends on the new schema.
|
|
117
|
+
- `npx prisma db seed` runs the configured seeding script.
|
|
118
|
+
- `npx ppy generate` regenerates the Python ORM classes used by the app. Use this after every schema change.
|
|
110
119
|
- `npx prisma migrate deploy` applies pending migrations in deployment environments.
|
|
111
120
|
- `npx prisma db push` syncs schema changes without creating a migration file, which is useful for prototyping.
|
|
112
|
-
- `npx prisma db seed` runs the configured seeding script.
|
|
113
121
|
- `npx prisma studio` opens the Prisma data browser.
|
|
114
122
|
|
|
115
123
|
Default rule:
|
|
116
124
|
|
|
117
|
-
-
|
|
125
|
+
- When `prisma/schema.prisma` changes, use this order: `npx prisma migrate dev`; if seeding is involved, run `npx prisma generate` and `npx prisma db seed`; then run `npx ppy generate`.
|
|
126
|
+
- Never hand-edit generated Prisma or Python ORM classes, and never replace `npx ppy generate` with a manual class update.
|
|
118
127
|
- Use migrations for tracked application changes.
|
|
119
128
|
- Use `db push` only when you intentionally want a faster, migration-free prototype loop.
|
|
120
129
|
|
|
@@ -142,7 +151,7 @@ After `npx prisma generate`, Prisma writes the generated JavaScript client into
|
|
|
142
151
|
|
|
143
152
|
This workspace already includes an app-owned async Python database package that exports `prisma`, `PrismaClient`, generated models, and helper types.
|
|
144
153
|
|
|
145
|
-
If Python route or RPC code needs database access, import from `src.lib.prisma` and keep that import path explicit in application code.
|
|
154
|
+
If Python route or RPC code needs database access, import from `src.lib.prisma` and keep that import path explicit in application code. Refresh generated classes with `npx ppy generate` instead of editing them manually.
|
|
146
155
|
|
|
147
156
|
## Python Route Usage
|
|
148
157
|
|
|
@@ -306,8 +315,9 @@ Use raw SQL sparingly. Prefer the generated Prisma API when the query can be exp
|
|
|
306
315
|
|
|
307
316
|
## Recommended Project Rules
|
|
308
317
|
|
|
309
|
-
- Keep the schema in `prisma/schema.prisma` and
|
|
318
|
+
- Keep the schema in `prisma/schema.prisma` and follow the required regeneration order after changes: `npx prisma migrate dev`, optional seed flow, then `npx ppy generate`.
|
|
310
319
|
- Reuse `src/lib/prisma/` for Python-side database access instead of creating a second bridge.
|
|
320
|
+
- Never hand-edit generated Prisma or Python ORM classes.
|
|
311
321
|
- Keep reusable database helpers in `src/lib/`, and keep route-specific orchestration in `src/app/`.
|
|
312
322
|
- Use `await` with Prisma operations.
|
|
313
323
|
- Convert Prisma objects to template-safe dictionaries when rendering HTML.
|
|
@@ -320,7 +330,10 @@ If an AI agent is working on a Caspian app with Prisma enabled, apply these rule
|
|
|
320
330
|
|
|
321
331
|
- Treat Prisma as the default ORM and persistence layer.
|
|
322
332
|
- Read `prisma/schema.prisma` before proposing model, relation, or field changes.
|
|
323
|
-
-
|
|
333
|
+
- When `prisma/schema.prisma` changes, run `npx prisma migrate dev` first.
|
|
334
|
+
- If the schema change requires seed data, run `npx prisma generate` and then `npx prisma db seed`.
|
|
335
|
+
- Run `npx ppy generate` after schema changes to refresh the Python ORM classes.
|
|
336
|
+
- Never hand-edit generated Prisma or Python ORM classes.
|
|
324
337
|
- Read `prisma.config.ts` and `prisma/seed.ts` when you need the current workspace's Prisma tooling examples.
|
|
325
338
|
- Reuse the existing `src/lib/prisma/` package when the Python app needs database access.
|
|
326
339
|
- Put reusable database helpers in `src/lib/`; keep route and RPC orchestration in `src/app/`.
|
package/dist/docs/index.md
CHANGED
|
@@ -58,7 +58,7 @@ Preferred lookup order:
|
|
|
58
58
|
1. Read `node_modules/caspian-utils/dist/docs/index.md` to discover available local docs.
|
|
59
59
|
2. Read `./caspian.config.json` before making any feature assumption. Use it to confirm which project capabilities are enabled and which directories or tooling rules apply.
|
|
60
60
|
3. Read `database.md` for Prisma setup and ORM usage, `auth.md` for session auth and route protection, `components.md` for reusable UI authoring, `pulsepoint.md` for browser-side reactive runtime behavior, `fetch-data.md` for data flows, `state.md` for transient request-scoped state, `cache.md` for page caching, and `validation.md` for input boundaries.
|
|
61
|
-
4. For authored component, route, and layout HTML files, generate exactly one top-level lowercase HTML element. Think React-style single parent wrapper: keep any owned PulsePoint logic in a plain `<script>` inside that root, do not handwrite `pp-component="..."` or `type="text/pp"` because Caspian injects those runtime attributes automatically, and treat `<!-- @import ... -->` comments as file-level directives that belong above the authored root element instead of inside `<div>`, `<section>`, or `<html>`.
|
|
61
|
+
4. For authored component, route, and layout HTML files, generate exactly one top-level lowercase HTML element. Think React-style single parent wrapper: keep any owned PulsePoint logic in a plain `<script>` inside that root, do not handwrite `pp-component="..."` or `type="text/pp"` because Caspian injects those runtime attributes automatically, and treat `<!-- @import ... -->` comments as file-level directives that belong above the authored root element instead of inside `<div>`, `<section>`, or `<html>`. When several component tags come from one Python file, import them from that exact file path, for example `<!-- @import { Breadcrumb, BreadcrumbItem, BreadcrumbList } from "../components/Breadcrumb.py" -->`.
|
|
62
62
|
5. Prefer local docs before generating code, commands, or migration guidance.
|
|
63
63
|
6. Check `node_modules/caspian-utils/dist/docs/` for packaged Caspian docs when local docs need more detail.
|
|
64
64
|
7. Only fall back to upstream documentation when local and packaged markdown do not cover the topic.
|
|
@@ -98,6 +98,8 @@ Use this folder for reusable UI components that should be imported into route te
|
|
|
98
98
|
|
|
99
99
|
The common Caspian pattern is a Python file such as `Button.py` with `@component`, optionally paired with a same-name HTML file such as `Button.html` when the component has richer markup or PulsePoint behavior.
|
|
100
100
|
|
|
101
|
+
One Python file can also export multiple related `@component` functions. When that happens, import those tags from that exact file path in HTML, for example `<!-- @import { Breadcrumb, BreadcrumbItem, BreadcrumbList } from "../components/Breadcrumb.py" -->`, instead of assuming each tag has its own sibling `.py` file.
|
|
102
|
+
|
|
101
103
|
For component HTML files, follow the same one-parent rule as route HTML files: one top-level lowercase HTML element only, with no sibling roots and no top-level script sitting outside that root.
|
|
102
104
|
|
|
103
105
|
Do not handwrite `pp-component="..."` or `type="text/pp"` in component source templates either. Write plain `<script>` inside the single root and let the render pipeline inject the runtime shape.
|