prisma-php 0.0.10 → 0.0.12

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.
@@ -0,0 +1,189 @@
1
+ ---
2
+ title: Swagger docs for APIs
3
+ nav_title: Swagger Docs
4
+ description: Learn when Prisma PHP Swagger docs are worth enabling so AI agents can keep OpenAPI generation aligned with backendOnly and schema-driven workflows.
5
+ related:
6
+ title: API Reference
7
+ description: Read the official Swagger and API docs together with the local Prisma PHP guidance.
8
+ links:
9
+ - /docs/swagger-docs-api
10
+ - /docs/api-get-started
11
+ - /docs/route-php
12
+ - /docs/orm-get-started
13
+ ---
14
+
15
+ ## Swagger docs in Prisma PHP
16
+
17
+ Prisma PHP can generate Swagger-friendly OpenAPI documentation for API workflows.
18
+
19
+ This is most useful when the project exposes endpoints for:
20
+
21
+ - a separate frontend
22
+ - mobile clients
23
+ - public or partner APIs
24
+ - SDK generation
25
+ - API testing and contract review
26
+
27
+ If the application is mainly a server-rendered Prisma PHP app that uses PulsePoint and `pp.fetchFunction(...)` for route-local interactions, Swagger docs may not be necessary.
28
+
29
+ If a task involves OpenAPI generation, backend-only APIs, external client contracts, or schema-driven endpoint docs, AI agents should read this page first and keep the Swagger workflow aligned with `prisma-php.json`.
30
+
31
+ ## AI rule: read the Swagger docs first
32
+
33
+ Before enabling or regenerating Swagger docs, use this order:
34
+
35
+ 1. Inspect `prisma-php.json` for `swaggerDocs` and `backendOnly`.
36
+ 2. Read `backend-only.md`, `route-handlers.md`, and `prisma-php-orm.md` as needed for the surrounding API workflow.
37
+ 3. Use `npm run create-swagger-docs` for the documented generation flow.
38
+ 4. Inspect `settings/prisma-schema-config.json` before changing output paths or generation modes.
39
+ 5. Do not treat Swagger generation as a substitute for ORM migrations or route implementation.
40
+
41
+ ## When Swagger docs are worth enabling
42
+
43
+ Enable Swagger docs when you need a stable machine-readable contract for the API.
44
+
45
+ Typical reasons include:
46
+
47
+ - generating typed frontend clients
48
+ - sharing endpoint definitions with other teams
49
+ - reviewing request and response shapes outside the codebase
50
+ - keeping backend-only or API-heavy projects documented as they evolve
51
+
52
+ In Prisma PHP, the project-level feature flag is `swaggerDocs` in `prisma-php.json`.
53
+
54
+ ```json filename="prisma-php.json"
55
+ {
56
+ "backendOnly": true,
57
+ "swaggerDocs": true
58
+ }
59
+ ```
60
+
61
+ If you enable the flag in an existing application, follow the documented project update flow from `upgrading.md`.
62
+
63
+ ## Generated OpenAPI JSON
64
+
65
+ When Prisma PHP generates Swagger docs, the OpenAPI JSON file is created or updated at:
66
+
67
+ ```txt
68
+ src/app/swagger-docs/apis/pphp-swagger.json
69
+ ```
70
+
71
+ That JSON file is the handoff point for tools such as:
72
+
73
+ - Swagger UI
74
+ - OpenAPI Generator
75
+ - `openapi-zod-client`
76
+ - `openapi-typescript`
77
+ - `orval`
78
+
79
+ ## Generation command
80
+
81
+ Prisma PHP's Swagger workflow supports generating documentation for models from `schema.prisma`.
82
+
83
+ ```bash package="npm"
84
+ npm run create-swagger-docs
85
+ npm run create-swagger-docs Order
86
+ npm run create-swagger-docs Order User Client
87
+ ```
88
+
89
+ During generation, Prisma PHP prompts for three decisions:
90
+
91
+ - whether to generate Swagger docs only
92
+ - whether to generate endpoints
93
+ - whether to generate PHP classes
94
+
95
+ That makes the workflow flexible enough for:
96
+
97
+ - docs-only regeneration
98
+ - endpoint scaffolding together with docs
99
+ - PHP class generation when the project needs it
100
+
101
+ ## Configuration file
102
+
103
+ Swagger generation can be customized from:
104
+
105
+ ```txt
106
+ settings/prisma-schema-config.json
107
+ ```
108
+
109
+ Example configuration:
110
+
111
+ ```json filename="settings/prisma-schema-config.json"
112
+ {
113
+ "swaggerDocsDir": "src/app/swagger-docs/apis",
114
+ "skipDefaultName": ["autoincrement", "cuid", "uuid", "now"],
115
+ "skipByPropertyValue": {
116
+ "isUpdatedAt": true
117
+ },
118
+ "skipFields": [],
119
+ "generateSwaggerDocsOnly": false,
120
+ "generateEndpoints": true,
121
+ "generatePhpClasses": true
122
+ }
123
+ ```
124
+
125
+ This file is where the Prisma PHP Swagger workflow decides:
126
+
127
+ - where the JSON should be written
128
+ - which schema defaults should be omitted from docs output
129
+ - which fields should be skipped entirely
130
+ - whether generation should include only docs, endpoints, PHP classes, or a combination
131
+
132
+ ## Recommended workflow
133
+
134
+ For API-oriented Prisma PHP work, a practical Swagger workflow is:
135
+
136
+ 1. update `schema.prisma`
137
+ 2. run the normal ORM workflow when the schema changed
138
+ 3. regenerate Swagger docs
139
+ 4. inspect `src/app/swagger-docs/apis/pphp-swagger.json`
140
+ 5. regenerate external clients if the contract changed
141
+
142
+ This keeps the API description aligned with the current schema and route generation output.
143
+
144
+ ## Backend-only projects and Swagger
145
+
146
+ Swagger docs fit especially well with backend-only Prisma PHP projects because those apps usually center on `route.php` handlers and separate consumers.
147
+
148
+ The common pairing is:
149
+
150
+ - `backendOnly: true`
151
+ - `swaggerDocs: true`
152
+
153
+ That gives the project a clear API-first posture: handler routes in Prisma PHP, plus an OpenAPI file that frontend and external clients can consume.
154
+
155
+ Read `backend-only.md` when the task is primarily about route structure, CORS, or the default API project shape.
156
+
157
+ ## React and TypeScript client generation
158
+
159
+ One common use case is generating a typed client for a separate React or TypeScript application.
160
+
161
+ ```bash package="npm"
162
+ npm i -D openapi-zod-client
163
+ npx openapi-zod-client --input http://localhost:3000/swagger-docs/apis/pphp-swagger.json --output ./client/src/api/pphp.ts
164
+ ```
165
+
166
+ After generation, the consuming app can validate server responses against the generated schemas instead of relying on handwritten request types.
167
+
168
+ ## What Swagger does not replace
169
+
170
+ Swagger docs help describe the API contract, but they do not replace:
171
+
172
+ - request validation with `PP\Validator`
173
+ - route-level method guards
174
+ - ORM migration and client generation when `schema.prisma` changes
175
+ - CORS configuration when external frontends call the API directly
176
+
177
+ Keep those concerns aligned with `route-handlers.md`, `validator.md`, `prisma-php-orm.md`, and `backend-only.md`.
178
+
179
+ ## Decision guide
180
+
181
+ Use this page when the task is about:
182
+
183
+ - `swaggerDocs` in `prisma-php.json`
184
+ - `pphp-swagger.json`
185
+ - `npm run create-swagger-docs`
186
+ - `settings/prisma-schema-config.json`
187
+ - OpenAPI client generation from Prisma PHP
188
+
189
+ Use `backend-only.md` when the main question is how a backend-only Prisma PHP app should be structured.
@@ -0,0 +1,195 @@
1
+ ---
2
+ title: TypeScript & NPM
3
+ nav_title: TypeScript
4
+ description: Learn how Prisma PHP uses the `typescript` feature flag so AI agents can place TypeScript in `ts/`, register browser helpers from `ts/main.ts`, and use them safely from PulsePoint component roots.
5
+ related:
6
+ title: Related docs
7
+ description: Read the Prisma PHP docs that define feature flags, project updates, and PulsePoint component boundaries before generating TypeScript-aware examples.
8
+ links:
9
+ - /docs/commands
10
+ - /docs/upgrading
11
+ - /docs/project-structure
12
+ - /docs/pulsepoint
13
+ - /docs/components
14
+ ---
15
+
16
+ Prisma PHP TypeScript support should follow the framework's Vite-backed frontend workflow, not ad hoc inline module imports inside `index.php`, `layout.php`, or imported partials.
17
+
18
+ If a task involves the `typescript` flag in `prisma-php.json`, the root `ts/` directory, `ts/main.ts`, frontend npm packages, or using registered browser helpers inside PulsePoint templates and scripts, AI agents should read this page first and keep the implementation aligned with Prisma PHP's component boundary rules.
19
+
20
+ ## AI rule: read the TypeScript docs first
21
+
22
+ Before generating, editing, or reviewing TypeScript-related frontend code, use this order:
23
+
24
+ 1. Read `./prisma-php.json` in a generated Prisma PHP app and confirm whether `typescript` is enabled.
25
+ 2. For an existing app, enable `typescript` first, then run `npx pp update project -y`.
26
+ 3. Keep reusable frontend TypeScript modules in the root `ts/` directory.
27
+ 4. Use `ts/main.ts` as the entry file that registers browser helpers for runtime use.
28
+ 5. Use those registered globals from template expressions and PulsePoint component scripts.
29
+ 6. Keep inline route or partial `<script>` blocks as plain JavaScript. Do not place `import` or `export` inside them.
30
+
31
+ Do not guess from React, Vue, Next.js, or generic Vite projects alone. Prisma PHP still follows its own PulsePoint component and route-file rules.
32
+
33
+ ## Read this doc when you need
34
+
35
+ - **the `typescript` feature flag in `prisma-php.json` or the `--typescript` create flag** -> `commands.md`, `upgrading.md`, and `typescript.md`
36
+ - **where TypeScript files should live in a Prisma PHP app** -> `project-structure.md` and `typescript.md`
37
+ - **how to use registered browser helpers inside a normal PulsePoint route root** -> `layouts-and-pages.md`, `pulsepoint.md`, and `typescript.md`
38
+ - **how to use the same helpers inside an imported single-root partial** -> `components.md` and `typescript.md`
39
+ - **installing npm packages for frontend utilities** -> `typescript.md`
40
+
41
+ ## When TypeScript is enabled
42
+
43
+ When `typescript` is enabled in `prisma-php.json`, Prisma PHP can use a Vite-powered frontend TypeScript workflow.
44
+
45
+ The practical rules are:
46
+
47
+ - keep browser-side TypeScript modules in `ts/`
48
+ - use `ts/main.ts` as the registration entry file
49
+ - install npm packages normally
50
+ - expose the browser helpers you want to call from templates or PulsePoint scripts
51
+ - keep inline PulsePoint scripts as plain JavaScript and call the registered globals from there
52
+
53
+ ## Enable TypeScript in a new or existing app
54
+
55
+ ### New project
56
+
57
+ ```bash package="npm"
58
+ npx create-prisma-php-app my-app --typescript
59
+ ```
60
+
61
+ ### Existing project
62
+
63
+ Enable the feature in `prisma-php.json`, then refresh the project files.
64
+
65
+ ```json filename="prisma-php.json"
66
+ {
67
+ "projectName": "my-app",
68
+ "typescript": true
69
+ }
70
+ ```
71
+
72
+ ```bash package="npm"
73
+ npx pp update project -y
74
+ ```
75
+
76
+ For broader project refresh guidance, read `upgrading.md`.
77
+
78
+ ## The `ts/` directory
79
+
80
+ For organization and reuse, keep frontend TypeScript logic in the root `ts/` directory.
81
+
82
+ This keeps module code out of route files and makes the frontend entry pipeline explicit.
83
+
84
+ Example layout:
85
+
86
+ ```txt
87
+ ts/
88
+ ├── date-utils.ts
89
+ ├── global-functions.ts
90
+ ├── main.ts
91
+ └── to-money.ts
92
+ ```
93
+
94
+ Example utility:
95
+
96
+ ```ts filename="ts/to-money.ts"
97
+ export function toMoney(value: number): string {
98
+ return `$${value.toFixed(2)}`;
99
+ }
100
+ ```
101
+
102
+ ## Use any npm package
103
+
104
+ Because this workflow is Vite-backed, you can install npm packages and import them directly into files under `ts/`.
105
+
106
+ ```bash package="npm"
107
+ npm install date-fns
108
+ ```
109
+
110
+ ```ts filename="ts/date-utils.ts"
111
+ import { format } from "date-fns";
112
+
113
+ export function getToday(): string {
114
+ return format(new Date(), "yyyy-MM-dd");
115
+ }
116
+ ```
117
+
118
+ ## Register helpers in `ts/main.ts`
119
+
120
+ Use the TypeScript entry file to register the browser helpers you want available globally.
121
+
122
+ ```ts filename="ts/main.ts"
123
+ import { createGlobalSingleton } from "./global-functions";
124
+ import { getToday } from "./date-utils";
125
+ import { toMoney } from "./to-money";
126
+
127
+ createGlobalSingleton("getToday", getToday);
128
+ createGlobalSingleton("toMoney", toMoney);
129
+ ```
130
+
131
+ After registration, those helpers can be used from Prisma PHP template expressions and PulsePoint component scripts without adding `import` statements inside the route file itself.
132
+
133
+ ## Important PulsePoint boundary
134
+
135
+ Prisma PHP inline component scripts are plain JavaScript, not module files.
136
+
137
+ That means the right split is:
138
+
139
+ - write reusable module logic in `ts/`
140
+ - register the pieces you need from `ts/main.ts`
141
+ - call those registered helpers from the inline PulsePoint script inside the component root
142
+ - do not place `import` or `export` inside the inline route or imported-partial script
143
+
144
+ When the UI lives in `index.php` or nested `layout.php`, keep the normal Prisma PHP route structure:
145
+
146
+ 1. PHP first
147
+ 2. one parent HTML element
148
+ 3. `pp-component` on that route root when PulsePoint is present
149
+ 4. one `<script>` block as the last child inside that same root element
150
+
151
+ When the UI lives in an imported partial rendered through `ImportComponent::render(...)`, keep exactly one root element and place any component-local `<script>` inside that root. Do not manually add `pp-component` inside the imported partial source.
152
+
153
+ ## Usage inside a PulsePoint route
154
+
155
+ This example keeps the route in the current Prisma PHP single-root component pattern while calling helpers registered from `ts/main.ts`.
156
+
157
+ ```php filename="src/app/index.php"
158
+ <?php
159
+
160
+ use PP\MainLayout;
161
+
162
+ MainLayout::$title = 'TypeScript Helpers';
163
+ MainLayout::$description = 'Use registered TypeScript helpers from a PulsePoint route.';
164
+ ?>
165
+
166
+ <section pp-component="typescript-demo-page">
167
+ <h1>TypeScript helpers</h1>
168
+ <p>Today: {getToday()}</p>
169
+ <p>Catalog price: {toMoney(1234.56)}</p>
170
+ <p>Discounted price: {discountedPrice}</p>
171
+
172
+ <button onclick="applyDiscount()">Apply discount</button>
173
+
174
+ <script>
175
+ const [discountedPrice, setDiscountedPrice] = pp.state(toMoney(15245));
176
+
177
+ function applyDiscount() {
178
+ setDiscountedPrice(toMoney(11999.5));
179
+ }
180
+ </script>
181
+ </section>
182
+ ```
183
+
184
+ The helper calls stay available in both template expressions and the inline PulsePoint script, while the route still follows the documented Prisma PHP component boundary rules.
185
+
186
+ ## AI rules for TypeScript tasks
187
+
188
+ - inspect `prisma-php.json` first and confirm whether `typescript` is enabled
189
+ - for existing apps, enable the feature and run `npx pp update project -y` before assuming the TypeScript scaffold exists
190
+ - keep reusable module code in `ts/`
191
+ - register browser helpers from `ts/main.ts`
192
+ - use npm packages through normal imports inside `ts/` files
193
+ - do not place `import` or `export` inside inline PulsePoint scripts in `index.php`, `layout.php`, or imported partials
194
+ - keep normal route files in the single-root PulsePoint pattern with the `<script>` as the last child inside the route root
195
+ - keep `ImportComponent` partials in the single-root pattern and let Prisma PHP inject `pp-component` there automatically
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Upgrading
3
- description: Learn how to upgrade your Prisma PHP application, enable framework features, and refresh your project safely.
3
+ description: Learn how to upgrade your Prisma PHP application so AI agents can enable features and refresh framework-managed files safely.
4
4
  related:
