@classytic/mongokit 3.1.5 → 3.2.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 +89 -4
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.js +5 -3
- package/dist/ai/index.d.ts +175 -0
- package/dist/ai/index.js +206 -0
- package/dist/chunks/{chunk-M2XHQGZB.js → chunk-44KXLGPO.js} +28 -1
- package/dist/chunks/{chunk-CSLJ2PL2.js → chunk-DEVXDBRL.js} +143 -9
- package/dist/chunks/{chunk-CF6FLC2G.js → chunk-I7CWNAJB.js} +1 -1
- package/dist/chunks/chunk-JWUAVZ3L.js +8 -0
- package/dist/chunks/{chunk-IT7DCOKR.js → chunk-UE2IEXZJ.js} +15 -8
- package/dist/chunks/chunk-URLJFIR7.js +22 -0
- package/dist/chunks/{chunk-SAKSLT47.js → chunk-VWKIKZYF.js} +274 -7
- package/dist/chunks/chunk-WSFCRVEQ.js +7 -0
- package/dist/{index-BXSSv1pW.d.ts → index-BDn5fSTE.d.ts} +13 -1
- package/dist/index.d.ts +151 -42
- package/dist/index.js +299 -299
- package/dist/{mongooseToJsonSchema-Cc5AwuDu.d.ts → mongooseToJsonSchema-CaRF_bCN.d.ts} +33 -2
- package/dist/pagination/PaginationEngine.d.ts +1 -1
- package/dist/pagination/PaginationEngine.js +3 -2
- package/dist/plugins/index.d.ts +125 -2
- package/dist/plugins/index.js +5 -3
- package/dist/{types-B5Uv6Ak7.d.ts → types-Jni1KgkP.d.ts} +18 -11
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +4 -2
- package/package.json +10 -2
- package/dist/chunks/chunk-VJXDGP3C.js +0 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { c as AggregatePaginationOptions, ad as AllPluginMethods,
|
|
1
|
+
import { h as PaginationResult, A as AnyDocument, i as PluginType, P as PaginationConfig, R as RepositoryOptions, j as ObjectId, S as SelectSpec, e as PopulateSpec, f as SortSpec$2, a as OffsetPaginationResult, b as KeysetPaginationResult, U as UpdateOptions, d as AggregatePaginationResult, W as WithTransactionOptions, k as RepositoryContext, H as HttpError } from './types-Jni1KgkP.js';
|
|
2
|
+
export { c as AggregatePaginationOptions, ad as AllPluginMethods, l as AnyModel, a7 as CacheAdapter, a9 as CacheOperationOptions, a8 as CacheOptions, aa as CacheStats, ac as CascadeOptions, ab as CascadeRelation, C as CreateInput, v as CreateOptions, Z as CrudSchemas, _ as DecodedCursor, D as DeepPartial, w as DeleteResult, L as EventHandlers, M as EventPayload, G as EventPhase, Q as FieldPreset, T as FieldRules, a5 as GroupResult, n as HookMode, I as InferDocument, o as InferRawDoc, Y as JsonSchema, r as KeysOfType, K as KeysetPaginationOptions, a1 as Logger, a6 as MinMaxResult, N as NonNullableFields, O as OffsetPaginationOptions, u as OperationOptions, p as PartialBy, g as Plugin, B as PluginFunction, J as RepositoryEvent, E as RepositoryInstance, F as RepositoryOperation, q as RequiredBy, X as SchemaBuilderOptions, a3 as SoftDeleteFilterMode, a2 as SoftDeleteOptions, a4 as SoftDeleteRepository, m as SortDirection, s as Strict, t as UpdateInput, x as UpdateManyResult, y as UpdateWithValidationResult, z as UserContext, a0 as ValidationChainOptions, V as ValidationResult, $ as ValidatorDefinition, ae as WithPlugins } from './types-Jni1KgkP.js';
|
|
3
3
|
import * as mongoose from 'mongoose';
|
|
4
|
-
import { PipelineStage,
|
|
4
|
+
import { PipelineStage, Model, Expression, ClientSession, PopulateOptions } from 'mongoose';
|
|
5
5
|
import { PaginationEngine } from './pagination/PaginationEngine.js';
|
|
6
|
-
import { L as LookupOptions, a as LookupBuilder } from './index-
|
|
7
|
-
export { i as actions } from './index-
|
|
8
|
-
export { AggregateHelpersMethods, BatchOperationsMethods, CacheMethods, MongoOperationsMethods, SoftDeleteMethods, SubdocumentMethods, aggregateHelpersPlugin, auditLogPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, fieldFilterPlugin, immutableField, methodRegistryPlugin, mongoOperationsPlugin, requireField, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin } from './plugins/index.js';
|
|
9
|
-
export { d as buildCrudSchemasFromModel, b as buildCrudSchemasFromMongooseSchema, j as createError, c as createFieldPreset,
|
|
6
|
+
import { L as LookupOptions, a as LookupBuilder } from './index-BDn5fSTE.js';
|
|
7
|
+
export { i as actions } from './index-BDn5fSTE.js';
|
|
8
|
+
export { AggregateHelpersMethods, BatchOperationsMethods, CacheMethods, MongoOperationsMethods, MultiTenantOptions, ObservabilityOptions, OperationMetric, SoftDeleteMethods, SubdocumentMethods, aggregateHelpersPlugin, auditLogPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, fieldFilterPlugin, immutableField, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, observabilityPlugin, requireField, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin } from './plugins/index.js';
|
|
9
|
+
export { d as buildCrudSchemasFromModel, b as buildCrudSchemasFromMongooseSchema, k as configureLogger, j as createError, c as createFieldPreset, l as createMemoryCache, f as filterResponseData, g as getFieldsForUser, e as getImmutableFields, a as getMongooseProjection, h as getSystemManagedFields, i as isFieldUpdateAllowed, v as validateUpdateBody } from './mongooseToJsonSchema-CaRF_bCN.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Framework-Agnostic Controller Interfaces
|
|
@@ -330,35 +330,28 @@ interface IResponseFormatter {
|
|
|
330
330
|
paginated<T>(result: PaginationResult<T>): IControllerResponse<PaginationResult<T>>;
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
/**
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
* .project({ password: 0 })
|
|
356
|
-
* .build();
|
|
357
|
-
*
|
|
358
|
-
* const results = await Model.aggregate(pipeline);
|
|
359
|
-
* ```
|
|
360
|
-
*/
|
|
361
|
-
|
|
333
|
+
/** Options for $vectorSearch stage (Atlas only) */
|
|
334
|
+
interface VectorSearchOptions {
|
|
335
|
+
/** Atlas Search index name */
|
|
336
|
+
index: string;
|
|
337
|
+
/** Field path containing the vector embedding */
|
|
338
|
+
path: string;
|
|
339
|
+
/** Query vector to search against */
|
|
340
|
+
queryVector: number[];
|
|
341
|
+
/** Number of candidates to consider (higher = more accurate, slower) */
|
|
342
|
+
numCandidates?: number;
|
|
343
|
+
/** Max results to return */
|
|
344
|
+
limit: number;
|
|
345
|
+
/** Pre-filter documents before vector search */
|
|
346
|
+
filter?: Record<string, unknown>;
|
|
347
|
+
/** Use exact search instead of ANN (slower but precise) */
|
|
348
|
+
exact?: boolean;
|
|
349
|
+
}
|
|
350
|
+
/** Result from build() including execution options */
|
|
351
|
+
interface AggregationPlan {
|
|
352
|
+
pipeline: PipelineStage[];
|
|
353
|
+
allowDiskUse: boolean;
|
|
354
|
+
}
|
|
362
355
|
type SortOrder = 1 | -1 | 'asc' | 'desc';
|
|
363
356
|
type SortSpec$1 = Record<string, SortOrder>;
|
|
364
357
|
type ProjectionSpec = Record<string, 0 | 1 | Expression>;
|
|
@@ -372,6 +365,7 @@ type GroupSpec = {
|
|
|
372
365
|
*/
|
|
373
366
|
declare class AggregationBuilder {
|
|
374
367
|
private pipeline;
|
|
368
|
+
private _diskUse;
|
|
375
369
|
/**
|
|
376
370
|
* Get the current pipeline
|
|
377
371
|
*/
|
|
@@ -380,6 +374,22 @@ declare class AggregationBuilder {
|
|
|
380
374
|
* Build and return the final pipeline
|
|
381
375
|
*/
|
|
382
376
|
build(): PipelineStage[];
|
|
377
|
+
/**
|
|
378
|
+
* Build pipeline with execution options (allowDiskUse, etc.)
|
|
379
|
+
*/
|
|
380
|
+
plan(): AggregationPlan;
|
|
381
|
+
/**
|
|
382
|
+
* Build and execute the pipeline against a model
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* const results = await new AggregationBuilder()
|
|
387
|
+
* .match({ status: 'active' })
|
|
388
|
+
* .allowDiskUse()
|
|
389
|
+
* .exec(MyModel);
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
exec<T = unknown>(model: Model<any>, session?: mongoose.ClientSession): Promise<T[]>;
|
|
383
393
|
/**
|
|
384
394
|
* Reset the pipeline
|
|
385
395
|
*/
|
|
@@ -595,6 +605,19 @@ declare class AggregationBuilder {
|
|
|
595
605
|
value?: unknown;
|
|
596
606
|
}>;
|
|
597
607
|
}): this;
|
|
608
|
+
/**
|
|
609
|
+
* Enable allowDiskUse for large aggregations that exceed 100MB memory limit
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```typescript
|
|
613
|
+
* const results = await new AggregationBuilder()
|
|
614
|
+
* .match({ status: 'active' })
|
|
615
|
+
* .group({ _id: '$category', total: { $sum: '$amount' } })
|
|
616
|
+
* .allowDiskUse()
|
|
617
|
+
* .exec(Model);
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
allowDiskUse(enable?: boolean): this;
|
|
598
621
|
/**
|
|
599
622
|
* Paginate - Add skip and limit for offset-based pagination
|
|
600
623
|
*/
|
|
@@ -690,6 +713,33 @@ declare class AggregationBuilder {
|
|
|
690
713
|
* $searchMeta - Get Atlas Search metadata (Atlas only)
|
|
691
714
|
*/
|
|
692
715
|
searchMeta(options: Record<string, unknown>): this;
|
|
716
|
+
/**
|
|
717
|
+
* $vectorSearch - Semantic similarity search using vector embeddings (Atlas only)
|
|
718
|
+
*
|
|
719
|
+
* Requires an Atlas Vector Search index on the target field.
|
|
720
|
+
* Must be the first stage in the pipeline.
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
* ```typescript
|
|
724
|
+
* const results = await new AggregationBuilder()
|
|
725
|
+
* .vectorSearch({
|
|
726
|
+
* index: 'vector_index',
|
|
727
|
+
* path: 'embedding',
|
|
728
|
+
* queryVector: await getEmbedding('running shoes'),
|
|
729
|
+
* limit: 10,
|
|
730
|
+
* numCandidates: 100,
|
|
731
|
+
* filter: { category: 'footwear' }
|
|
732
|
+
* })
|
|
733
|
+
* .project({ embedding: 0, score: { $meta: 'vectorSearchScore' } })
|
|
734
|
+
* .exec(ProductModel);
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
737
|
+
vectorSearch(options: VectorSearchOptions): this;
|
|
738
|
+
/**
|
|
739
|
+
* Add vectorSearchScore as a field after $vectorSearch
|
|
740
|
+
* Convenience for `.addFields({ score: { $meta: 'vectorSearchScore' } })`
|
|
741
|
+
*/
|
|
742
|
+
withVectorScore(fieldName?: string): this;
|
|
693
743
|
/**
|
|
694
744
|
* Create a builder from an existing pipeline
|
|
695
745
|
*/
|
|
@@ -748,6 +798,14 @@ declare class Repository<TDoc = AnyDocument> {
|
|
|
748
798
|
* Register event listener
|
|
749
799
|
*/
|
|
750
800
|
on(event: string, listener: HookListener): this;
|
|
801
|
+
/**
|
|
802
|
+
* Remove a specific event listener
|
|
803
|
+
*/
|
|
804
|
+
off(event: string, listener: HookListener): this;
|
|
805
|
+
/**
|
|
806
|
+
* Remove all listeners for an event, or all listeners entirely
|
|
807
|
+
*/
|
|
808
|
+
removeAllListeners(event?: string): this;
|
|
751
809
|
/**
|
|
752
810
|
* Emit event (sync - for backwards compatibility)
|
|
753
811
|
*/
|
|
@@ -777,6 +835,7 @@ declare class Repository<TDoc = AnyDocument> {
|
|
|
777
835
|
getById(id: string | ObjectId, options?: {
|
|
778
836
|
select?: SelectSpec;
|
|
779
837
|
populate?: PopulateSpec;
|
|
838
|
+
populateOptions?: PopulateOptions[];
|
|
780
839
|
lean?: boolean;
|
|
781
840
|
session?: ClientSession;
|
|
782
841
|
throwOnNotFound?: boolean;
|
|
@@ -789,6 +848,7 @@ declare class Repository<TDoc = AnyDocument> {
|
|
|
789
848
|
getByQuery(query: Record<string, unknown>, options?: {
|
|
790
849
|
select?: SelectSpec;
|
|
791
850
|
populate?: PopulateSpec;
|
|
851
|
+
populateOptions?: PopulateOptions[];
|
|
792
852
|
lean?: boolean;
|
|
793
853
|
session?: ClientSession;
|
|
794
854
|
throwOnNotFound?: boolean;
|
|
@@ -830,6 +890,8 @@ declare class Repository<TDoc = AnyDocument> {
|
|
|
830
890
|
};
|
|
831
891
|
limit?: number;
|
|
832
892
|
search?: string;
|
|
893
|
+
/** Advanced populate options (from QueryParser or Arc's BaseController) */
|
|
894
|
+
populateOptions?: PopulateOptions[];
|
|
833
895
|
}, options?: {
|
|
834
896
|
select?: SelectSpec;
|
|
835
897
|
populate?: PopulateSpec;
|
|
@@ -970,9 +1032,36 @@ declare class Repository<TDoc = AnyDocument> {
|
|
|
970
1032
|
*/
|
|
971
1033
|
buildLookup(from?: string): LookupBuilder;
|
|
972
1034
|
/**
|
|
973
|
-
* Execute callback within a transaction
|
|
1035
|
+
* Execute callback within a transaction with automatic retry on transient failures.
|
|
1036
|
+
*
|
|
1037
|
+
* Uses the MongoDB driver's `session.withTransaction()` which automatically retries
|
|
1038
|
+
* on `TransientTransactionError` and `UnknownTransactionCommitResult`.
|
|
1039
|
+
*
|
|
1040
|
+
* The callback always receives a `ClientSession`. When `allowFallback` is true
|
|
1041
|
+
* and the MongoDB deployment doesn't support transactions (e.g., standalone),
|
|
1042
|
+
* the callback runs without a transaction on the same session.
|
|
1043
|
+
*
|
|
1044
|
+
* @param callback - Receives a `ClientSession` to pass to repository operations
|
|
1045
|
+
* @param options.allowFallback - Run without transaction on standalone MongoDB (default: false)
|
|
1046
|
+
* @param options.onFallback - Called when falling back to non-transactional execution
|
|
1047
|
+
* @param options.transactionOptions - MongoDB driver transaction options (readConcern, writeConcern, etc.)
|
|
1048
|
+
*
|
|
1049
|
+
* @example
|
|
1050
|
+
* ```typescript
|
|
1051
|
+
* const result = await repo.withTransaction(async (session) => {
|
|
1052
|
+
* const order = await repo.create({ total: 100 }, { session });
|
|
1053
|
+
* await paymentRepo.create({ orderId: order._id }, { session });
|
|
1054
|
+
* return order;
|
|
1055
|
+
* });
|
|
1056
|
+
*
|
|
1057
|
+
* // With fallback for standalone/dev environments
|
|
1058
|
+
* await repo.withTransaction(callback, {
|
|
1059
|
+
* allowFallback: true,
|
|
1060
|
+
* onFallback: (err) => logger.warn('Running without transaction', err),
|
|
1061
|
+
* });
|
|
1062
|
+
* ```
|
|
974
1063
|
*/
|
|
975
|
-
withTransaction<T>(callback: (session: ClientSession
|
|
1064
|
+
withTransaction<T>(callback: (session: ClientSession) => Promise<T>, options?: WithTransactionOptions): Promise<T>;
|
|
976
1065
|
private _isTransactionUnsupported;
|
|
977
1066
|
/**
|
|
978
1067
|
* Execute custom query with event emission
|
|
@@ -1053,9 +1142,11 @@ declare class Repository<TDoc = AnyDocument> {
|
|
|
1053
1142
|
*
|
|
1054
1143
|
* ### Lookup Security
|
|
1055
1144
|
*
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
1145
|
+
* Lookup pipelines are sanitized by default:
|
|
1146
|
+
* - Dangerous stages blocked ($out, $merge, $unionWith, $collStats, $currentOp, $listSessions)
|
|
1147
|
+
* - Dangerous operators blocked inside $match/$addFields/$set ($where, $function, $accumulator, $expr)
|
|
1148
|
+
* - Optional collection whitelist via `allowedLookupCollections`
|
|
1149
|
+
* For maximum security, use per-collection field allowlists in your controller layer.
|
|
1059
1150
|
*
|
|
1060
1151
|
* ### Filter Security
|
|
1061
1152
|
*
|
|
@@ -1154,6 +1245,13 @@ interface QueryParserOptions {
|
|
|
1154
1245
|
* @example ['name', 'description', 'sku', 'tags']
|
|
1155
1246
|
*/
|
|
1156
1247
|
searchFields?: string[];
|
|
1248
|
+
/**
|
|
1249
|
+
* Whitelist of collection names allowed in lookups.
|
|
1250
|
+
* When set, only these collections can be used in $lookup stages.
|
|
1251
|
+
* When undefined, all collection names are allowed.
|
|
1252
|
+
* @example ['departments', 'categories', 'users']
|
|
1253
|
+
*/
|
|
1254
|
+
allowedLookupCollections?: string[];
|
|
1157
1255
|
}
|
|
1158
1256
|
/**
|
|
1159
1257
|
* Modern Query Parser
|
|
@@ -1276,6 +1374,17 @@ declare class QueryParser {
|
|
|
1276
1374
|
* Recursively filters out operators like $where, $function, $accumulator
|
|
1277
1375
|
*/
|
|
1278
1376
|
private _sanitizeMatchConfig;
|
|
1377
|
+
/**
|
|
1378
|
+
* Sanitize pipeline stages for use in $lookup.
|
|
1379
|
+
* Blocks dangerous stages ($out, $merge, etc.) and recursively sanitizes
|
|
1380
|
+
* operator expressions within $match, $addFields, and $set stages.
|
|
1381
|
+
*/
|
|
1382
|
+
private _sanitizePipeline;
|
|
1383
|
+
/**
|
|
1384
|
+
* Recursively sanitize expression objects, blocking dangerous operators
|
|
1385
|
+
* like $where, $function, $accumulator inside $addFields/$set stages.
|
|
1386
|
+
*/
|
|
1387
|
+
private _sanitizeExpressions;
|
|
1279
1388
|
private _sanitizeSearch;
|
|
1280
1389
|
/**
|
|
1281
1390
|
* Build regex-based multi-field search filters
|
|
@@ -1310,4 +1419,4 @@ declare class QueryParser {
|
|
|
1310
1419
|
*/
|
|
1311
1420
|
declare function createRepository<TDoc>(Model: mongoose.Model<TDoc, any, any, any>, plugins?: PluginType[], paginationConfig?: PaginationConfig, options?: RepositoryOptions): Repository<TDoc>;
|
|
1312
1421
|
|
|
1313
|
-
export { AggregatePaginationResult, AggregationBuilder, AnyDocument, type FilterQuery, HttpError, type IController, type IControllerResponse, type IRequestContext, type IResponseFormatter, KeysetPaginationResult, LookupBuilder, LookupOptions, ObjectId, OffsetPaginationResult, PaginationConfig, PaginationEngine, PaginationResult, type ParsedQuery, PluginType, PopulateSpec, QueryParser, type QueryParserOptions, Repository, RepositoryContext, RepositoryOptions, type SearchMode, SelectSpec, SortSpec$2 as SortSpec, UpdateOptions, WithTransactionOptions, createRepository, Repository as default };
|
|
1422
|
+
export { AggregatePaginationResult, AggregationBuilder, AnyDocument, type FilterQuery, HttpError, type IController, type IControllerResponse, type IRequestContext, type IResponseFormatter, KeysetPaginationResult, LookupBuilder, LookupOptions, ObjectId, OffsetPaginationResult, PaginationConfig, PaginationEngine, PaginationResult, type ParsedQuery, PluginType, type PopulateOption, PopulateSpec, QueryParser, type QueryParserOptions, Repository, RepositoryContext, RepositoryOptions, type SearchMode, SelectSpec, SortSpec$2 as SortSpec, UpdateOptions, WithTransactionOptions, createRepository, Repository as default };
|