fastify-auto-sqlapi 0.1.10 → 0.1.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.
Files changed (57) hide show
  1. package/AGENTS.md +1 -1
  2. package/AGENTS_BACKEND.md +76 -2
  3. package/AGENTS_FRONTEND.md +69 -545
  4. package/BREAKING_CHANGES.md +63 -0
  5. package/CHANGELOG.md +96 -0
  6. package/README.md +98 -11
  7. package/dist/index.d.ts +5 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +6 -1
  10. package/dist/lib/agent/manifest.d.ts +53 -0
  11. package/dist/lib/agent/manifest.d.ts.map +1 -0
  12. package/dist/lib/agent/manifest.js +153 -0
  13. package/dist/lib/agent/tool-schemas.d.ts +36 -0
  14. package/dist/lib/agent/tool-schemas.d.ts.map +1 -0
  15. package/dist/lib/agent/tool-schemas.js +47 -0
  16. package/dist/lib/cli/schema-codegen.d.ts.map +1 -1
  17. package/dist/lib/cli/schema-codegen.js +9 -1
  18. package/dist/lib/engine/bulk/bulk-delete.d.ts.map +1 -1
  19. package/dist/lib/engine/bulk/bulk-delete.js +5 -1
  20. package/dist/lib/engine/rest/delete.d.ts.map +1 -1
  21. package/dist/lib/engine/rest/delete.js +4 -1
  22. package/dist/lib/engine/rest/get.d.ts.map +1 -1
  23. package/dist/lib/engine/rest/get.js +4 -1
  24. package/dist/lib/engine/search/search.d.ts.map +1 -1
  25. package/dist/lib/engine/search/search.js +8 -2
  26. package/dist/lib/nullable.d.ts +17 -0
  27. package/dist/lib/nullable.d.ts.map +1 -0
  28. package/dist/lib/nullable.js +24 -0
  29. package/dist/lib/schema/search.d.ts +11 -9
  30. package/dist/lib/schema/search.d.ts.map +1 -1
  31. package/dist/lib/schema/search.js +27 -10
  32. package/dist/lib/table-helpers.d.ts.map +1 -1
  33. package/dist/lib/table-helpers.js +12 -2
  34. package/dist/routes/auto/agent-manifest.routes.d.ts +12 -0
  35. package/dist/routes/auto/agent-manifest.routes.d.ts.map +1 -0
  36. package/dist/routes/auto/agent-manifest.routes.js +30 -0
  37. package/dist/routes/auto/bulk-delete.routes.d.ts.map +1 -1
  38. package/dist/routes/auto/bulk-delete.routes.js +1 -0
  39. package/dist/routes/auto/delete.routes.d.ts.map +1 -1
  40. package/dist/routes/auto/delete.routes.js +1 -0
  41. package/dist/routes/auto/get.routes.d.ts.map +1 -1
  42. package/dist/routes/auto/get.routes.js +1 -0
  43. package/dist/routes/auto/plugin.d.ts.map +1 -1
  44. package/dist/routes/auto/plugin.js +4 -0
  45. package/dist/routes/auto/route-helpers.d.ts +7 -0
  46. package/dist/routes/auto/route-helpers.d.ts.map +1 -1
  47. package/dist/routes/auto/route-helpers.js +11 -0
  48. package/dist/routes/auto/search.routes.js +3 -3
  49. package/dist/types/plugin.d.ts +7 -0
  50. package/dist/types/plugin.d.ts.map +1 -1
  51. package/dist/types/table.d.ts +6 -0
  52. package/dist/types/table.d.ts.map +1 -1
  53. package/dist/types/table.js +8 -0
  54. package/docs/adr/0007-explicit-table-generation.md +39 -0
  55. package/docs/adr/0008-agent-client-interface.md +66 -0
  56. package/docs/adr/README.md +2 -0
  57. package/package.json +1 -1
