prisma-php 0.0.11 → 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.
@@ -2,9 +2,10 @@
2
2
 
3
3
  ## Source Of Truth
4
4
 
5
- - Treat `dist/docs/index.md` as the entry point for Prisma PHP guidance in this repo.
6
- - Read the matching doc in `dist/docs` before generating or editing framework-specific Prisma PHP code.
7
- - When updating AI guidance in this repo, keep `AGENTS.md`, `.github/copilot-instructions.md`, and `dist/docs` aligned.
5
+ - For Prisma PHP applications, treat `node_modules/prisma-php/dist/docs/index.md` as the entry point for the installed framework version.
6
+ - Read the matching doc in `node_modules/prisma-php/dist/docs` before generating or editing framework-specific Prisma PHP code.
7
+ - Expect `AGENTS.md` in the project root and keep it aligned with the installed Prisma PHP docs contract.
8
+ - When updating Prisma PHP package/docs sources in this repo, keep `AGENTS.md`, `.github/copilot-instructions.md`, and `dist/docs` aligned so the published docs remain correct after install.
8
9
  - Keep every `dist/docs/*.md` page AI-discoverable on its own: the frontmatter description and opening section should clearly say when agents should read that file and which adjacent docs to consult next.
9
10
 
10
11
  ## Route File Conventions
@@ -17,26 +18,32 @@
17
18
  ## Component Boundary Rules
18
19
 
19
20
  - Distinguish PHPX class components from `ImportComponent` partials.
20
- - `ImportComponent` partials must output exactly one root element because Prisma PHP attaches serialized props and a stable `pp-component` attribute to that root.
21
+ - `ImportComponent` partials must output exactly one root element because Prisma PHP uses that root as the imported component boundary and serializes props there.
21
22
  - Do not manually add `pp-component` inside `ImportComponent` partial source; Prisma PHP injects it there. For normal PulsePoint-aware route files, add `pp-component` to the single root element yourself.
22
23
 
23
24
  ## Relevant Docs
24
25
 
25
26
  - Project structure and feature placement: `dist/docs/project-structure.md`
26
27
  - CLI project creation and update commands: `dist/docs/commands.md`
28
+ - First-time project installation and local setup: `dist/docs/installation.md`
29
+ - Existing-project upgrades and feature refreshes: `dist/docs/upgrading.md`
30
+ - TypeScript frontend tooling, the `typescript` flag, and `ts/main.ts` registration: `dist/docs/typescript.md`
27
31
  - Backend-only API usage and `backendOnly`: `dist/docs/backend-only.md`
28
32
  - Route and layout structure: `dist/docs/layouts-and-pages.md`
29
33
  - AI integration, provider-backed chat, streaming, and MCP boundary: `dist/docs/get-started-ia.md`
30
34
  - Data loading, `#[Exposed]`, and SSE streaming: `dist/docs/fetching-data.md`
31
35
  - PulsePoint runtime rules: `dist/docs/pulsepoint.md`
32
36
  - Component and `ImportComponent` rules: `dist/docs/components.md`
37
+ - Cache behavior and `CacheHandler`: `dist/docs/caching.md`
33
38
  - Validation rules: `dist/docs/validator.md`
39
+ - Prisma ORM schema, migrations, and generated PHP classes: `dist/docs/prisma-php-orm.md`
34
40
  - Environment variables and `PP\Env` usage: `dist/docs/env.md`
35
41
  - File uploads and file manager behavior: `dist/docs/file-manager.md`
36
42
  - Email and SMTP workflows: `dist/docs/email.md`
37
43
  - WebSocket and realtime behavior: `dist/docs/websocket.md`
38
44
  - MCP server and tool rules: `dist/docs/mcp.md`
39
45
  - Authentication: `dist/docs/authentication.md`
46
+ - Error handling, expected failures, and route error files: `dist/docs/error-handling.md`
40
47
  - Metadata and icons: `dist/docs/metadata-and-og-images.md`
