@aaroncadillac/crudify-mongo 3.1.0 → 3.1.1
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/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/crudify.js +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,10 @@ All notable changes to this project are documented here. The format follows [Kee
|
|
|
8
8
|
|
|
9
9
|
- **`additionalRoutes` was removed** (deprecated since the 2.x line, both the function and the array form). Passing it now throws a `TypeError` at registration pointing to the replacement. Migrate to `routes(api, ctx)` or `actions`. Because this is a breaking change on top of the published 3.0.0, the next release that includes it must be a **major** version.
|
|
10
10
|
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **Bulk `POST` ignored schema defaults when validating.** The array form validated each item with the static `Model.validate(data)`, which does not apply `default`s, so a bulk without a field that has a `default` (and is `required`, e.g. `status`) answered `400` while the same document sent alone worked. Each item is now built once with `new Model(data)`, validated with `doc.validate()` (defaults applied) and the same documents are passed to `Model.create(docs, { validateBeforeSave: false })` (or `insertMany`), so nothing is built or validated twice. Everything is still validated before writing (an invalid item inserts nothing), save hooks run once per document, and `createScope` checks are untouched. Release as a patch (`[patch]`).
|
|
14
|
+
|
|
11
15
|
## [3.1.0] - 2026-10-22
|
|
12
16
|
|
|
13
17
|
### Added
|
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ Without any configuration:
|
|
|
75
75
|
- `options` only honour `page`, `limit` and `sort`. `limit` defaults to 50 and is capped at 100; `populate`, `select`, `lean` and `pagination: false` from the client are ignored.
|
|
76
76
|
- Writes drop `_id`, `__v` and the timestamps, accept no update operators besides `$set` / `$unset`, and refuse operators nested inside values.
|
|
77
77
|
- Fields with `select: false` in your schema cannot be filtered or sorted on (it would be a search oracle).
|
|
78
|
-
- Bulk creation goes through `Model.create`, so `pre('save')` / `post('save')` hooks always run, and an invalid item inserts nothing.
|
|
78
|
+
- Bulk creation goes through `Model.create`, so `pre('save')` / `post('save')` hooks always run, schema defaults are applied before validating, and an invalid item inserts nothing.
|
|
79
79
|
- Errors are mapped to a fixed shape. Duplicate keys become a generic `409`; unexpected errors become `500 Internal error` (the detail goes to your logs, never to the client).
|
|
80
80
|
- Invalid ids answer `404` without touching the database.
|
|
81
81
|
|
package/crudify.js
CHANGED
|
@@ -233,9 +233,10 @@ const createHandlers = (c, ctx) => {
|
|
|
233
233
|
const data = []
|
|
234
234
|
for (const item of isBulk ? req.body : [req.body]) data.push(await prepare(item, req, rules))
|
|
235
235
|
let docs
|
|
236
|
-
if (isBulk) { // validate
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
if (isBulk) { // build each document once (applies schema defaults) and validate all before writing: an invalid item inserts nothing
|
|
237
|
+
const built = data.map(d => new Model(d))
|
|
238
|
+
await Promise.all(built.map(d => d.validate()))
|
|
239
|
+
docs = await (c.bulk.insertMany ? Model.insertMany(built) : Model.create(built, { validateBeforeSave: false })) // create() runs save hooks; already validated
|
|
239
240
|
} else docs = await Model.create(data[0])
|
|
240
241
|
if (hooks.afterCreate) await hooks.afterCreate(docs, req)
|
|
241
242
|
reply.code(201)
|
package/package.json
CHANGED