@classytic/mongokit 3.2.5 → 3.3.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/README.md +2 -2
- package/dist/actions/index.d.mts +2 -2
- package/dist/actions/index.mjs +1 -2
- package/dist/{aggregate-BAi4Do-X.mjs → aggregate-BClp040M.mjs} +80 -12
- package/dist/{aggregate-D9x87vej.d.mts → aggregate-BkOG9qwr.d.mts} +3 -1
- package/dist/ai/index.d.mts +1 -1
- package/dist/{cache-keys-C8Z9B5sw.mjs → cache-keys-CzFwVnLy.mjs} +28 -9
- package/dist/{custom-id.plugin-Dc4Y3Eie.d.mts → custom-id.plugin-BJ3FSnzt.d.mts} +51 -3
- package/dist/{custom-id.plugin-m0VW6yYm.mjs → custom-id.plugin-FInXDsUX.mjs} +1744 -76
- package/dist/index.d.mts +63 -15
- package/dist/index.mjs +10 -1146
- package/dist/{limits-DsNeCx4D.mjs → limits-s1-d8rWb.mjs} +2 -2
- package/dist/{mongooseToJsonSchema-1qQMScHL.d.mts → mongooseToJsonSchema-B6O2ED3n.d.mts} +1 -1
- package/dist/pagination/PaginationEngine.d.mts +1 -1
- package/dist/pagination/PaginationEngine.mjs +18 -5
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.mjs +1 -1
- package/dist/{types-Bnwv9NV6.d.mts → types-pVY0w1Pp.d.mts} +29 -3
- package/dist/utils/index.d.mts +22 -5
- package/dist/utils/index.mjs +2 -2
- package/package.json +3 -3
- package/dist/create-BuO6xt0v.mjs +0 -55
- /package/dist/{mongooseToJsonSchema-COdDEkIJ.mjs → mongooseToJsonSchema-D_i2Am_O.mjs} +0 -0
|
@@ -89,7 +89,7 @@ function validateCursorSort(cursorSort, currentSort) {
|
|
|
89
89
|
* @throws Error if versions don't match
|
|
90
90
|
*/
|
|
91
91
|
function validateCursorVersion(cursorVersion, expectedVersion) {
|
|
92
|
-
if (cursorVersion
|
|
92
|
+
if (cursorVersion > expectedVersion) throw new Error(`Cursor version ${cursorVersion} is newer than expected version ${expectedVersion}. Please upgrade.`);
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Serializes a value for cursor storage
|
|
@@ -120,7 +120,7 @@ function rehydrateValue(serialized, type) {
|
|
|
120
120
|
switch (type) {
|
|
121
121
|
case "date": return new Date(serialized);
|
|
122
122
|
case "objectid": return new mongoose.Types.ObjectId(serialized);
|
|
123
|
-
case "boolean": return
|
|
123
|
+
case "boolean": return serialized === true || serialized === "true";
|
|
124
124
|
case "number": return Number(serialized);
|
|
125
125
|
default: return serialized;
|
|
126
126
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as SchemaBuilderOptions, T as HttpError, dt as UserContext, m as CrudSchemas, o as CacheAdapter, pt as ValidationResult, x as FieldPreset } from "./types-
|
|
1
|
+
import { $ as SchemaBuilderOptions, T as HttpError, dt as UserContext, m as CrudSchemas, o as CacheAdapter, pt as ValidationResult, x as FieldPreset } from "./types-pVY0w1Pp.mjs";
|
|
2
2
|
import mongoose, { Schema } from "mongoose";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/field-selection.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as KeysetPaginationOptions, I as OffsetPaginationOptions, L as OffsetPaginationResult, i as AnyDocument, j as KeysetPaginationResult, n as AggregatePaginationResult, t as AggregatePaginationOptions, z as PaginationConfig } from "../types-
|
|
1
|
+
import { A as KeysetPaginationOptions, I as OffsetPaginationOptions, L as OffsetPaginationResult, i as AnyDocument, j as KeysetPaginationResult, n as AggregatePaginationResult, t as AggregatePaginationOptions, z as PaginationConfig } from "../types-pVY0w1Pp.mjs";
|
|
2
2
|
import { Model } from "mongoose";
|
|
3
3
|
|
|
4
4
|
//#region src/pagination/PaginationEngine.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as createError, r as warn } from "../logger-D8ily-PP.mjs";
|
|
2
|
-
import { a as validatePage, c as validateKeysetSort, d as validateCursorSort, f as validateCursorVersion, i as validateLimit, l as decodeCursor, n as calculateTotalPages, o as buildKeysetFilter, r as shouldWarnDeepPagination, s as getPrimaryField, t as calculateSkip, u as encodeCursor } from "../limits-
|
|
2
|
+
import { a as validatePage, c as validateKeysetSort, d as validateCursorSort, f as validateCursorVersion, i as validateLimit, l as decodeCursor, n as calculateTotalPages, o as buildKeysetFilter, r as shouldWarnDeepPagination, s as getPrimaryField, t as calculateSkip, u as encodeCursor } from "../limits-s1-d8rWb.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/pagination/PaginationEngine.ts
|
|
5
5
|
/**
|
|
@@ -48,10 +48,11 @@ var PaginationEngine = class {
|
|
|
48
48
|
const sanitizedPage = validatePage(page, this.config);
|
|
49
49
|
const sanitizedLimit = validateLimit(limit, this.config);
|
|
50
50
|
const skip = calculateSkip(sanitizedPage, sanitizedLimit);
|
|
51
|
+
const fetchLimit = countStrategy === "none" ? sanitizedLimit + 1 : sanitizedLimit;
|
|
51
52
|
let query = this.Model.find(filters);
|
|
52
53
|
if (select) query = query.select(select);
|
|
53
54
|
if (populate && (Array.isArray(populate) ? populate.length : populate)) query = query.populate(populate);
|
|
54
|
-
query = query.sort(sort).skip(skip).limit(
|
|
55
|
+
query = query.sort(sort).skip(skip).limit(fetchLimit).lean(lean);
|
|
55
56
|
if (session) query = query.session(session);
|
|
56
57
|
if (hint) query = query.hint(hint);
|
|
57
58
|
if (maxTimeMS) query = query.maxTimeMS(maxTimeMS);
|
|
@@ -69,6 +70,11 @@ var PaginationEngine = class {
|
|
|
69
70
|
}
|
|
70
71
|
const [docs] = await Promise.all([query.exec()]);
|
|
71
72
|
const totalPages = countStrategy === "none" ? 0 : calculateTotalPages(total, sanitizedLimit);
|
|
73
|
+
let hasNext;
|
|
74
|
+
if (countStrategy === "none") {
|
|
75
|
+
hasNext = docs.length > sanitizedLimit;
|
|
76
|
+
if (hasNext) docs.pop();
|
|
77
|
+
} else hasNext = sanitizedPage < totalPages;
|
|
72
78
|
const warning = shouldWarnDeepPagination(sanitizedPage, this.config.deepPageThreshold) ? `Deep pagination (page ${sanitizedPage}). Consider getAll({ after, sort, limit }) for better performance.` : void 0;
|
|
73
79
|
return {
|
|
74
80
|
method: "offset",
|
|
@@ -77,7 +83,7 @@ var PaginationEngine = class {
|
|
|
77
83
|
limit: sanitizedLimit,
|
|
78
84
|
total,
|
|
79
85
|
pages: totalPages,
|
|
80
|
-
hasNext
|
|
86
|
+
hasNext,
|
|
81
87
|
hasPrev: sanitizedPage > 1,
|
|
82
88
|
...warning && { warning }
|
|
83
89
|
};
|
|
@@ -165,7 +171,9 @@ var PaginationEngine = class {
|
|
|
165
171
|
const { pipeline = [], page = 1, limit = this.config.defaultLimit, session, hint, maxTimeMS, countStrategy = "exact", readPreference } = options;
|
|
166
172
|
const sanitizedPage = validatePage(page, this.config);
|
|
167
173
|
const sanitizedLimit = validateLimit(limit, this.config);
|
|
168
|
-
const
|
|
174
|
+
const skip = calculateSkip(sanitizedPage, sanitizedLimit);
|
|
175
|
+
const fetchLimit = countStrategy === "none" ? sanitizedLimit + 1 : sanitizedLimit;
|
|
176
|
+
const facetStages = { docs: [{ $skip: skip }, { $limit: fetchLimit }] };
|
|
169
177
|
if (countStrategy !== "none") facetStages.total = [{ $count: "count" }];
|
|
170
178
|
const facetPipeline = [...pipeline, { $facet: facetStages }];
|
|
171
179
|
const aggregation = this.Model.aggregate(facetPipeline);
|
|
@@ -177,6 +185,11 @@ var PaginationEngine = class {
|
|
|
177
185
|
const docs = result.docs;
|
|
178
186
|
const total = result.total?.[0]?.count || 0;
|
|
179
187
|
const totalPages = countStrategy === "none" ? 0 : calculateTotalPages(total, sanitizedLimit);
|
|
188
|
+
let hasNext;
|
|
189
|
+
if (countStrategy === "none") {
|
|
190
|
+
hasNext = docs.length > sanitizedLimit;
|
|
191
|
+
if (hasNext) docs.pop();
|
|
192
|
+
} else hasNext = sanitizedPage < totalPages;
|
|
180
193
|
const warning = shouldWarnDeepPagination(sanitizedPage, this.config.deepPageThreshold) ? `Deep pagination in aggregate (page ${sanitizedPage}). Uses $skip internally.` : void 0;
|
|
181
194
|
return {
|
|
182
195
|
method: "aggregate",
|
|
@@ -185,7 +198,7 @@ var PaginationEngine = class {
|
|
|
185
198
|
limit: sanitizedLimit,
|
|
186
199
|
total,
|
|
187
200
|
pages: totalPages,
|
|
188
|
-
hasNext
|
|
201
|
+
hasNext,
|
|
189
202
|
hasPrev: sanitizedPage > 1,
|
|
190
203
|
...warning && { warning }
|
|
191
204
|
};
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { A as subdocumentPlugin, B as
|
|
1
|
+
import "../types-pVY0w1Pp.mjs";
|
|
2
|
+
import { A as subdocumentPlugin, B as immutableField, C as observabilityPlugin, D as CacheMethods, E as cascadePlugin, F as batchOperationsPlugin, G as methodRegistryPlugin, H as uniqueField, I as MongoOperationsMethods, J as auditLogPlugin, K as SoftDeleteMethods, L as mongoOperationsPlugin, M as aggregateHelpersPlugin, N as BatchOperationsMethods, O as cachePlugin, R as autoInject, S as OperationMetric, T as multiTenantPlugin, U as validationChainPlugin, V as requireField, W as MethodRegistryRepository, X as fieldFilterPlugin, Y as timestampPlugin, _ as AuditTrailMethods, a as SequentialIdOptions, b as auditTrailPlugin, c as getNextSequence, d as ElasticSearchOptions, f as elasticSearchPlugin, g as AuditQueryResult, h as AuditQueryOptions, i as PrefixedIdOptions, j as AggregateHelpersMethods, k as SubdocumentMethods, l as prefixedId, m as AuditOperation, n as DateSequentialIdOptions, o as customIdPlugin, p as AuditEntry, q as softDeletePlugin, r as IdGenerator, s as dateSequentialId, t as CustomIdOptions, u as sequentialId, v as AuditTrailOptions, w as MultiTenantOptions, x as ObservabilityOptions, y as AuditTrailQuery, z as blockIf } from "../custom-id.plugin-BJ3FSnzt.mjs";
|
|
3
3
|
export { type AggregateHelpersMethods, type AuditEntry, type AuditOperation, type AuditQueryOptions, type AuditQueryResult, type AuditTrailMethods, type AuditTrailOptions, AuditTrailQuery, type BatchOperationsMethods, type CacheMethods, type CustomIdOptions, type DateSequentialIdOptions, type ElasticSearchOptions, type IdGenerator, type MethodRegistryRepository, type MongoOperationsMethods, type MultiTenantOptions, type ObservabilityOptions, type OperationMetric, type PrefixedIdOptions, type SequentialIdOptions, type SoftDeleteMethods, type SubdocumentMethods, aggregateHelpersPlugin, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, customIdPlugin, dateSequentialId, elasticSearchPlugin, fieldFilterPlugin, getNextSequence, immutableField, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, observabilityPlugin, prefixedId, requireField, sequentialId, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as methodRegistryPlugin, D as fieldFilterPlugin, E as timestampPlugin, S as validationChainPlugin, T as auditLogPlugin, _ as autoInject, a as sequentialId, b as requireField, c as auditTrailPlugin, d as cascadePlugin, f as cachePlugin, g as mongoOperationsPlugin, h as batchOperationsPlugin, i as prefixedId, l as observabilityPlugin, m as aggregateHelpersPlugin, n as dateSequentialId, o as elasticSearchPlugin, p as subdocumentPlugin, r as getNextSequence, s as AuditTrailQuery, t as customIdPlugin, u as multiTenantPlugin, v as blockIf, w as softDeletePlugin, x as uniqueField, y as immutableField } from "../custom-id.plugin-
|
|
1
|
+
import { C as methodRegistryPlugin, D as fieldFilterPlugin, E as timestampPlugin, S as validationChainPlugin, T as auditLogPlugin, _ as autoInject, a as sequentialId, b as requireField, c as auditTrailPlugin, d as cascadePlugin, f as cachePlugin, g as mongoOperationsPlugin, h as batchOperationsPlugin, i as prefixedId, l as observabilityPlugin, m as aggregateHelpersPlugin, n as dateSequentialId, o as elasticSearchPlugin, p as subdocumentPlugin, r as getNextSequence, s as AuditTrailQuery, t as customIdPlugin, u as multiTenantPlugin, v as blockIf, w as softDeletePlugin, x as uniqueField, y as immutableField } from "../custom-id.plugin-FInXDsUX.mjs";
|
|
2
2
|
|
|
3
3
|
export { AuditTrailQuery, aggregateHelpersPlugin, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, customIdPlugin, dateSequentialId, elasticSearchPlugin, fieldFilterPlugin, getNextSequence, immutableField, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, observabilityPlugin, prefixedId, requireField, sequentialId, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin };
|
|
@@ -692,11 +692,15 @@ interface CreateOptions {
|
|
|
692
692
|
interface UpdateOptions extends OperationOptions {
|
|
693
693
|
/** Enable update pipeline syntax */
|
|
694
694
|
updatePipeline?: boolean;
|
|
695
|
+
/** Array filters for positional operator $[<identifier>] updates */
|
|
696
|
+
arrayFilters?: Record<string, unknown>[];
|
|
695
697
|
}
|
|
696
698
|
/** Delete result */
|
|
697
699
|
interface DeleteResult {
|
|
698
700
|
success: boolean;
|
|
699
701
|
message: string;
|
|
702
|
+
id?: string;
|
|
703
|
+
soft?: boolean;
|
|
700
704
|
count?: number;
|
|
701
705
|
}
|
|
702
706
|
/** Update many result */
|
|
@@ -808,14 +812,21 @@ interface Plugin {
|
|
|
808
812
|
type PluginFunction = (repo: RepositoryInstance) => void;
|
|
809
813
|
/** Plugin type (object or function) */
|
|
810
814
|
type PluginType = Plugin | PluginFunction;
|
|
815
|
+
/** Hook with priority for deterministic phase ordering */
|
|
816
|
+
interface PrioritizedHook {
|
|
817
|
+
listener: (data: any) => void | Promise<void>;
|
|
818
|
+
priority: number;
|
|
819
|
+
}
|
|
811
820
|
/** Repository instance for plugin type reference */
|
|
812
821
|
interface RepositoryInstance {
|
|
813
822
|
Model: Model<any>;
|
|
814
823
|
model: string;
|
|
815
|
-
_hooks: Map<string,
|
|
824
|
+
_hooks: Map<string, PrioritizedHook[]>;
|
|
816
825
|
_pagination: unknown;
|
|
817
826
|
use(plugin: PluginType): this;
|
|
818
|
-
on(event: string, listener: (data: any) => void | Promise<void
|
|
827
|
+
on(event: string, listener: (data: any) => void | Promise<void>, options?: {
|
|
828
|
+
priority?: number;
|
|
829
|
+
}): this;
|
|
819
830
|
off(event: string, listener: (data: any) => void | Promise<void>): this;
|
|
820
831
|
removeAllListeners(event?: string): this;
|
|
821
832
|
emit(event: string, data: unknown): void;
|
|
@@ -825,7 +836,7 @@ interface RepositoryInstance {
|
|
|
825
836
|
[key: string]: unknown;
|
|
826
837
|
}
|
|
827
838
|
/** Repository operation names */
|
|
828
|
-
type RepositoryOperation = "create" | "createMany" | "update" | "updateMany" | "delete" | "deleteMany" | "getById" | "getByQuery" | "getAll" | "aggregatePaginate" | "lookupPopulate";
|
|
839
|
+
type RepositoryOperation = "create" | "createMany" | "update" | "updateMany" | "delete" | "deleteMany" | "getById" | "getByQuery" | "getAll" | "getOrCreate" | "count" | "exists" | "distinct" | "aggregate" | "aggregatePaginate" | "lookupPopulate" | "bulkWrite";
|
|
829
840
|
/** Event lifecycle phases */
|
|
830
841
|
type EventPhase = "before" | "after" | "error";
|
|
831
842
|
/** Repository event names (generated from template literals) */
|
|
@@ -1087,6 +1098,7 @@ interface CacheStats {
|
|
|
1087
1098
|
misses: number;
|
|
1088
1099
|
sets: number;
|
|
1089
1100
|
invalidations: number;
|
|
1101
|
+
errors: number;
|
|
1090
1102
|
}
|
|
1091
1103
|
/** Cascade relation definition */
|
|
1092
1104
|
interface CascadeRelation {
|
|
@@ -1158,6 +1170,7 @@ type AllPluginMethods<TDoc> = {
|
|
|
1158
1170
|
multiplyField(id: string | ObjectId, field: string, multiplier: number, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1159
1171
|
setMin(id: string | ObjectId, field: string, value: unknown, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1160
1172
|
setMax(id: string | ObjectId, field: string, value: unknown, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1173
|
+
atomicUpdate(id: string | ObjectId, operators: Record<string, Record<string, unknown>>, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1161
1174
|
updateMany(query: Record<string, unknown>, data: Record<string, unknown>, options?: {
|
|
1162
1175
|
session?: ClientSession;
|
|
1163
1176
|
updatePipeline?: boolean;
|
|
@@ -1172,6 +1185,19 @@ type AllPluginMethods<TDoc> = {
|
|
|
1172
1185
|
acknowledged: boolean;
|
|
1173
1186
|
deletedCount: number;
|
|
1174
1187
|
}>;
|
|
1188
|
+
bulkWrite(operations: Record<string, unknown>[], options?: {
|
|
1189
|
+
session?: ClientSession;
|
|
1190
|
+
ordered?: boolean;
|
|
1191
|
+
}): Promise<{
|
|
1192
|
+
ok: number;
|
|
1193
|
+
insertedCount: number;
|
|
1194
|
+
upsertedCount: number;
|
|
1195
|
+
matchedCount: number;
|
|
1196
|
+
modifiedCount: number;
|
|
1197
|
+
deletedCount: number;
|
|
1198
|
+
insertedIds: Record<number, unknown>;
|
|
1199
|
+
upsertedIds: Record<number, unknown>;
|
|
1200
|
+
}>;
|
|
1175
1201
|
groupBy(field: string, options?: {
|
|
1176
1202
|
limit?: number;
|
|
1177
1203
|
session?: unknown;
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import { G as PopulateSpec, at as SortSpec, et as SelectSpec } from "../types-
|
|
2
|
-
import { a as isFieldUpdateAllowed, c as configureLogger, d as filterResponseData, f as getFieldsForUser, i as getSystemManagedFields, l as createError, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, p as getMongooseProjection, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel, u as createFieldPreset } from "../mongooseToJsonSchema-
|
|
1
|
+
import { G as PopulateSpec, at as SortSpec, et as SelectSpec } from "../types-pVY0w1Pp.mjs";
|
|
2
|
+
import { a as isFieldUpdateAllowed, c as configureLogger, d as filterResponseData, f as getFieldsForUser, i as getSystemManagedFields, l as createError, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, p as getMongooseProjection, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel, u as createFieldPreset } from "../mongooseToJsonSchema-B6O2ED3n.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/cache-keys.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Generate cache key for getById operations
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Includes select/populate/lean in the key so different query shapes
|
|
9
|
+
* (e.g., plain vs populated, lean vs hydrated) never collide.
|
|
10
|
+
*
|
|
11
|
+
* Format: {prefix}:id:{model}:{documentId} (no options)
|
|
12
|
+
* Format: {prefix}:id:{model}:{documentId}:{optionsHash} (with options)
|
|
9
13
|
*
|
|
10
14
|
* @example
|
|
11
15
|
* byIdKey('mk', 'User', '507f1f77bcf86cd799439011')
|
|
12
16
|
* // => 'mk:id:User:507f1f77bcf86cd799439011'
|
|
17
|
+
* byIdKey('mk', 'User', '507f1f77bcf86cd799439011', { select: 'name email' })
|
|
18
|
+
* // => 'mk:id:User:507f1f77bcf86cd799439011:a1b2c3d4'
|
|
13
19
|
*/
|
|
14
|
-
declare function byIdKey(prefix: string, model: string, id: string
|
|
20
|
+
declare function byIdKey(prefix: string, model: string, id: string, options?: {
|
|
21
|
+
select?: SelectSpec;
|
|
22
|
+
populate?: PopulateSpec;
|
|
23
|
+
lean?: boolean;
|
|
24
|
+
}): string;
|
|
15
25
|
/**
|
|
16
26
|
* Generate cache key for single-document queries
|
|
17
27
|
*
|
|
@@ -21,7 +31,7 @@ declare function byIdKey(prefix: string, model: string, id: string): string;
|
|
|
21
31
|
* byQueryKey('mk', 'User', { email: 'john@example.com' })
|
|
22
32
|
* // => 'mk:one:User:a1b2c3d4'
|
|
23
33
|
*/
|
|
24
|
-
declare function byQueryKey(prefix: string, model: string, query: Record<string, unknown>, options?: {
|
|
34
|
+
declare function byQueryKey(prefix: string, model: string, version: number, query: Record<string, unknown>, options?: {
|
|
25
35
|
select?: SelectSpec;
|
|
26
36
|
populate?: PopulateSpec;
|
|
27
37
|
}): string;
|
|
@@ -46,6 +56,13 @@ declare function listQueryKey(prefix: string, model: string, version: number, pa
|
|
|
46
56
|
after?: string;
|
|
47
57
|
select?: SelectSpec;
|
|
48
58
|
populate?: PopulateSpec;
|
|
59
|
+
search?: string;
|
|
60
|
+
mode?: string;
|
|
61
|
+
lean?: boolean;
|
|
62
|
+
readPreference?: string;
|
|
63
|
+
hint?: string | Record<string, unknown>;
|
|
64
|
+
maxTimeMS?: number;
|
|
65
|
+
countStrategy?: string;
|
|
49
66
|
}): string;
|
|
50
67
|
/**
|
|
51
68
|
* Generate cache key for collection version tag
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as createError, t as configureLogger } from "../logger-D8ily-PP.mjs";
|
|
2
|
-
import { a as modelPattern, c as filterResponseData, i as listQueryKey, l as getFieldsForUser, n as byQueryKey, o as versionKey, r as listPattern, s as createFieldPreset, t as byIdKey, u as getMongooseProjection } from "../cache-keys-
|
|
3
|
-
import { a as isFieldUpdateAllowed, i as getSystemManagedFields, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-
|
|
2
|
+
import { a as modelPattern, c as filterResponseData, i as listQueryKey, l as getFieldsForUser, n as byQueryKey, o as versionKey, r as listPattern, s as createFieldPreset, t as byIdKey, u as getMongooseProjection } from "../cache-keys-CzFwVnLy.mjs";
|
|
3
|
+
import { a as isFieldUpdateAllowed, i as getSystemManagedFields, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-D_i2Am_O.mjs";
|
|
4
4
|
|
|
5
5
|
export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getImmutableFields, getMongooseProjection, getSystemManagedFields, isFieldUpdateAllowed, listPattern, listQueryKey, modelPattern, validateUpdateBody, versionKey };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/mongokit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Production-grade MongoDB repositories with zero dependencies - smart pagination, events, and plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -104,10 +104,10 @@
|
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@types/node": "^22.0.0",
|
|
106
106
|
"@vitest/coverage-v8": "^3.2.4",
|
|
107
|
-
"mongodb-memory-server": "^10.
|
|
107
|
+
"mongodb-memory-server": "^10.4.3",
|
|
108
108
|
"mongoose": "^9.1.3",
|
|
109
109
|
"tsdown": "^0.20.3",
|
|
110
110
|
"typescript": "^5.7.0",
|
|
111
|
-
"vitest": "^3.
|
|
111
|
+
"vitest": "^3.2.4"
|
|
112
112
|
}
|
|
113
113
|
}
|
package/dist/create-BuO6xt0v.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-DQk6qfdC.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/actions/create.ts
|
|
4
|
-
var create_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
-
create: () => create,
|
|
6
|
-
createDefault: () => createDefault,
|
|
7
|
-
createMany: () => createMany,
|
|
8
|
-
upsert: () => upsert
|
|
9
|
-
});
|
|
10
|
-
/**
|
|
11
|
-
* Create single document
|
|
12
|
-
*/
|
|
13
|
-
async function create(Model, data, options = {}) {
|
|
14
|
-
const document = new Model(data);
|
|
15
|
-
await document.save({ session: options.session });
|
|
16
|
-
return document;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Create multiple documents
|
|
20
|
-
*/
|
|
21
|
-
async function createMany(Model, dataArray, options = {}) {
|
|
22
|
-
return Model.insertMany(dataArray, {
|
|
23
|
-
session: options.session,
|
|
24
|
-
ordered: options.ordered !== false
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Create with defaults (useful for initialization)
|
|
29
|
-
*/
|
|
30
|
-
async function createDefault(Model, overrides = {}, options = {}) {
|
|
31
|
-
const defaults = {};
|
|
32
|
-
Model.schema.eachPath((path, schemaType) => {
|
|
33
|
-
const schemaOptions = schemaType.options;
|
|
34
|
-
if (schemaOptions.default !== void 0 && path !== "_id") defaults[path] = typeof schemaOptions.default === "function" ? schemaOptions.default() : schemaOptions.default;
|
|
35
|
-
});
|
|
36
|
-
return create(Model, {
|
|
37
|
-
...defaults,
|
|
38
|
-
...overrides
|
|
39
|
-
}, options);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Upsert (create or update)
|
|
43
|
-
*/
|
|
44
|
-
async function upsert(Model, query, data, options = {}) {
|
|
45
|
-
return Model.findOneAndUpdate(query, { $setOnInsert: data }, {
|
|
46
|
-
upsert: true,
|
|
47
|
-
returnDocument: "after",
|
|
48
|
-
runValidators: true,
|
|
49
|
-
session: options.session,
|
|
50
|
-
...options.updatePipeline !== void 0 ? { updatePipeline: options.updatePipeline } : {}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
export { upsert as i, createMany as n, create_exports as r, create as t };
|
|
File without changes
|