fastify-auto-sqlapi 0.0.1 → 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.
- package/AGENTS.md +56 -0
- package/AGENTS_BACKEND.md +833 -0
- package/AGENTS_FRONTEND.md +414 -0
- package/README.md +19 -1
- package/dist/bin/generate-tables.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/cli/pg-introspect.d.ts.map +1 -1
- package/dist/lib/cli/pg-introspect.js +8 -1
- package/dist/lib/cli/tables-codegen.d.ts.map +1 -1
- package/dist/lib/cli/tables-codegen.js +28 -0
- package/dist/lib/engine/bulk/bulk-upsert.d.ts.map +1 -1
- package/dist/lib/engine/bulk/bulk-upsert.js +14 -4
- package/dist/lib/engine/rest/insert.d.ts.map +1 -1
- package/dist/lib/engine/rest/insert.js +8 -5
- package/dist/lib/engine/rest/update.d.ts.map +1 -1
- package/dist/lib/engine/rest/update.js +8 -5
- package/dist/lib/engine/validate.d.ts +11 -0
- package/dist/lib/engine/validate.d.ts.map +1 -0
- package/dist/lib/engine/validate.js +29 -0
- package/dist/lib/schema/bulk-upsert.js +2 -2
- package/dist/lib/schema/helpers.d.ts +5 -0
- package/dist/lib/schema/helpers.d.ts.map +1 -1
- package/dist/lib/schema/helpers.js +15 -0
- package/dist/lib/schema/insert.js +2 -2
- package/dist/lib/schema/update.d.ts.map +1 -1
- package/dist/lib/schema/update.js +4 -3
- package/dist/routes/auto/plugin.d.ts.map +1 -1
- package/dist/routes/auto/plugin.js +12 -1
- package/dist/types.d.ts +21 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
package/AGENTS.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# fastify-auto-sqlapi — Agent Instructions
|
|
2
|
+
|
|
3
|
+
You are configuring a Fastify server that uses `fastify-auto-sqlapi` to auto-generate CRUD APIs from database tables. Follow these instructions precisely.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The plugin generates REST endpoints (search, get, insert, update, delete, bulk upsert, bulk delete) from database table definitions. No ORM — raw SQL. Supports **PostgreSQL**, **MySQL**, and **MariaDB**. The consumer defines table configurations, and the plugin handles routing, validation, and query execution.
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
- **[AGENTS_BACKEND.md](./AGENTS_BACKEND.md)** — Setup workflow, CLI, schema/table generation, `defineTable()` complete reference, `buildRelation`, `extraFilters` + `extendedCondition`, **SqlApi** (programmatic high-level API for custom routes), ConditionBuilder API, QueryClient API, Swagger, multi-tenant configuration, **validation** (`validate` + `validateBulk`), hooks, key conventions, common backend patterns, FAQ/gotchas, dialect differences.
|
|
12
|
+
|
|
13
|
+
- **[AGENTS_FRONTEND.md](./AGENTS_FRONTEND.md)** — Generated endpoints overview, search (POST with body filters, conditions/advanced filters using ConditionBuilder methods, query params for ordering/pagination/aggregation), joinFilters (EXISTS-based filtering by related tables), GET, INSERT (with secondaries), UPDATE (with secondaries + deletions), DELETE, bulk upsert, bulk delete, response shapes (PK-only), **validation errors** (structured field-level 400 responses), joins usage, joinGroups/aggregations, pagination, computed values.
|
|
14
|
+
|
|
15
|
+
## Quick Reference
|
|
16
|
+
|
|
17
|
+
### Generated endpoints
|
|
18
|
+
|
|
19
|
+
For a table `customer` with `prefix: '/auto'`:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
POST /auto/search/customer — search with filters in body
|
|
23
|
+
GET /auto/rest/customer/:id — get single record by PK
|
|
24
|
+
POST /auto/rest/customer — insert record (+ secondaries)
|
|
25
|
+
PUT /auto/rest/customer — update record (+ secondaries + deletions)
|
|
26
|
+
DELETE /auto/rest/customer/:id — delete record by PK
|
|
27
|
+
PUT /auto/bulk/customer — bulk upsert (array of items)
|
|
28
|
+
POST /auto/bulk/customer/delete — bulk delete (array of PKs)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Minimal setup
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import Fastify from 'fastify';
|
|
35
|
+
import fastifyPostgres from '@fastify/postgres';
|
|
36
|
+
import { fastifyAutoSqlApi } from 'fastify-auto-sqlapi';
|
|
37
|
+
import { dbTables } from './src/db/tables/dbTables.js';
|
|
38
|
+
|
|
39
|
+
const app = Fastify();
|
|
40
|
+
await app.register(fastifyPostgres, { connectionString: 'postgres://...' });
|
|
41
|
+
await app.register(fastifyAutoSqlApi, { DbTables: dbTables, swagger: true });
|
|
42
|
+
await app.listen({ port: 3000 });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Minimal table definition
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { defineTable, exportTableInfo } from 'fastify-auto-sqlapi';
|
|
49
|
+
import { SchemaCustomer as Schema } from '../schemas/SchemaCustomer';
|
|
50
|
+
|
|
51
|
+
export const TableCustomer = defineTable({
|
|
52
|
+
primary: 'id',
|
|
53
|
+
excludeFromCreation: ['id'], // MUST include auto-increment PKs
|
|
54
|
+
...exportTableInfo(Schema),
|
|
55
|
+
});
|
|
56
|
+
```
|