@@ -0,0 +1,39 @@
1
+ # 0007. Table generation is explicit — `--all` is a migration helper, not the default
2
+
3
+ - **Status**: accepted
4
+ - **Date**: 2026-07-23
5
+
6
+ ## Context
7
+
8
+ `sqlapi-generate-schema` with no arguments introspects every table, while
9
+ `sqlapi-generate-tables` with no arguments prints usage and exits, requiring `--all` or
10
+ explicit table names. A review flagged the opposite defaults as an inconsistency to
11
+ harmonize.
12
+
13
+ ## Decision
14
+
15
+ The asymmetry is deliberate and stays. The two generators have different roles:
16
+
17
+ - **Schemas** are disposable mirrors of the database — regenerating all of them is always
18
+ correct, so "all" is the natural default.
19
+ - **Table files are the consumer's working set**: which tables become API endpoints is a
20
+ deliberate choice, and it is legitimate to keep tables out of `DbTables`. The intended
21
+ flow is *"I added a table, I generate its Table file explicitly"*
22
+ (`sqlapi-generate-tables customer`). If the default were "all", every run would
23
+ resurrect Table files the consumer had deliberately deleted, forcing them to delete the
24
+ same files again and again. `--all` exists only as a bootstrap helper when introducing
25
+ the plugin into an existing codebase.
26
+
27
+ ## Alternatives considered
28
+
29
+ - **Default to `--all` (mirror generate-schema)** — rejected: re-creates deleted Table
30
+ files on every run, fighting the consumer's curation of the exposed surface.
31
+ - **Tracking deleted tables** (a skip-list) — rejected: state to maintain for a problem
32
+ explicit invocation solves for free.
33
+
34
+ ## Consequences
35
+
36
+ - `sqlapi-generate-tables` keeps requiring `--all` or table names; running it bare prints
37
+ usage and exits non-zero.
38
+ - The generator never overwrites existing Table files, so both the explicit and the
39
+ `--all` flow are safe to re-run.
@@ -0,0 +1,66 @@
1
+ # 0008. Agent client interface: static grammar + runtime manifest
2
+
3
+ - **Status**: accepted
4
+ - **Date**: 2026-07-26
5
+
6
+ ## Context
7
+
8
+ The plugin doubles as the enforcement layer for LLM clients that drive the API at runtime
9
+ (a chat agent operating on backoffice data: whatever requests the model invents, tenant
10
+ scoping, `readExclude`, `operations` and caps still apply). Such a client needs to be
11
+ told how to call the API — but an LLM prompt has different constraints than human
12
+ documentation: every line costs tokens on every call, and anything deployment-specific
13
+ goes stale the moment the schema changes.
14
+
15
+ ## Decision
16
+
17
+ The client-facing documentation is split into two halves with different lifecycles:
18
+
19
+ - **Grammar** — `AGENTS_FRONTEND.md`: HOW to call the API (endpoints, search with the four
20
+ join families, condition methods with params arity, ordering notations, pagination,
21
+ writes, error shapes). Static, identical for every deployment, ~110 dense lines designed
22
+ for a system prompt. It deliberately contains **no tables, fields or aliases**.
23
+ - **Vocabulary** — the manifest (`agentManifest: true` → `GET {prefix}/agent/manifest(.md)`,
24
+ or `buildAgentManifest()` programmatically): WHAT this deployment exposes — tables,
25
+ fields with type/required/nullable, enabled operations, join aliases with direction,
26
+ computed fields. Generated from `DbTables` at startup, so it can never drift from the
27
+ running configuration.
28
+
29
+ Three deliberate properties:
30
+
31
+ 1. **The grammar file replaced the old tutorial-style `AGENTS_FRONTEND.md` under the same
32
+ filename.** The path `node_modules/fastify-auto-sqlapi/AGENTS_FRONTEND.md` is known to
33
+ consumers' coding agents; a new filename would have broken every existing reference for
34
+ zero benefit. Do not rename it.
35
+ 2. **Density is a feature, not a documentation gap.** The file lives in LLM system
36
+ prompts: jsonc examples with terse end-of-line comments, no rationale, no repetition —
37
+ each concept appears exactly once. Normative rules (what returns 400) belong in it;
38
+ explanations do not. Expanding it with prose and tutorials would revert this decision.
39
+ 3. **Loose validation with the structured 400 as retry signal is the default strategy**
40
+ for LLM tools; strict per-table JSON-Schema tools are opt-in via `agentToolSchemas()`.
41
+ The plugin's 400 (`fields: [{path, code, message}]`) was designed machine-readable, so
42
+ a loose generic tool self-corrects in one round trip. This is also why the plugin does
43
+ not ship an opinionated MCP/tool layer: it provides the pieces (grammar, manifest,
44
+ schemas), the consumer composes them.
45
+
46
+ ## Alternatives considered
47
+
48
+ - **One complete document (grammar + tables of a given deployment)** — rejected: the
49
+ deployment-specific half goes stale on every schema change; the manifest endpoint is
50
+ the only source that cannot drift.
51
+ - **A new `AGENT_CLIENT.md` alongside the old `AGENTS_FRONTEND.md`** — rejected: near-total
52
+ content overlap, proven drift risk (a fix had to be applied to both files during the
53
+ same session that created the second one), and known-path breakage on removal.
54
+ - **Strict JSON-Schema tools as the default** — rejected: the full search schema per
55
+ table is enormous (conditions, four join families, per-alias shapes); across N tables
56
+ it explodes prompt size and degrades model performance. Kept as opt-in for hot tables.
57
+
58
+ ## Consequences
59
+
60
+ - `AGENTS_FRONTEND.md` serves both coding agents (writing client code) and runtime LLM
61
+ clients; the verbose tutorial content it replaced is covered by the grammar plus
62
+ Swagger.
63
+ - Contributions that add tables/fields/examples-with-prose to the grammar file, or rename
64
+ it, should be declined with a pointer to this ADR.
65
+ - New request-shape features must update the grammar (a rule line, not a tutorial) and,
66
+ when they touch per-table capabilities, the manifest builder.
@@ -21,6 +21,8 @@ not by editing history.
21
21
  | [0004](./0004-updates-always-open.md) | Updates are always open — no `excludeFromUpdate` |
22
22
  | [0005](./0005-insert-pipeline-sanitize-before-hooks.md) | Insert pipeline: client payload sanitized before `beforeInsert` |
23
23
  | [0006](./0006-raw-db-errors.md) | Raw DB errors surface as 500 — no SQLSTATE→HTTP mapping |
24
+ | [0007](./0007-explicit-table-generation.md) | Table generation is explicit — `--all` is a migration helper, not the default |
25
+ | [0008](./0008-agent-client-interface.md) | Agent client interface: static grammar + runtime manifest |
24
26
 
25
27
  ## When to write one
26
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-auto-sqlapi",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Fastify plugin for automatic CRUD API generation from PostgreSQL, MySQL and MariaDB tables",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",