prisma-php 0.0.2 → 0.0.4

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.
@@ -1,434 +1,212 @@
1
- # PulsePoint: always read the official docs before generating code
1
+ # PulsePoint Runtime Guide
2
2
 
3
- > Purpose: eliminate guessing and make AI-generated PulsePoint code accurate, copy-pasteable, and aligned with the real runtime.
4
- >
5
- > Scope: this document covers the **core PulsePoint runtime** only — browser-side state, effects, refs, and markup directives. It does **not** assume any specific backend or server framework.
6
- >
7
- > Official docs: [https://pulsepoint.tsnc.tech/llms](https://pulsepoint.tsnc.tech/llms)
8
- >
9
- > Version: 3.0.0
3
+ ## Purpose
10
4
 
11
- ---
5
+ This file describes the PulsePoint runtime that is actually implemented in the current TypeScript source of this repo. Use it as the working contract for AI-generated code.
12
6
 
13
- ## Read the PulsePoint docs first
7
+ If `src/` is available, read it first. If the app only exposes a plain HTML page plus a minified or bundled runtime loaded by a script tag, inspect those artifacts instead and follow the same behavior. Do not assume React, Vue, Svelte, or older PulsePoint docs.
14
8
 
15
- Before generating, editing, or reviewing any PulsePoint code, read the official PulsePoint docs:
9
+ ## What the runtime actually does
16
10
 
17
- ```txt
18
- https://pulsepoint.tsnc.tech/llms
19
- ```
20
-
21
- Treat the PulsePoint docs as the source of truth for:
22
-
23
- - supported runtime APIs
24
- - supported directives and markup behavior
25
- - syntax rules
26
- - state and effect patterns
27
- - ref usage
28
- - limitations and forbidden patterns
29
-
30
- Do not rely on assumptions from React, Vue, Alpine, Svelte, Livewire, jQuery, or any other framework.
31
-
32
- If the docs do not show a feature or API, do **not** invent it.
33
-
34
- ---
35
-
36
- ## Prisma PHP integration rule
37
-
38
- When PulsePoint is used inside a Prisma PHP application, the default full-stack pattern is:
39
-
40
- - PulsePoint for reactive browser state and UI updates
41
- - `pp.fetchFunction(...)` for frontend-to-PHP server calls
42
- - `#[Exposed]` on PHP functions or methods that the frontend should be allowed to call
43
- - `PP\Validator` on the PHP side for authoritative input validation and normalization
44
-
45
- Do not invent parallel client/server patterns when the built-in Prisma PHP RPC flow already fits the task. In typical Prisma PHP page work, prefer PulsePoint plus `pp.fetchFunction(...)` over ad hoc API wiring.
46
-
47
- Use `route.php` only when you explicitly need a standalone endpoint such as a webhook, public JSON route, external integration endpoint, or other no-view handler.
48
-
49
- ## Validation boundary
50
-
51
- PulsePoint can help with local UX such as:
52
-
53
- - showing inline hints
54
- - disabling submit buttons
55
- - rendering field-level error messages
56
- - debouncing live validation requests
57
-
58
- But the final validation still belongs on the PHP side.
59
-
60
- In Prisma PHP, the default boundary is:
61
-
62
- - **PulsePoint** for local UI state and feedback
63
- - **`pp.fetchFunction(...)`** for sending data to PHP
64
- - **`PP\Validator`** for authoritative backend validation
65
-
66
- Do not present browser-only checks as the final source of truth.
67
-
68
- ---
69
-
70
- ## What PulsePoint is responsible for
71
-
72
- PulsePoint is the **browser-side reactive runtime**.
73
-
74
- It is responsible for UI interactivity such as:
75
-
76
- - local reactive state
77
- - reactive effects
78
- - DOM refs
79
- - list rendering
80
- - attribute spreading
81
- - simple interactive bindings
82
-
83
- PulsePoint is **not** the backend.
84
-
85
- That means an AI agent must keep these concerns separate:
86
-
87
- - **PulsePoint docs** decide how frontend runtime code should be written.
88
- - **Project/backend docs** decide how data is loaded, validated, saved, authenticated, or routed on the server.
89
-
90
- ---
91
-
92
- ## Allowed runtime surface
93
-
94
- Only use the runtime surface explicitly allowed here unless the official docs say otherwise.
95
-
96
- ### Core JavaScript API
97
-
98
- 1. `pp.state<T>(initial)` → `[state, setState]`
99
- 2. `pp.ref<T>(initial: T | null)`
100
- 3. `pp.effect(fn: () => void | (() => void), deps?: Dependency[])`
11
+ PulsePoint is a browser-side component runtime. It renders HTML, binds state and events, and morphs the DOM in place.
101
12
 
102
- ### Markup directives
13
+ A component root is any element with `pp-component`.
103
14
 
104
- 1. `pp-for` _(only on `<template>`)_
105
- 2. `pp-spread`
106
- 3. `pp-ref`
15
+ ## Component roots and scripts
107
16
 
108
- If a symbol is not listed above and is not documented in the official PulsePoint docs, treat it as unsupported.
109
-
110
- ---
111
-
112
- ## Decision rules for AI agents
113
-
114
- When working with PulsePoint, follow these rules:
115
-
116
- 1. Read the official PulsePoint docs before making runtime decisions.
117
- 2. Do not invent undocumented helpers, directives, lifecycle APIs, or magic globals.
118
- 3. Keep backend assumptions out of PulsePoint-only examples.
119
- 4. Prefer simple, explicit patterns over framework-inspired abstractions.
120
- 5. Generate code that is valid immediately, not pseudo-code.
121
- 6. When uncertain, reduce scope to documented PulsePoint primitives.
122
- 7. If a project also includes framework-specific rules, apply them **after** the PulsePoint docs for backend concerns, but keep PulsePoint runtime syntax aligned with the official PulsePoint docs.
123
-
124
- ---
125
-
126
- ## Priority order
127
-
128
- When generating code that uses PulsePoint, use this order of truth:
129
-
130
- 1. The user’s explicit request
131
- 2. The official PulsePoint docs: `https://pulsepoint.tsnc.tech/llms`
132
- 3. Project-specific agent rules or local project docs
133
- 4. Existing project code and structure
134
- 5. General framework knowledge
135
-
136
- If any assumption conflicts with the official PulsePoint docs, follow the PulsePoint docs.
137
-
138
- ---
139
-
140
- ## File layout rules
141
-
142
- For PulsePoint runtime code, keep a predictable layout:
143
-
144
- 1. HTML markup first
145
- 2. One `<script>` block at the bottom
17
+ - Each component root may contain one inline `<script type="text/pp">` block for component logic.
18
+ - The script is plain JavaScript, not a module. Do not use `import` or `export` inside it.
19
+ - Top-level bindings from the script are exported automatically to the template. Do not manually `return { ... }`.
20
+ - Top-level `const`, `let`, `function`, and supported destructuring patterns become template bindings.
21
+ - `pp.props` contains the current prop bag for the component.
22
+ - `children` contains the component's initial inner HTML.
23
+ - Nested `pp-component` roots are boundaries and are not flattened by a parent component.
146
24
 
147
25
  Example:
148
26
 
149
27
  ```html
150
- <ul>
151
- <template pp-for="user in users">
152
- <li key="{user.id}">{user.name}</li>
153
- </template>
154
- </ul>
155
-
156
- <script>
157
- const [users, setUsers] = pp.state([
158
- { id: 1, name: "Alice" },
159
- { id: 2, name: "Bob" },
160
- ]);
161
- </script>
162
- ```
163
-
164
- Rules:
165
-
166
- - Use **exactly one** `<script>` block per page or component unless the project explicitly requires something else.
167
- - Place the script block **after** the markup.
168
- - JavaScript should only reference data that already exists when the script runs.
169
- - Do not scatter PulsePoint runtime logic across multiple disconnected script blocks unless the docs or project structure explicitly requires it.
170
-
171
- ---
172
-
173
- ## Conditionals and booleans
174
-
175
- Prefer visibility toggles instead of complex conditional markup.
176
-
177
- ### Preferred
178
-
179
- ```html
180
- <div hidden="{!isOpen}">Shown when open</div>
181
- <div hidden="{isOpen}">Shown when closed</div>
182
- ```
183
-
184
- ### Text or attribute ternaries
185
-
186
- ```html
187
- <span class="{isActive ? 'text-green-600' : 'text-red-600'}">
188
- {isActive ? 'Active' : 'Inactive'}
189
- </span>
190
- ```
191
-
192
- ### Boolean attributes
193
-
194
- ```html
195
- <input type="checkbox" checked="{isActive}" />
28
+ <div pp-component="counter-card">
29
+ <h2>{title}</h2>
30
+ <p>Count: {count}</p>
31
+ <button onclick="setCount(count + 1)">Increment</button>
32
+
33
+ <script type="text/pp">
34
+ const { title } = pp.props;
35
+ const [count, setCount] = pp.state(0);
36
+ const doubled = count * 2;
37
+
38
+ function reset() {
39
+ setCount(0);
40
+ }
41
+ </script>
42
+ </div>
196
43
  ```
197
44
 
198
- String branches in ternaries must be quoted correctly.
45
+ ## Hooks exposed through `pp`
199
46
 
200
- - Correct: `{isActive ? 'text-blue-500' : 'text-gray-500'}`
201
- - Invalid: `{isActive ? text-blue-500' : 'text-gray-500'}`
47
+ - `pp.state(initial)` returns `[value, setValue]`.
48
+ - `pp.effect(callback, deps?)` runs after render and can return cleanup.
49
+ - `pp.layoutEffect(callback, deps?)` runs synchronously after DOM mutation.
50
+ - `pp.ref(initialValue?)` returns `{ current }`.
51
+ - `pp.memo(factory, deps)` memoizes a computed value.
52
+ - `pp.callback(callback, deps)` memoizes a function.
53
+ - `pp.reducer(reducer, initialState)` returns `[state, dispatch]`.
54
+ - `pp.portal(ref, target?)` portals a ref-managed element into a target.
55
+ - `pp.props` exposes the current props.
202
56
 
203
- ---
57
+ Notes:
204
58
 
205
- ## Refs with `pp-ref`
59
+ - `pp.state` setters accept either a value or an updater function.
60
+ - `pp.effect` and `pp.layoutEffect` use dependency arrays like React, but only the hooks listed here exist.
61
+ - Keep template-facing bindings at the top level so the AST-based exporter can see them.
206
62
 
207
- ### Single element ref
208
-
209
- ```html
210
- <input type="text" pp-ref="{nameInput}" />
211
- <button onclick="nameInput.current?.focus()">Focus</button>
63
+ ## Template expressions and attributes
212
64
 
213
- <script>
214
- const nameInput = pp.ref(null);
215
- </script>
216
- ```
65
+ - Use `{expression}` in text nodes and attribute values.
66
+ - Pure bindings like `value="{count}"` are evaluated as expressions.
67
+ - Mixed text like `class="card {isActive ? 'active' : ''}"` is supported.
68
+ - Boolean attributes are normalized for supported boolean names.
69
+ - Use `pp-spread="{...attrs}"` to spread one object expression into attributes.
70
+ - Use plain `key` for keyed diffing. `pp-key` is not implemented in the current source.
217
71
 
218
- ### Dynamic ref registration
72
+ Example:
219
73
 
220
74
  ```html
221
- <ul>
222
- <template pp-for="item in items">
223
- <li key="{item.id}">
224
- <input pp-ref="{registerRef(item.id)}" hidden="{editingId !== item.id}" />
225
- <button onclick="setEditingId(item.id)">Edit</button>
226
- </li>
227
- </template>
228
- </ul>
75
+ <button pp-spread="{...buttonAttrs}" hidden="{isLoading}">Save</button>
229
76
 
230
- <script>
231
- const [items, setItems] = pp.state([
232
- { id: 1, name: "Task A" },
233
- { id: 2, name: "Task B" },
234
- ]);
235
- const [editingId, setEditingId] = pp.state(null);
236
-
237
- const itemRefs = new Map();
238
-
239
- const registerRef = (id) => (el) => {
240
- if (el) itemRefs.set(id, el);
241
- else itemRefs.delete(id);
77
+ <script type="text/pp">
78
+ const buttonAttrs = {
79
+ class: "btn btn-primary",
80
+ "aria-label": "save",
242
81
  };
243
-
244
- pp.effect(() => {
245
- if (editingId && itemRefs.has(editingId)) {
246
- itemRefs.get(editingId).focus();
247
- }
248
- }, [editingId]);
82
+ const isLoading = false;
249
83
  </script>
250
84
  ```
251
85
 
252
- Rules:
86
+ ## Refs
253
87
 
254
- - Initialize refs with `pp.ref(null)`.
255
- - Null-check ref access where appropriate.
256
- - Use refs for DOM access and imperative behavior, not as general reactive state storage.
88
+ - Use `pp-ref="nameInput"` when the value is a ref object or callback already in scope.
89
+ - Use `pp-ref="{registerRef(id)}"` when you need a dynamic expression.
90
+ - `pp.ref(null)` is the normal way to create a ref object.
91
+ - The runtime generates `data-pp-ref` internally. Do not author it.
92
+ - Do not author `pp-event-owner`, `pp-owner`, or `pp-dynamic-*` attributes by hand.
257
93
 
258
- ---
259
-
260
- ## Spread with `pp-spread`
261
-
262
- ### Basic usage
263
-
264
- ```html
265
- <button pp-spread="{...btn}">Submit</button>
266
-
267
- <script>
268
- const [btn] = pp.state({
269
- class: "px-3 py-2 rounded-md",
270
- "aria-label": "submit",
271
- });
272
- </script>
273
- ```
274
-
275
- ### Multiple spreads
94
+ Example:
276
95
 
277
96
  ```html
278
- <input pp-spread="{...base, ...validation}" placeholder="Name" />
279
-
280
- <script>
281
- const [base] = pp.state({ class: "input-base", required: true });
282
- const [validation] = pp.state({ pattern: "[A-Za-z]+" });
283
- </script>
97
+ <div pp-component="focus-box">
98
+ <input pp-ref="nameInput" />
99
+ <button onclick="nameInput.current?.focus()">Focus</button>
100
+
101
+ <script type="text/pp">
102
+ const nameInput = pp.ref(null);
103
+ </script>
104
+ </div>
284
105
  ```
285
106
 
286
- Rules:
107
+ ## Lists and loops
287
108
 
288
- - Later spreads override earlier spreads.
289
- - Explicit attributes on the element override spread values.
290
-
291
- ---
109
+ - Use `pp-for` only on `<template>`.
110
+ - Supported forms are `item in items` and `(item, index) in items`.
111
+ - The collection must be an array. Non-arrays are treated as empty lists.
112
+ - Loop content can contain interpolations, events, refs, and nested components.
113
+ - Use stable unique `key` values on repeated elements.
114
+ - Duplicate keys can trigger warnings, so do not use random keys.
292
115
 
293
- ## Lists with `pp-for`
116
+ Example:
294
117
 
295
118
  ```html
296
119
  <ul>
297
- <template pp-for="todo in todos">
120
+ <template pp-for="(todo, index) in todos">
298
121
  <li key="{todo.id}">
299
- {todo.title}
122
+ {index + 1}. {todo.title}
300
123
  <button onclick="removeTodo(todo.id)">Remove</button>
301
124
  </li>
302
125
  </template>
303
126
  </ul>
304
127
 
305
- <script>
128
+ <script type="text/pp">
306
129
  const [todos, setTodos] = pp.state([
307
130
  { id: 1, title: "First task" },
308
131
  { id: 2, title: "Second task" },
309
132
  ]);
310
133
 
311
134
  function removeTodo(id) {
312
- setTodos(todos.filter((item) => item.id !== id));
135
+ setTodos(todos.filter((todo) => todo.id !== id));
313
136
  }
314
137
  </script>
315
138
  ```
316
139
 
317
- Rules:
318
-
319
- - Use `pp-for` only on `<template>`.
320
- - Always use stable keys such as IDs or stable indices.
321
- - Never use random keys.
322
- - Prefer immutable updates through setters.
323
-
324
- ---
325
-
326
- ## Effects with `pp.effect`
327
-
328
- ```html
329
- <script>
330
- pp.effect(() => console.log("Any change"));
331
-
332
- pp.effect(() => {
333
- return () => {
334
- // cleanup
335
- };
336
- }, []);
337
-
338
- const [count, setCount] = pp.state(0);
339
-
340
- pp.effect(() => {
341
- console.log("count", count);
342
- }, [count]);
343
- </script>
344
- ```
345
-
346
- Rules:
140
+ ## Events
347
141
 
348
- - Use `[]` for one-time setup and cleanup.
349
- - Use dependency arrays to react to specific state changes.
350
- - Avoid unconditional setter calls inside effects.
351
- - Guard effect-driven updates to prevent loops.
142
+ - Use native `on*` attributes such as `onclick`, `oninput`, and `onsubmit`.
143
+ - Event values may be raw code or wrapped in `{...}`.
144
+ - The runtime injects `event`, `e`, `$event`, `target`, `currentTarget`, and `el`.
145
+ - Do not use hyphenated event attrs like `on-click`.
146
+ - Handlers are rebound after DOM morphing, so do not assume one-time binding.
352
147
 
353
- ---
148
+ ## SPA, loading, and navigation helpers
354
149
 
355
- ## Input binding patterns
150
+ - `body[pp-spa="true"]` enables client-side navigation interception.
151
+ - `a[pp-spa="false"]` disables interception for that link.
152
+ - `pp-loading-content="true"` marks the page region that gets swapped during navigation.
153
+ - `pp-loading-url` selects route-specific loading states.
154
+ - `pp-loading-transition` accepts JSON with `fadeIn` and `fadeOut` timing values.
155
+ - `pp-reset-scroll="true"` resets scroll positions during navigation.
356
156
 
357
- ### Checkbox
157
+ The runtime also exposes navigation and bridge helpers through `pp`:
358
158
 
359
- ```html
360
- <input
361
- type="checkbox"
362
- checked="{isActive}"
363
- onchange="setIsActive(event.target.checked)"
364
- />
365
-
366
- <script>
367
- const [isActive, setIsActive] = pp.state(false);
368
- </script>
369
- ```
370
-
371
- ### Text input
159
+ - `pp.mount()`
160
+ - `pp.redirect(url)`
161
+ - `pp.fetchFunction(name, data?, optionsOrAbort?)`
162
+ - `pp.enablePerf()`
163
+ - `pp.disablePerf()`
164
+ - `pp.getPerfStats()`
165
+ - `pp.resetPerfStats()`
372
166
 
373
- ```html
374
- <input type="text" value="{name}" oninput="setName(event.target.value)" />
375
-
376
- <script>
377
- const [name, setName] = pp.state("");
378
- </script>
379
- ```
167
+ Notes:
380
168
 
381
- Rules:
169
+ - `pp.redirect()` uses SPA navigation when it is enabled and the URL is same-origin; otherwise it falls back to normal navigation.
170
+ - `pp.fetchFunction()` is the runtime RPC bridge. It posts to the current route, attaches the wire headers the backend expects, and can switch to FormData for files, report upload progress, abort the previous request, or stream responses when supported.
171
+ - The bundle mounts the runtime automatically once the global `pp` singleton is accessed after DOMContentLoaded, but `pp.mount()` exists if you want to trigger it explicitly.
382
172
 
383
- - Inputs should read from state.
384
- - Inputs should write back through explicit setters.
385
- - Avoid mixing manual DOM querying with reactive state for the same value.
173
+ ## Plain HTML bundle usage
386
174
 
387
- ---
175
+ When the app is shipped as plain HTML plus a minified bundle:
388
176
 
389
- ## Forbidden patterns
177
+ - Keep the component markup in the HTML.
178
+ - Load the bundle with a script tag after the markup or with `defer`.
179
+ - Keep component logic inside `<script type="text/pp">` blocks in the HTML.
180
+ - Do not assume access to the TypeScript source at runtime.
390
181
 
391
- Do not generate these unless the official PulsePoint docs explicitly document them:
182
+ ## What to avoid
392
183
 
393
- 1. Undocumented runtime APIs
394
- 2. Undocumented directives
395
- 3. `pp-for` on non-`<template>` elements
396
- 4. Random keys in rendered lists
397
- 5. Multiple scattered script blocks for normal PulsePoint pages
398
- 6. Direct DOM mutation for stateful UI that should be reactive
399
- 7. Backend-specific assumptions in PulsePoint-only snippets
400
- 8. Syntax copied from another framework without PulsePoint documentation support
184
+ Do not generate these unless the current source explicitly supports them:
401
185
 
402
- ---
186
+ - `pp-context`
187
+ - `pp-key`
188
+ - `data-pp-ref`
189
+ - `pp-owner`
190
+ - `pp-event-owner`
191
+ - `pp-dynamic-script`
192
+ - `pp-dynamic-meta`
193
+ - `pp-dynamic-link`
194
+ - plain `<script>` for component logic inside a component root
195
+ - React, Vue, Svelte, or JSX-style component patterns that are not implemented here
196
+ - made-up hooks, directives, or globals not present in the current TypeScript source
403
197
 
404
- ## How AI should respond when PulsePoint is involved
198
+ ## AI checklist
405
199
 
406
- When a user asks for PulsePoint code, the AI should:
200
+ When working on PulsePoint code, follow this order:
407
201
 
408
- 1. Check the official PulsePoint docs first.
409
- 2. Keep the solution inside documented PulsePoint primitives.
410
- 3. Separate frontend PulsePoint behavior from backend implementation details.
411
- 4. Avoid claiming a PulsePoint feature exists unless the docs support it.
412
- 5. Prefer working examples that are ready to paste into a project.
413
-
414
- A good PulsePoint answer should feel:
415
-
416
- - minimal
417
- - explicit
418
- - backend-agnostic when appropriate
419
- - syntactically valid
420
- - faithful to the documented runtime
421
-
422
- ---
202
+ - Use the current TypeScript source when it is available.
203
+ - If only HTML plus a minified bundle exists, inspect those artifacts and follow the runtime behavior implemented there.
204
+ - Keep template-facing variables at the top level of the component script.
205
+ - Use only the hooks, directives, and attributes listed above.
206
+ - Keep `pp-for` on `<template>` and use plain `key`.
207
+ - Use refs and events as implemented, not as they work in another framework.
208
+ - Avoid generating internal runtime attributes.
423
209
 
424
210
  ## Final reminder
425
211
 
426
- If you are generating, reviewing, or refactoring PulsePoint code, do **not** guess.
427
-
428
- Read the official docs first:
429
-
430
- ```txt
431
- https://pulsepoint.tsnc.tech/llms
432
- ```
433
-
434
- Then generate code using documented PulsePoint behavior only.
212
+ If a feature is not implemented in the current runtime source, do not invent it.
@@ -7,6 +7,7 @@ related:
7
7
  description: Learn more about route handlers in Prisma PHP.
8
8
  links:
9
9
  - /docs/route-php
10
+ - /docs/php-validator
10
11
  - /docs/index-php
11
12
  - /docs/pages-and-layouts
12
13
  ---
@@ -109,6 +110,7 @@ A good handler pattern is:
109
110
  5. return structured JSON for expected validation failures
110
111
 
111
112
  This keeps the handler consistent whether the request came from a form, a `fetch()` call, or another client.
113
+ For the full local validation guidance, read `validator.md` alongside this page.
112
114
 
113
115
  ## Request Helper
114
116