@classytic/mongokit 3.16.0 → 3.16.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/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { isGeoOperator, parseGeoFilter } from "./query/primitives/geo.mjs";
|
|
|
9
9
|
import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "./field-selection-CQW3WBiK.mjs";
|
|
10
10
|
import { buildFieldTypeMap, coerceFieldValue, coerceHeuristic } from "./query/primitives/coercion.mjs";
|
|
11
11
|
import { extractSchemaIndexes } from "./query/primitives/indexes.mjs";
|
|
12
|
-
import { n as buildCrudSchemasFromMongooseSchema, r as createMemoryCache, t as buildCrudSchemasFromModel } from "./mongooseToJsonSchema-
|
|
12
|
+
import { n as buildCrudSchemasFromMongooseSchema, r as createMemoryCache, t as buildCrudSchemasFromModel } from "./mongooseToJsonSchema-CMM2QHzd.mjs";
|
|
13
13
|
import { isControlParam } from "@classytic/repo-core/query-parser";
|
|
14
14
|
//#region src/create-repository.ts
|
|
15
15
|
function isLoggerAudit(value) {
|
|
@@ -505,10 +505,37 @@ function convertTreeToJsonSchema(tree, options, seen = /* @__PURE__ */ new WeakS
|
|
|
505
505
|
if (required.length) schema.required = required;
|
|
506
506
|
return schema;
|
|
507
507
|
}
|
|
508
|
+
/**
|
|
509
|
+
* Recursively delete every `default` keyword from a JSON-schema subtree
|
|
510
|
+
* (properties, array items, nested subdocuments).
|
|
511
|
+
*
|
|
512
|
+
* A `default` has no place in an UPDATE (PATCH) validator. Hosts that run
|
|
513
|
+
* Fastify/AJV with `useDefaults: true` (arc's `createApp` does) would
|
|
514
|
+
* otherwise have the default INJECTED into any PATCH body that omits the
|
|
515
|
+
* field — and the repository then `$set`s it, silently overwriting stored
|
|
516
|
+
* data on a partial update. The canonical bite: a nullable field carrying
|
|
517
|
+
* `default: null` (e.g. `publishedAt`) gets nulled out on every
|
|
518
|
+
* content-only save, unpublishing the doc. Partial updates must touch only
|
|
519
|
+
* the fields the client actually sent; DB-layer defaults still apply on
|
|
520
|
+
* create via Mongoose. The nullable type widening (`type: [..., 'null']`)
|
|
521
|
+
* stays, so a client may still explicitly send `null` — it just won't be
|
|
522
|
+
* auto-injected.
|
|
523
|
+
*/
|
|
524
|
+
function stripDefaultsDeep(node) {
|
|
525
|
+
if (Array.isArray(node)) {
|
|
526
|
+
for (const item of node) stripDefaultsDeep(item);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (!node || typeof node !== "object") return;
|
|
530
|
+
const obj = node;
|
|
531
|
+
delete obj.default;
|
|
532
|
+
for (const value of Object.values(obj)) stripDefaultsDeep(value);
|
|
533
|
+
}
|
|
508
534
|
function buildJsonSchemaForUpdate(createJson, options) {
|
|
509
535
|
const clone = JSON.parse(JSON.stringify(createJson));
|
|
510
536
|
delete clone.required;
|
|
511
537
|
applyFieldRules(clone, collectFieldsToOmit(options, "update"), options);
|
|
538
|
+
stripDefaultsDeep(clone);
|
|
512
539
|
if (options?.strictAdditionalProperties === true) clone.additionalProperties = false;
|
|
513
540
|
if (options?.update?.requireAtLeastOne === true) clone.minProperties = 1;
|
|
514
541
|
return clone;
|
package/dist/utils/index.mjs
CHANGED
|
@@ -2,5 +2,5 @@ import { t as configureLogger } from "../logger-DprijP5h.mjs";
|
|
|
2
2
|
import { t as createError } from "../error-B00pI7dV.mjs";
|
|
3
3
|
import { n as isObjectIdInstance, r as isValidIdForType, t as getSchemaIdType } from "../id-resolution-DduoO4LI.mjs";
|
|
4
4
|
import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "../field-selection-CQW3WBiK.mjs";
|
|
5
|
-
import { n as buildCrudSchemasFromMongooseSchema, r as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-
|
|
5
|
+
import { n as buildCrudSchemasFromMongooseSchema, r as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-CMM2QHzd.mjs";
|
|
6
6
|
export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getMongooseProjection, getSchemaIdType, isObjectIdInstance, isValidIdForType };
|
package/package.json
CHANGED