41
48
  - API-style handlers and webhooks: `dist/docs/route-handlers.md`
42
49
  - Swagger/OpenAPI generation and `swaggerDocs`: `dist/docs/swagger-docs.md`
@@ -7,6 +7,7 @@ related:
7
7
  links:
8
8
  - /docs/installation
9
9
  - /docs/upgrading
10
+ - /docs/typescript
10
11
  ---
11
12
 
12
13
  This guide explains what each Prisma PHP CLI command does, when to use it, and how the create and update workflows fit together.
@@ -163,6 +164,10 @@ npx create-prisma-php-app my-app --tailwindcss
163
164
 
164
165
  Enables TypeScript support for the frontend toolchain.
165
166
 
167
+ When this flag is enabled, Prisma PHP should keep frontend TypeScript in the root `ts/` directory, register browser helpers from `ts/main.ts`, and use those registered globals from template expressions and PulsePoint component scripts.
168
+
169
+ Read `typescript.md` for the TypeScript-specific workflow.
170
+
166
171
  ### Use this when
167
172
 
168
173
  - you want typed frontend code
@@ -15,6 +15,8 @@ related:
15
15
 
16
16
  Prisma PHP is a good fit for AI features, but the right Prisma PHP pattern depends on what you are actually building.
17
17
 
18
+ If a task involves provider-backed chat, prompt forms, streamed output, assistant panels, or deciding between page-local AI, websocket, and MCP, AI agents should read this page first and keep the implementation aligned with the installed Prisma PHP docs.
19
+
18
20
  For a normal user-facing chat box, assistant panel, prompt form, streamed summary, or similar page-local AI feature, the recommended Prisma PHP approach is:
19
21
 
20
22
  1. render the UI in `index.php`
@@ -10,7 +10,9 @@ related:
10
10
  - /docs/get-started-ia
11
11
  ---
12
12
 
13
- {/_AI agent hint: Prisma PHP uses local installed docs as the source of truth for the active project version. Before generating framework-specific code, read `prisma-php.json` first, then read the relevant docs from `node_modules/prisma-php/dist/docs`. For authentication, read `authentication.md` first, then verify the official auth docs: `auth-get-started`, `credentials`, and `state-manager-auth`. For environment variables, `.env`, `PP\Env`, `Env::get(...)`, `Env::string(...)`, `Env::bool(...)`, `Env::int(...)`, or runtime configuration, read `env.md` first, then verify the official env docs: `env` and `env-file`. For file uploads, `multipart/form-data`, `$_FILES`, `PP\FileManager\UploadFile`, rename/delete flows, or file manager screens, read `file-manager.md` first, then verify the official File Manager docs: `get-started-file`. For email sending, SMTP config, `.env` mail variables, `PP\PHPMailer\Mailer`, HTML or text bodies, recipients, reply-to, or attachments, read `email.md` first, then verify the official Email docs: `email-get-started`. For websocket support, Ratchet setup, `IoServer`, `HttpServer`, `WsServer`, `ConnectionManager`, connection lifecycle methods, browser `WebSocket`, or realtime UI flows, read `websocket.md` first, then verify the official websocket docs: `websocket-get-started` and `websocket-chat-app`. For MCP support, `#[McpTool]`, `#[Schema]`, `PhpMcp\Server\Server`, `StreamableHttpServerTransport`, or `src/Lib/MCP/mcp-server.php`, read `mcp.md` first, then verify the official MCP docs: `prisma-php-ai-mcp` and `ai-tools`. For ORM work, read `prisma-php-orm.md` before choosing schema, migration, or generation commands. For PulsePoint runtime behavior specifically, read `pulsepoint.md` before generating reactive UI code. For normal interactive full-stack page work, default to PulsePoint plus `pp.fetchFunction(...)` unless the user explicitly asks for a PHP-only interaction style. For normal PulsePoint-aware route files such as `index.php` and nested `layout.php`, keep PHP first, then one parent HTML element that acts as the route-view boundary; when PulsePoint logic is present, put `pp-component` on that root and keep the `<script>` as the last child inside it. For imported partial components rendered with `ImportComponent::render(...)`, keep exactly one root element and place any component-local `<script>` inside that root; Prisma PHP injects `pp-component` on the imported root automatically. Do not confuse the route-file pattern with the imported-partial pattern. For backend validation, sanitization, `Validator`, `Rule`, `pp.fetchFunction(...)` validation flows, or request validation in `route.php`, read `validator.md` first, then use `fetching-data.md`, `error-handling.md`, and `route-handlers.md` for context-specific patterns, then consult the official Validator docs. `PP\Validator` is a Prisma PHP core class located in `vendor/tsnc/prisma-php/src/Validator.php`. Route creation is file-based from `src/app`; Prisma PHP auto-generates route listings such as `files-list.json`, so AI agents must not create, edit, or maintain that file manually._/}
13
+ Use this page as the routing entry point for the local Prisma PHP docs. If a task involves choosing which Prisma PHP guide to read before generating framework-specific code, start here and then jump to the matching page in `node_modules/prisma-php/dist/docs`.
14
+
15
+ Before generating framework-specific code, read `prisma-php.json` first, then the matching local docs page. For auth read `authentication.md`; for env read `env.md`; for uploads read `file-manager.md`; for email read `email.md`; for websocket read `websocket.md`; for MCP read `mcp.md`; for ORM read `prisma-php-orm.md`; for reactive UI read `pulsepoint.md`; for validation read `validator.md`; for data loading read `fetching-data.md`; and for route or layout structure read `layouts-and-pages.md`.
14
16
 