5
5
  title: Related docs
6
6
  description: Review the Prisma PHP docs for commands, project setup, and feature configuration.
@@ -27,6 +27,8 @@ npx pp update project -y
27
27
 
28
28
  The `-y` flag runs the update in non-interactive mode, which is the recommended choice for AI-driven project updates and scripted automation.
29
29
 
30
+ If a task involves refreshing an existing Prisma PHP app, enabling saved feature flags, or syncing framework-managed files, AI agents should read this page first and prefer the documented non-interactive update flow for automation.
31
+
30
32
  ## Before you update
31
33
 
32
34
  Before running the update command, review your `prisma-php.json` file.
@@ -45,6 +47,8 @@ npx pp update project -y
45
47
 
46
48
  This ensures the update process applies the correct files, dependencies, and project structure for the features you selected.
47
49
 
50
+ If the feature you are enabling is API-focused, read `backend-only.md` for `backendOnly` usage and `swagger-docs.md` for `swaggerDocs` generation workflow details.
51
+
48
52
  ## Typical upgrade flow
49
53
 
50
54
  Use this workflow when upgrading an existing Prisma PHP application:
@@ -52,17 +56,17 @@ Use this workflow when upgrading an existing Prisma PHP application:
52
56
  1. Open `prisma-php.json`.
