🗑️ chore: remove outdated instructions and migration documentation
This commit is contained in:
47
api/hooks/AGENTS.md
Normal file
47
api/hooks/AGENTS.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# API Hooks (tibi-server)
|
||||
|
||||
Hook files run inside the tibi-server Go runtime (goja).
|
||||
|
||||
## Conventions
|
||||
|
||||
- Wrap hook files in an IIFE: `;(function () { ... })()`.
|
||||
- Always return a HookResponse type or throw a HookException type.
|
||||
- Use inline type casting with `/** @type {TypeName} */ (value)` and typed collection entries from `types/global.d.ts`.
|
||||
- Avoid `@ts-ignore`; use proper casting instead.
|
||||
- Use `const` and `let` instead of `var`. The tibi-server runtime supports modern JS declarations.
|
||||
|
||||
## context.filter — Go object quirk
|
||||
|
||||
`context.filter` is not a regular JS object but a Go object. Even when empty, it is **truthy**.
|
||||
Always check with `Object.keys()`:
|
||||
|
||||
```js
|
||||
const requestedFilter =
|
||||
context.filter &&
|
||||
typeof context.filter === "object" &&
|
||||
!Array.isArray(context.filter) &&
|
||||
Object.keys(context.filter).length > 0
|
||||
? context.filter
|
||||
: null
|
||||
```
|
||||
|
||||
**Never** use `context.filter || null` — it is always truthy and results in an empty filter object inside `$and`, which crashes the Go server.
|
||||
|
||||
## Single-item vs. list retrieval
|
||||
|
||||
For single-item retrieval (`GET /:collection/:id`), the Go server sets `_id` automatically from the URL parameter.
|
||||
GET read hooks should therefore **not set their own `_id` filter** for `req.param("id")`;
|
||||
instead, only add authorization filters (e.g. `{ userId: userId }`).
|
||||
|
||||
## HookResponse fields for GET hooks
|
||||
|
||||
- `filter` — MongoDB filter (list retrieval only, or to restrict single-item retrieval)
|
||||
- `selector` — MongoDB projection (`{ fieldName: 0 }` to exclude, `{ fieldName: 1 }` to include)
|
||||
- `offset`, `limit`, `sort` — pagination/sorting
|
||||
- `pipelineMod` — function to manipulate the aggregation pipeline
|
||||
|
||||
## Related tests
|
||||
|
||||
- When creating or modifying collections/hooks: extend or create corresponding API tests in `tests/api/`.
|
||||
- After hook changes, run only affected API tests: `npx playwright test tests/api/filename.spec.ts`.
|
||||
- When tests fail, clarify whether the hook or the test needs adjustment — coordinate with the user.
|
||||
24
api/hooks/ssr/AGENTS.md
Normal file
24
api/hooks/ssr/AGENTS.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# SSR and Caching
|
||||
|
||||
Server-side rendering via goja (Go JS runtime) with HTML caching.
|
||||
|
||||
## Request flow
|
||||
|
||||
1. `get_read.js` receives the request and calls `lib/ssr-server.js`.
|
||||
2. `ssr-server.js` renders the Svelte app via `lib/app.server.js` and injects `window.__SSR_CACHE__`.
|
||||
3. On the client, `lib/ssr.js` hydrates using the injected cache data.
|
||||
4. Rendered HTML is stored in the `ssr` collection with dependency tracking.
|
||||
|
||||
## Build
|
||||
|
||||
- SSR bundle is built via `yarn build:server` and outputs to `lib/app.server.js`.
|
||||
- The build uses `--banner:js='// @ts-nocheck'` to suppress type errors in the generated bundle.
|
||||
|
||||
## Cache invalidation
|
||||
|
||||
- `clear_cache.js` hook invalidates SSR cache entries based on collection dependencies.
|
||||
- When content changes, only SSR entries that depend on the changed collection/entry are cleared.
|
||||
|
||||
## Route validation
|
||||
|
||||
SSR route validation is currently disabled and returns -1 in `config.js`; update this when enabling SSR per route.
|
||||
Reference in New Issue
Block a user