15
17
  Welcome to the Prisma PHP documentation!
16
18
 
@@ -118,6 +120,7 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
118
120
  - **backend-only Prisma PHP usage, API-first projects, `backendOnly`, CORS, separate frontend clients, or choosing `route.php` as the default route file** → `backend-only.md`
119
121
  - **pages, layouts, route creation, nested routes, or PulsePoint-aware `index.php` and `layout.php` structure** → `layouts-and-pages.md`
120
122
  - **PHPX components, props, children, fragments, icons, buttons, accordions, or component composition** → `components.md`
123
+ - **frontend TypeScript tooling, the `typescript` flag, the `ts/` directory, `ts/main.ts`, npm packages, or registered browser helpers used from template expressions and PulsePoint scripts** → `typescript.md`
121
124
  - **environment variables, `.env`, `PP\Env`, `Env::get(...)`, `Env::string(...)`, `Env::bool(...)`, `Env::int(...)`, or runtime configuration** → `env.md`
122
125
  - **file uploads, `multipart/form-data`, `$_FILES`, `PP\FileManager\UploadFile`, rename/delete flows, file replacement, allowed file types, upload size rules, or file manager pages** → `file-manager.md`
123
126
  - **AI integration, provider SDKs, chat UIs, streamed assistant responses, or deciding between page-local AI features, websocket, and MCP** → `get-started-ia.md`
@@ -147,6 +150,7 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
147
150
  - when the project is API-first or backend-only, read `backend-only.md`, inspect `backendOnly` in `prisma-php.json`, and default to `route.php` for normal route behavior
148
151
  - when reading runtime configuration, `.env`, or feature flags, read `env.md` first and prefer `PP\Env` typed helpers over repeated manual parsing
149
152
  - when building interactive frontend behavior, prefer the documented PulsePoint pattern with browser-side reactive state and `pp.fetchFunction(...)` for server calls; treat this as the default unless the user explicitly asks for a PHP-only interaction pattern
153
+ - when the task involves frontend TypeScript tooling or registered browser helpers, read `typescript.md`, keep reusable module code in `ts/`, and call the registered globals from PulsePoint component scripts instead of placing `import` or `export` inside inline route scripts
150
154
  - when building PulsePoint inside `index.php` or `layout.php`, read `layouts-and-pages.md` together with `pulsepoint.md`, use one parent route root, put `pp-component` on that root, and keep the `<script>` inside it as the last child
