@classytic/mongokit 3.7.0 → 3.10.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 +12 -3
- package/dist/{PaginationEngine-CPmZv7Ds.mjs → PaginationEngine-B93fLCcO.mjs} +3 -3
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.mjs +1 -1
- package/dist/ai/index.d.mts +1 -1
- package/dist/{error-Lw9GEAro.mjs → error-CzYwrfUP.mjs} +25 -3
- package/dist/{index-C-qZUqv8.d.mts → index-C7WmYP6F.d.mts} +14 -6
- package/dist/index.d.mts +263 -77
- package/dist/index.mjs +6 -6
- package/dist/{mongooseToJsonSchema-DUwXPStK.mjs → mongooseToJsonSchema-D1sdCOmj.mjs} +21 -103
- package/dist/{mongooseToJsonSchema-Du-UopRK.d.mts → mongooseToJsonSchema-t-MoVleF.d.mts} +20 -19
- package/dist/pagination/PaginationEngine.d.mts +1 -1
- package/dist/pagination/PaginationEngine.mjs +1 -1
- package/dist/plugins/index.d.mts +1 -1
- package/dist/plugins/index.mjs +1 -1
- package/dist/{types-BgdeBXI1.d.mts → types-BUS0Zj8y.d.mts} +70 -133
- package/dist/{update-BDsQ3cdy.mjs → update-CWXfFC6O.mjs} +52 -13
- package/dist/utils/index.d.mts +3 -3
- package/dist/utils/index.mjs +3 -3
- package/dist/{validation-chain.plugin-CEyJssZl.mjs → validation-chain.plugin-Ccu6irtx.mjs} +1081 -381
- package/dist/{validation-chain.plugin-Be9rG04B.d.mts → validation-chain.plugin-JkipjuOR.d.mts} +4 -36
- package/package.json +5 -3
- /package/dist/{cursor-DZ9JSoMM.mjs → cursor-J84rR6wG.mjs} +0 -0
- /package/dist/{sort-ffe-9JBg.mjs → sort-CrZjTK25.mjs} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
2
|
import { r as warn } from "./logger-DJ7egMnd.mjs";
|
|
3
|
-
import { t as createError } from "./error-
|
|
3
|
+
import { t as createError } from "./error-CzYwrfUP.mjs";
|
|
4
4
|
//#region src/query/LookupBuilder.ts
|
|
5
5
|
/** Stages that are never valid inside a $lookup pipeline */
|
|
6
6
|
const BLOCKED_PIPELINE_STAGES = [
|
|
@@ -544,7 +544,11 @@ async function deleteById(Model, id, options = {}) {
|
|
|
544
544
|
_id: id,
|
|
545
545
|
...options.query
|
|
546
546
|
};
|
|
547
|
-
if (!await Model.findOneAndDelete(query).session(options.session ?? null))
|
|
547
|
+
if (!await Model.findOneAndDelete(query).session(options.session ?? null)) return {
|
|
548
|
+
success: false,
|
|
549
|
+
message: "Document not found",
|
|
550
|
+
id: String(id)
|
|
551
|
+
};
|
|
548
552
|
return {
|
|
549
553
|
success: true,
|
|
550
554
|
message: "Deleted successfully",
|
|
@@ -566,11 +570,17 @@ async function deleteMany(Model, query, options = {}) {
|
|
|
566
570
|
*/
|
|
567
571
|
async function deleteByQuery(Model, query, options = {}) {
|
|
568
572
|
const document = await Model.findOneAndDelete(query).session(options.session ?? null);
|
|
569
|
-
if (!document
|
|
573
|
+
if (!document) {
|
|
574
|
+
if (options.throwOnNotFound === true) throw createError(404, "Document not found");
|
|
575
|
+
return {
|
|
576
|
+
success: false,
|
|
577
|
+
message: "Document not found"
|
|
578
|
+
};
|
|
579
|
+
}
|
|
570
580
|
return {
|
|
571
581
|
success: true,
|
|
572
582
|
message: "Deleted successfully",
|
|
573
|
-
|
|
583
|
+
id: String(document._id)
|
|
574
584
|
};
|
|
575
585
|
}
|
|
576
586
|
/**
|
|
@@ -650,7 +660,7 @@ async function getById(Model, id, options = {}) {
|
|
|
650
660
|
if (options.session) query.session(options.session);
|
|
651
661
|
if (options.readPreference) query.read(options.readPreference);
|
|
652
662
|
const document = await query.exec();
|
|
653
|
-
if (!document && options.throwOnNotFound
|
|
663
|
+
if (!document && options.throwOnNotFound === true) throw createError(404, "Document not found");
|
|
654
664
|
return document;
|
|
655
665
|
}
|
|
656
666
|
/**
|
|
@@ -670,7 +680,7 @@ async function getByQuery(Model, query, options = {}) {
|
|
|
670
680
|
if (options.session) mongoQuery.session(options.session);
|
|
671
681
|
if (options.readPreference) mongoQuery.read(options.readPreference);
|
|
672
682
|
const document = await mongoQuery.exec();
|
|
673
|
-
if (!document && options.throwOnNotFound
|
|
683
|
+
if (!document && options.throwOnNotFound === true) throw createError(404, "Document not found");
|
|
674
684
|
return document;
|
|
675
685
|
}
|
|
676
686
|
/**
|
|
@@ -729,6 +739,7 @@ async function exists(Model, query, options = {}) {
|
|
|
729
739
|
//#endregion
|
|
730
740
|
//#region src/actions/update.ts
|
|
731
741
|
var update_exports = /* @__PURE__ */ __exportAll({
|
|
742
|
+
findOneAndUpdate: () => findOneAndUpdate,
|
|
732
743
|
increment: () => increment,
|
|
733
744
|
pullFromArray: () => pullFromArray,
|
|
734
745
|
pushToArray: () => pushToArray,
|
|
@@ -759,15 +770,13 @@ async function update(Model, id, data, options = {}) {
|
|
|
759
770
|
_id: id,
|
|
760
771
|
...options.query
|
|
761
772
|
};
|
|
762
|
-
|
|
773
|
+
return await Model.findOneAndUpdate(query, data, {
|
|
763
774
|
returnDocument: "after",
|
|
764
775
|
runValidators: true,
|
|
765
776
|
session: options.session,
|
|
766
777
|
...options.updatePipeline !== void 0 ? { updatePipeline: options.updatePipeline } : {},
|
|
767
778
|
...options.arrayFilters ? { arrayFilters: options.arrayFilters } : {}
|
|
768
|
-
}).select(options.select || "").populate(parsePopulate(options.populate)).lean(options.lean ?? false);
|
|
769
|
-
if (!document) throw createError(404, "Document not found");
|
|
770
|
-
return document;
|
|
779
|
+
}).select(options.select || "").populate(parsePopulate(options.populate)).lean(options.lean ?? false) ?? null;
|
|
771
780
|
}
|
|
772
781
|
/**
|
|
773
782
|
* Update with query constraints (optimized)
|
|
@@ -824,9 +833,17 @@ async function updateWithValidation(Model, id, data, validationOptions = {}, opt
|
|
|
824
833
|
}
|
|
825
834
|
};
|
|
826
835
|
}
|
|
836
|
+
const updated = await update(Model, id, data, options);
|
|
837
|
+
if (!updated) return {
|
|
838
|
+
success: false,
|
|
839
|
+
error: {
|
|
840
|
+
code: 404,
|
|
841
|
+
message: "Document not found"
|
|
842
|
+
}
|
|
843
|
+
};
|
|
827
844
|
return {
|
|
828
845
|
success: true,
|
|
829
|
-
data:
|
|
846
|
+
data: updated
|
|
830
847
|
};
|
|
831
848
|
}
|
|
832
849
|
/**
|
|
@@ -857,10 +874,32 @@ async function updateByQuery(Model, query, data, options = {}) {
|
|
|
857
874
|
...options.updatePipeline !== void 0 ? { updatePipeline: options.updatePipeline } : {},
|
|
858
875
|
...options.arrayFilters ? { arrayFilters: options.arrayFilters } : {}
|
|
859
876
|
}).select(options.select || "").populate(parsePopulate(options.populate)).lean(options.lean ?? false);
|
|
860
|
-
if (!document && options.throwOnNotFound
|
|
877
|
+
if (!document && options.throwOnNotFound === true) throw createError(404, "Document not found");
|
|
861
878
|
return document;
|
|
862
879
|
}
|
|
863
880
|
/**
|
|
881
|
+
* Atomic findOneAndUpdate primitive.
|
|
882
|
+
*
|
|
883
|
+
* Returns the matched document (post-update by default) or null when no doc
|
|
884
|
+
* matches and `upsert` is false. Used by outbox relays, distributed locks,
|
|
885
|
+
* and workflow semaphores that need compare-and-set in a single round-trip.
|
|
886
|
+
*/
|
|
887
|
+
async function findOneAndUpdate(Model, filter, update, options = {}) {
|
|
888
|
+
assertUpdatePipelineAllowed(update, options.updatePipeline);
|
|
889
|
+
const returnDocument = options.returnDocument ?? "after";
|
|
890
|
+
return await Model.findOneAndUpdate(filter, update, {
|
|
891
|
+
returnDocument,
|
|
892
|
+
upsert: options.upsert ?? false,
|
|
893
|
+
runValidators: options.runValidators ?? true,
|
|
894
|
+
session: options.session,
|
|
895
|
+
...options.sort ? { sort: options.sort } : {},
|
|
896
|
+
...options.arrayFilters ? { arrayFilters: options.arrayFilters } : {},
|
|
897
|
+
...options.collation ? { collation: options.collation } : {},
|
|
898
|
+
...options.maxTimeMS ? { maxTimeMS: options.maxTimeMS } : {},
|
|
899
|
+
...options.updatePipeline !== void 0 ? { updatePipeline: options.updatePipeline } : {}
|
|
900
|
+
}).select(options.select || "").populate(parsePopulate(options.populate)).lean(options.lean ?? true);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
864
903
|
* Increment field
|
|
865
904
|
*/
|
|
866
905
|
async function increment(Model, id, field, value = 1, options = {}) {
|
|
@@ -879,4 +918,4 @@ async function pullFromArray(Model, id, field, value, options = {}) {
|
|
|
879
918
|
return update(Model, id, { $pull: { [field]: value } }, options);
|
|
880
919
|
}
|
|
881
920
|
//#endregion
|
|
882
|
-
export {
|
|
921
|
+
export { upsert as _, count as a, LookupBuilder as b, getByQuery as c, deleteById as d, deleteByQuery as f, create_exports as g, createMany as h, update_exports as i, getOrCreate as l, create as m, update as n, exists as o, delete_exports as p, updateByQuery as r, getById as s, findOneAndUpdate as t, read_exports as u, aggregate_exports as v, distinct as y };
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
1
|
+
import { Y as PopulateSpec, at as SelectSpec, dt as SortSpec } from "../types-BUS0Zj8y.mjs";
|
|
2
|
+
import { a as createFieldPreset, c as getMongooseProjection, i as configureLogger, l as createError, n as buildCrudSchemasFromMongooseSchema, o as filterResponseData, r as createMemoryCache, s as getFieldsForUser, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-t-MoVleF.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/cache-keys.d.ts
|
|
5
5
|
/**
|
|
@@ -146,4 +146,4 @@ declare function getSchemaIdType(schema?: SchemaLike | null): IdType;
|
|
|
146
146
|
*/
|
|
147
147
|
declare function isValidIdForType(id: unknown, idType: IdType): boolean;
|
|
148
148
|
//#endregion
|
|
149
|
-
export { type IdType, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser,
|
|
149
|
+
export { type IdType, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getMongooseProjection, getSchemaIdType, isObjectIdInstance, isValidIdForType, listPattern, listQueryKey, modelPattern, versionKey };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as configureLogger } from "../logger-DJ7egMnd.mjs";
|
|
2
|
-
import { t as createError } from "../error-
|
|
2
|
+
import { t as createError } from "../error-CzYwrfUP.mjs";
|
|
3
3
|
import { n as isObjectIdInstance, r as isValidIdForType, t as getSchemaIdType } from "../id-resolution-e4BT9zAV.mjs";
|
|
4
4
|
import { a as byIdKey, c as listQueryKey, i as getMongooseProjection, l as modelPattern, n as filterResponseData, o as byQueryKey, r as getFieldsForUser, s as listPattern, t as createFieldPreset, u as versionKey } from "../field-selection-dI0m4RBs.mjs";
|
|
5
|
-
import {
|
|
6
|
-
export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser,
|
|
5
|
+
import { n as buildCrudSchemasFromMongooseSchema, r as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-D1sdCOmj.mjs";
|
|
6
|
+
export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getMongooseProjection, getSchemaIdType, isObjectIdInstance, isValidIdForType, listPattern, listQueryKey, modelPattern, versionKey };
|