53
57
  2. Enable or review the features your project should use.
54
58
  3. Save the file.
55
- 4. Run the update command:
59
+ 4. Run the update command.
56
60
 
57
- ```bash package="npm"
58
- npx pp update project
59
- ```
61
+ ```bash package="npm"
62
+ npx pp update project
63
+ ```
60
64
 
61
- For AI agents or automation, use:
65
+ For AI agents or automation, use:
62
66
 
63
- ```bash package="npm"
64
- npx pp update project -y
65
- ```
67
+ ```bash package="npm"
68
+ npx pp update project -y
69
+ ```
66
70
 
67
71
  5. Reinstall or verify project dependencies if needed.
68
72
  6. Test the application locally.
@@ -5,6 +5,7 @@ related:
5
5
  title: Related docs
6
6
  description: Read the official Prisma PHP websocket docs before generating or editing realtime code.
7
7
  links:
8
+ - /docs/env
8
9
  - /docs/websocket-get-started
9
10
  - /docs/websocket-chat-app
10
11
  - /docs/project-structure
@@ -35,6 +36,7 @@ Do not assume another framework's realtime abstractions apply directly.
35
36
 
36
37
  - **Ratchet setup, `IoServer`, `HttpServer`, `WsServer`, `ConnectionManager`, `MessageComponentInterface`, `SplObjectStorage`, or websocket server structure** -> official `websocket-get-started`
37
38
  - **chat-style websocket examples or broadcast behavior** -> official `websocket-chat-app`
39
+ - **typed environment access for `WS_*` values, `APP_TIMEZONE`, or `.env` loading boundaries** -> `env.md` plus `websocket.md`
38
40
  - **feature flags and scaffolding for websocket support** -> `upgrading.md` plus `websocket.md`
39
41
  - **where websocket-related files belong in a Prisma PHP project** -> `project-structure.md` plus `websocket.md`
40
42
  - **interactive route UI that reacts to websocket events** -> `pulsepoint.md` and `fetching-data.md` plus `websocket.md`
@@ -101,6 +103,8 @@ AI should preserve these settings and precedence rules:
101
103
  - `APP_TIMEZONE` with fallback `UTC`
102
104
  - CLI overrides through `--host=...`, `--port=...`, and `--verbose=...`
103
105
 
106
+ These runtime values are read through `PP\Env`, whose implementation lives in `vendor/tsnc/prisma-php/src/Env.php`.
107
+
104
108
  The effective host and port resolve in this order:
105
109
 
106
110
  1. CLI arguments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-php",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Prisma PHP tooling",
5
5
  "main": "index.js",
6
6
  "scripts": {