151
155
  - when importing a PHP partial with `ImportComponent`, require exactly one root element and keep any partial-local `<script>` inside that root because Prisma PHP attaches serialized props and a stable `pp-component` attribute to that imported root
152
156
  - do not leave a PulsePoint `<script>` as a sibling outside the route root
@@ -175,6 +179,18 @@ For a normal chat UI, assistant panel, streamed summary, or other page-local AI
175
179
 
176
180
  Use `get-started-ia.md` as the local AI guide for provider-backed chat, streaming, and the boundary between page-local AI, websocket, and MCP tooling.
177
181
 
182
+ ## TypeScript
183
+
184
+ Prisma PHP can use a Vite-backed TypeScript workflow when the `typescript` feature flag is enabled in `prisma-php.json`.
185
+
186
+ Use `typescript.md` as the local AI guide for:
187
+
188
+ - enabling TypeScript in new or existing projects
189
+ - organizing frontend modules in `ts/`
190
+ - registering browser helpers in `ts/main.ts`
191
+ - installing npm packages for frontend utilities
192
+ - using registered helpers from template expressions and PulsePoint scripts while keeping inline component scripts as plain JavaScript
193
+
178
194
  ## Env
179
195
 
180
196
  Prisma PHP includes a documented environment helper centered on `PP\Env`, which reads already-loaded runtime values and exposes typed accessors for strings, booleans, and integers.
@@ -2,11 +2,11 @@
2
2
  title: Installation
3
3
  description: Learn how to create a new Prisma PHP application so AI agents can use the first-time setup flow instead of existing-project update commands.
4
4
  related:
5
- title: Related docs
6
- description: Read the full command reference and the existing-project update workflow.
7
- links:
8
- - /docs/commands
9
- - /docs/upgrading
5
+ title: Related docs
6
+ description: Read the full command reference and the existing-project update workflow.
7
+ links:
8
+ - /docs/commands
9
+ - /docs/upgrading
10
10
  ---
11
11
 
12
12
  Create a new Prisma PHP app and run it locally.
@@ -15,6 +15,8 @@ Prisma PHP ORM gives Prisma PHP applications a schema-first, Prisma-style data l
15
15
 
16
16
  It uses your Prisma schema, Prisma migrations, and generated PHP classes so your application can query the database through the documented Prisma PHP API.
17
17
 
18
+ If a task involves `schema.prisma`, migrations, generated Prisma PHP classes, `npx prisma ...`, or `npx ppo generate`, AI agents should read this page first and keep the workflow aligned with the installed Prisma PHP docs.
19
+
18
20
  ## ORM result shape rule
19
21
 
20
22
  Prisma PHP ORM query results should be treated as model-shaped objects returned by the generated Prisma PHP classes that follow `prisma/schema.prisma`.
@@ -75,7 +77,7 @@ Use this order:
75
77
 
76
78
  For Prisma PHP ORM tasks, AI should read:
77
79
 
78
- - `06-prisma-php-orm.md`
80
+ - `prisma-php-orm.md`
79
81
  - the official Prisma PHP ORM docs for the installed version
80
82
  - `schema.prisma`
81
83
  - `prisma.config.ts`
@@ -196,24 +198,26 @@ Use this flow:
196
198
  6. when the user is using SQLite, prefer saving the database file inside the local `./prisma` directory
197
199
  7. for the normal local setup, use:
198
200
 
199
- ```env
200
- DATABASE_URL="file:./prisma/dev.db"
201
- ```
201
+ ```env
202
+ DATABASE_URL="file:./prisma/dev.db"
203
+ ```
202
204
 
203
- 8. confirm the resolved path points to a valid project-local SQLite file such as `./prisma/dev.db`
204
- 9. do not point the SQLite file at an unrelated root-level location when the project is using the standard Prisma PHP layout
205
- 10. if the `./prisma` directory is the intended storage location, the SQLite database file should be created and saved there
206
- 11. if the SQLite database file is missing, invalid, or not initialized yet, run:
205
+ Then continue with these checks:
207
206
 
