create-backon 0.10.0 → 0.13.0

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/README.md CHANGED
@@ -104,7 +104,19 @@ and regenerates `src/endpoints/index.ts` so the new route is mounted next
104
104
  to the ones that were already there. It refuses to run outside a backon
105
105
  project, refuses a route name whose folder already exists, and refuses a
106
106
  name that's already mounted. Run `add-method` next to give the new route
107
- an actual GET/POST/etc.
107
+ an actual GET/POST/etc — or add `--crud` to wire up the standard five in
108
+ one go instead of one at a time:
109
+
110
+ ```
111
+ bun run add-route users --crud
112
+ ```
113
+
114
+ Adds `list` (GET /), `create` (POST /), `getById` (GET /:id), `update`
115
+ (PUT /:id), and `remove` (DELETE /:id) right after creating the route —
116
+ the exact same names `add-method`'s own suggestions already default to,
117
+ just all five at once. Leave `--crud` off (or say no to the "Scaffold
118
+ standard CRUD methods now?" prompt when running `add-route` with no name)
119
+ to get the usual blank endpoint instead.
108
120
 
109
121
  ## Adding a method to a route
110
122
 
@@ -133,6 +145,13 @@ told to stop, so a whole endpoint's worth of methods is normally one
133
145
  `bun run add-method` session. Refuses a method name or a verb+path pair
134
146
  that's already there.
135
147
 
148
+ Every file edit here (and in `remove-method`, below) goes through a real
149
+ TypeScript/JavaScript AST ([ts-morph](https://ts-morph.com)) rather than
150
+ matching raw text — an import is recognized as already present by its
151
+ actual structure, and a method's own statements are found by the exact
152
+ name `add-method` already enforces is unique per endpoint. A hand-reformatted
153
+ mount line or import doesn't throw either operation off.
154
+
136
155
  ## Removing a route
137
156
 
138
157
  The undo for `add-route`:
@@ -206,7 +225,8 @@ bun run server-config
206
225
  or `bunx create-backon server-config`. The interactive alternative to
207
226
  running `add-route`/`add-method`/`remove-route` individually — opens with
208
227
  the same endpoint dashboard `project` shows, then a menu: add a new
209
- endpoint, remove one, add a method, remove a method, or modify a method
228
+ endpoint (with the same "scaffold standard CRUD methods now?" prompt
229
+ `add-route` offers), remove one, add a method, remove a method, or modify a method
210
230
  (change its path, name, or body/query validation in place — the one thing
211
231
  none of the standalone commands offer, since it's a checked
212
232
  remove-then-re-add rather than a new codegen path). Loops back to the menu
@@ -217,7 +237,54 @@ commands rather than one combined dashboard — "show me what's here" and
217
237
  can also accidentally edit something isn't actually a safe overview.
218
238
  `add-route`/`add-method`/`remove-route`/`list-routes`/`doctor` all keep
219
239
  working exactly as documented above; `server-config` is a wrapper around
220
- the same underlying logic, not a replacement for them.
240
+ the same underlying logic, not a replacement for them. On a `neon`/`postgres`
241
+ project, the same menu also has "Add a database table"/"Remove a database
242
+ table" — see the next section.
243
+
244
+ ## Managing the database schema
245
+
246
+ Only for the `neon`/`postgres` db choices — both speak the same Postgres
247
+ schema dialect (`drizzle-orm/pg-core`), which is what makes one implementation
248
+ cover both. SQLite uses different column builders entirely and isn't
249
+ supported here yet; `add-table`/`remove-table` refuse with a clear message
250
+ on a `sqlite`/`none` project rather than doing something wrong silently.
251
+
252
+ ```
253
+ bun run add-table
254
+ ```
255
+
256
+ or `bunx create-backon add-table` (`table` also works, and a name can be
257
+ passed as an argument: `add-table users`). Walks through a table name, an
258
+ "add an auto-increment id primary key column?" question, and then columns
259
+ one at a time — name, type (`text`/`integer`/`boolean`/`timestamp`/`uuid`),
260
+ required/unique, and a type-appropriate default (`.defaultNow()` for
261
+ timestamps, `.defaultRandom()` for uuid, a literal for text/integer/boolean).
262
+ A column can also reference another table's `id` instead of picking a type —
263
+ rendered as the idiomatic `integer(...).references(() => otherTable.id)`
264
+ pattern. Loops to "add another table?" until told to stop.
265
+
266
+ Every call only edits `src/config/schema.<ext>` — appending a real
267
+ `pgTable(...)` export and merging into the shared `drizzle-orm/pg-core`
268
+ import rather than duplicating it. **Nothing here ever touches the actual
269
+ database** — `bun run db:generate`/`db:migrate`/`db:push` (from
270
+ drizzle-kit, wired into every `neon`/`postgres` project's `package.json`)
271
+ are separate, explicit commands you run yourself when ready. See the
272
+ generated README's "Table schema" section for the `generate`+`migrate` vs.
273
+ `push` tradeoff.
274
+
275
+ `bun run remove-table` (`rm-table` also works) is the undo: picks a table,
276
+ confirms, removes its `pgTable(...)` export, and prunes any `pg-core`
277
+ builder nothing else in the file still uses. Refuses to remove a table
278
+ another table's column still references — leaving that in place would
279
+ compile fine but throw a real `ReferenceError` the moment drizzle-kit or
280
+ `db.query` tried to resolve it, so this is caught here instead. Removing
281
+ the last table resets `schema.<ext>` to its blank, freshly-scaffolded
282
+ stub, matching how `remove-method` resets a route's files when its last
283
+ method goes.
284
+
285
+ Both are also in `server-config`'s menu (see above), single-shot rather
286
+ than their own standalone "add another?" loop — `server-config`'s own
287
+ loop already re-shows state and re-prompts after every action.
221
288
 
222
289
  ## Generating API docs
223
290
 
@@ -242,6 +309,37 @@ same spec and reference page as live routes on a running server instead of
242
309
  writing them to disk — useful for CI, static hosting, or feeding the spec
243
310
  into an external tool, where `serveApiDocs`'s live routes don't apply.
244
311
 
312
+ ## Generating a typed API client
313
+
314
+ Every generated project also includes:
315
+
316
+ ```
317
+ bun run generate-client
318
+ ```
319
+
320
+ Writes `client/api.<ext>` — a fetch client with one function per mounted
321
+ method, grouped by endpoint (`usersApi.list()`, `usersApi.create(body)`,
322
+ `usersApi.getById(id)`, and so on), read directly off `*.routes.<ext>`/
323
+ `*.controller.<ext>` — the same files `add-method`/`remove-method`/
324
+ `server-config` already write, so there's nothing to keep in sync by hand.
325
+ Backed by `scripts/generate-client.<ext>`, generated alongside everything
326
+ else; unlike `generate-docs.<ext>` it doesn't import `src/app` — it reads
327
+ the endpoint files directly, so it can't fail because `app.ts` throws on a
328
+ missing env var. It also never goes stale on its own: it re-discovers
329
+ routes fresh every time it *runs*, so only its output needs a re-run after
330
+ routes or methods change, not the script itself.
331
+
332
+ In TypeScript projects, each generated function's body/query parameters
333
+ are typed via `z.infer<typeof theSchema>` against the schema the
334
+ controller already exports — imported by type, not re-declared, so the
335
+ client's argument types can't drift from what `defineRoute()` actually
336
+ validates. Response shape is deliberately not claimed beyond an optional
337
+ `<T = unknown>` generic per call (`usersApi.list<User[]>()`) — backon
338
+ doesn't validate responses, so nothing here pretends to know a shape it
339
+ can't verify. JavaScript projects get the same functions with no type
340
+ annotations. `client/` is a build artifact like `openapi.json`/`docs.html`,
341
+ not source, so it's in the generated `.gitignore` by default.
342
+
245
343
  ## Deploying to Vercel
246
344
 
247
345
  Picking Vercel at the "Where's this headed?" prompt adds two things, both