208
- ```bash
209
- npx prisma migrate dev
210
- ```
207
+ - confirm the resolved path points to a valid project-local SQLite file such as `./prisma/dev.db`
208
+ - do not point the SQLite file at an unrelated root-level location when the project is using the standard Prisma PHP layout
209
+ - if the `./prisma` directory is the intended storage location, the SQLite database file should be created and saved there
210
+ - if the SQLite database file is missing, invalid, or not initialized yet, run:
211
211
 
212
- 12. after migration succeeds, run:
212
+ ```bash
213
+ npx prisma migrate dev
214
+ ```
213
215
 
214
- ```bash
215
- npx ppo generate
216
- ```
216
+ - after migration succeeds, run:
217
+
218
+ ```bash
219
+ npx ppo generate
220
+ ```
217
221
 
218
222
  Important SQLite rule:
219
223
 
@@ -1,20 +1,33 @@
1
1
  ---
2
2
  title: Project structure and organization
3
3
  nav_title: Project Structure
4
- description: Learn the folder and file conventions in Prisma PHP so AI agents can place features in the right files and folders.
4
+ description: Learn the folder and file conventions in Prisma PHP, including the installed docs path and project-root AGENTS.md, so AI agents can place features in the right files and folders.
5
+ related:
6
+ title: Related docs
7
+ description: Use the routing, handler, component, and TypeScript docs once you know where a change belongs.
8
+ links:
9
+ - /docs/pages-and-layouts
10
+ - /docs/route-php
11
+ - /docs/import-component
12
+ - /docs/typescript
13
+ ---
5
14
 
6
15
  This page provides an overview of the folder and file conventions in **Prisma PHP**, and recommendations for organizing your project. It follows the Prisma PHP routing model and mirrors the mental model of a Next.js App Router style project structure, adapted to how Prisma PHP actually works.
7
16
 
8
17
  If a task involves file placement, feature flags, route creation, or overall Prisma PHP app organization, AI agents should read this page first and use it as the directory-level source of truth before generating files.
9
18
 
19
+ For AI-assisted work, treat `node_modules/prisma-php/dist/docs` as the installed Prisma PHP docs location for the active project version, and keep `AGENTS.md` in the project root aligned with that docs set.
20
+
10
21
  ## AI rule: read the structure docs first
11
22
 
12
23
  Before generating Prisma PHP files or folders, use this order:
13
24
 
14
25
  1. Read `prisma-php.json`.
15
- 2. Decide whether the task belongs in `src/app`, `src/Lib`, `prisma`, `public`, or `settings`.
16
- 3. Create routes from the route tree instead of editing `files-list.json`.
17
- 4. Use `layouts-and-pages.md`, `route-handlers.md`, or `components.md` once the file location is known.
26
+ 2. Read the matching installed doc in `node_modules/prisma-php/dist/docs`.
27
+ 3. Read `AGENTS.md` for project-specific Prisma PHP rules.
28
+ 4. Decide whether the task belongs in `src/app`, `src/Lib`, `prisma`, `public`, `settings`, or the installed docs path.
29
+ 5. Create routes from the route tree instead of editing `files-list.json`.
30
+ 6. Use `layouts-and-pages.md`, `route-handlers.md`, or `components.md` once the file location is known.
18
31
 
19
32
  ## Folder and file conventions
20
33
 
@@ -26,10 +39,21 @@ Top-level folders are used to organize your application's source code, configura
26
39
  | ---------- | ----------------------------------------------------------------------------- |
27
40
  | `src/app` | File-system based routing, pages, layouts, loading states, and route handlers |
28
41
  | `src/Lib` | Application libraries, generated Prisma classes, auth, middleware, utilities |
42
+ | `ts` | Frontend TypeScript modules and Vite entry files when `typescript` is enabled |
29
43
  | `public` | Public web root, static files, CSS, JS, favicon, and public entry point |
30
44
  | `prisma` | Prisma schema, migrations, and seed scripts |
31
45
  | `settings` | Project configuration such as paths, BrowserSync, and related setup |
32
46
 
47
+ ### Installed framework docs
48
+
49
+ Prisma PHP installs its framework docs inside `node_modules/prisma-php/dist/docs`.
50
+
51
+ AI agents should treat that installed docs directory as the single source of truth for framework behavior in the active project version.
52
+
53
+ | Path | Purpose |
54
+ | ----------------------------------- | -------------------------------------------------------------------- |
55
+ | `node_modules/prisma-php/dist/docs` | Installed Prisma PHP docs for the current project version and AI use |
56
+
33
57
  ### Top-level files
34
58
 
35
59
  These files are typically used to configure the app, manage dependencies, and define environment values.
@@ -39,6 +63,7 @@ These files are typically used to configure the app, manage dependencies, and de
39
63
  | `composer.json` | PHP dependencies and autoloading |
40
64
  | `package.json` | Frontend tooling and development scripts when used |
41
65
  | `.env` | Environment variables |
66
+ | `AGENTS.md` | Project-root AI guidance aligned with the installed docs set |
42
67
  | `prisma/schema.prisma` | Main Prisma schema file |
43
68
  | `public/index.php` | Public entry point |
44
69
  | `bootstrap.php` | Application bootstrap and middleware registration when present |
@@ -69,6 +94,8 @@ For backend-only API projects, read `backend-only.md`.
69
94
 
70
95
  For Swagger and OpenAPI generation, read `swagger-docs.md`.
71
96
 
97
+ For TypeScript frontend tooling, the root `ts/` directory, `ts/main.ts`, and npm-backed browser utilities, read `typescript.md`.
98
+
72
99
  ### Full-stack vs backend-only routing decision
73
100
 
74
101
  One of the most important capability flags is `backendOnly`.
@@ -236,6 +263,10 @@ Redirects are handled with `Request::redirect()`, which sends an HTTP `Location`
236
263
 
237
264
  ```txt
238
265
  prisma-php-project/
266
+ ├── node_modules/
267
+ │ └── prisma-php/
268
+ │ └── dist/
269
+ │ └── docs/
239
270
  ├── prisma/
240
271
  │ ├── migrations/
241
272
  │ ├── schema.prisma
@@ -287,6 +318,7 @@ prisma-php-project/
287
318
  ├── composer.json
288
319
  ├── package.json
289
320
  ├── prisma-php.json
321
+ ├── AGENTS.md
290
322
  └── .env
291
323
  ```
292
324
 
@@ -1,14 +1,22 @@
1
1
  ---
2
2
  title: PulsePoint Runtime Guide
3
3
  description: Learn how AI agents should use the current PulsePoint runtime contract, component script rules, and supported directives in Prisma PHP.
4
+ related:
5
+ title: Related docs
6
+ description: Read the route, component, data-fetching, and TypeScript docs alongside the PulsePoint runtime contract.
7
+ links:
8
+ - /docs/pages-and-layouts
9
+ - /docs/import-component
10
+ - /docs/fetch-function
11
+ - /docs/typescript
4
12
  ---
5
13
 
6
- # PulsePoint Runtime Guide
7
-
8
14
  ## Purpose
9
15
 
10
16
  This file describes the PulsePoint runtime that is actually implemented in the current TypeScript source of this repo. Treat it as the working contract for AI-generated code.
11
17
 
18
+ If a task involves `pp.state`, `pp.effect`, `pp-ref`, `pp-spread`, route-root scripts, imported partial runtime behavior, or current `pp-component` semantics, AI agents should read this page first and keep generated code aligned with the runtime implemented in this repo.
19
+
12
20
  Do not assume React, Vue, Svelte, JSX, or older PulsePoint docs.
13
21
 
14
22
  ## Runtime shape
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-php",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Prisma PHP tooling",
5
5
  "main": "index.js",
6
6
  "scripts": {