@classytic/mongokit 3.10.1 → 3.10.3
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/actions/index.d.mts +1 -1
- package/dist/ai/index.d.mts +3 -3
- package/dist/{index-miN5rFQm.d.mts → index-CNNavGpM.d.mts} +23 -23
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/{mongooseToJsonSchema-DlTx-Or2.d.mts → mongooseToJsonSchema-Bi8hNbj8.d.mts} +1 -1
- package/dist/pagination/PaginationEngine.d.mts +1 -1
- package/dist/plugins/index.d.mts +1 -1
- package/dist/plugins/index.mjs +1 -1
- package/dist/{types-Bbr54g--.d.mts → types-CYFJa36g.d.mts} +35 -15
- package/dist/utils/index.d.mts +2 -2
- package/dist/{validation-chain.plugin-DAvlX93q.d.mts → validation-chain.plugin-BYJo0Y6g.d.mts} +28 -7
- package/dist/{validation-chain.plugin-Ccu6irtx.mjs → validation-chain.plugin-D-yH2f8a.mjs} +62 -8
- package/package.json +4 -3
package/dist/actions/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as create_d_exports, i as delete_d_exports, n as update_d_exports, o as aggregate_d_exports, r as read_d_exports } from "../index-
|
|
1
|
+
import { a as create_d_exports, i as delete_d_exports, n as update_d_exports, o as aggregate_d_exports, r as read_d_exports } from "../index-CNNavGpM.mjs";
|
|
2
2
|
export { aggregate_d_exports as aggregate, create_d_exports as create, delete_d_exports as deleteActions, read_d_exports as read, update_d_exports as update };
|
package/dist/ai/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { K as Plugin } from "../types-
|
|
2
|
-
import {
|
|
1
|
+
import { K as Plugin } from "../types-CYFJa36g.mjs";
|
|
2
|
+
import { PipelineStage } from "mongoose";
|
|
3
3
|
|
|
4
4
|
//#region src/ai/types.d.ts
|
|
5
5
|
/** Supported similarity metrics for vector search */
|
|
@@ -73,7 +73,7 @@ interface VectorSearchParams {
|
|
|
73
73
|
/** Which vector field config to use (default: first configured) */
|
|
74
74
|
field?: string;
|
|
75
75
|
/** MongoDB session for transactions */
|
|
76
|
-
session?:
|
|
76
|
+
session?: unknown;
|
|
77
77
|
/** Fields to include/exclude in results */
|
|
78
78
|
project?: Record<string, 0 | 1>;
|
|
79
79
|
/** Include similarity score in results */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Dt as LookupOptions, E as GroupResult, H as OperationOptions, L as MinMaxResult, Q as ReadPreferenceType, T as FindOneAndUpdateOptions, Y as PopulateSpec, a as AnyDocument, at as SelectSpec, dt as SortSpec, g as CreateOptions, gt as UpdateWithValidationResult, ht as UpdateOptions, mt as UpdateManyResult, y as DeleteResult, z as ObjectId } from "./types-
|
|
2
|
-
import {
|
|
1
|
+
import { Dt as LookupOptions, E as GroupResult, H as OperationOptions, L as MinMaxResult, Q as ReadPreferenceType, T as FindOneAndUpdateOptions, Y as PopulateSpec, a as AnyDocument, at as SelectSpec, dt as SortSpec, g as CreateOptions, gt as UpdateWithValidationResult, ht as UpdateOptions, mt as UpdateManyResult, y as DeleteResult, z as ObjectId } from "./types-CYFJa36g.mjs";
|
|
2
|
+
import { Model, PipelineStage } from "mongoose";
|
|
3
3
|
|
|
4
4
|
//#region src/actions/aggregate.d.ts
|
|
5
5
|
declare namespace aggregate_d_exports {
|
|
@@ -9,7 +9,7 @@ declare namespace aggregate_d_exports {
|
|
|
9
9
|
* Execute aggregation pipeline
|
|
10
10
|
*/
|
|
11
11
|
declare function aggregate<TResult = unknown>(Model: Model<any>, pipeline: PipelineStage[], options?: {
|
|
12
|
-
session?:
|
|
12
|
+
session?: unknown;
|
|
13
13
|
}): Promise<TResult[]>;
|
|
14
14
|
/**
|
|
15
15
|
* Aggregate with pagination using native MongoDB $facet
|
|
@@ -19,7 +19,7 @@ declare function aggregate<TResult = unknown>(Model: Model<any>, pipeline: Pipel
|
|
|
19
19
|
declare function aggregatePaginate<TDoc = AnyDocument>(Model: Model<TDoc>, pipeline: PipelineStage[], options?: {
|
|
20
20
|
page?: number;
|
|
21
21
|
limit?: number;
|
|
22
|
-
session?:
|
|
22
|
+
session?: unknown;
|
|
23
23
|
}): Promise<{
|
|
24
24
|
docs: TDoc[];
|
|
25
25
|
total: number;
|
|
@@ -34,13 +34,13 @@ declare function aggregatePaginate<TDoc = AnyDocument>(Model: Model<TDoc>, pipel
|
|
|
34
34
|
*/
|
|
35
35
|
declare function groupBy(Model: Model<any>, field: string, options?: {
|
|
36
36
|
limit?: number;
|
|
37
|
-
session?:
|
|
37
|
+
session?: unknown;
|
|
38
38
|
}): Promise<GroupResult[]>;
|
|
39
39
|
/**
|
|
40
40
|
* Count by field values
|
|
41
41
|
*/
|
|
42
42
|
declare function countBy(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
|
|
43
|
-
session?:
|
|
43
|
+
session?: unknown;
|
|
44
44
|
}): Promise<GroupResult[]>;
|
|
45
45
|
/**
|
|
46
46
|
* Lookup (join) with another collection
|
|
@@ -57,38 +57,38 @@ declare function lookup<TDoc = AnyDocument>(Model: Model<TDoc>, lookupOptions: L
|
|
|
57
57
|
*/
|
|
58
58
|
declare function unwind<TDoc = AnyDocument>(Model: Model<TDoc>, field: string, options?: {
|
|
59
59
|
preserveEmpty?: boolean;
|
|
60
|
-
session?:
|
|
60
|
+
session?: unknown;
|
|
61
61
|
}): Promise<TDoc[]>;
|
|
62
62
|
/**
|
|
63
63
|
* Facet search (multiple aggregations in one query)
|
|
64
64
|
*/
|
|
65
65
|
declare function facet<TResult = Record<string, unknown[]>>(Model: Model<any>, facets: Record<string, PipelineStage[]>, options?: {
|
|
66
|
-
session?:
|
|
66
|
+
session?: unknown;
|
|
67
67
|
}): Promise<TResult[]>;
|
|
68
68
|
/**
|
|
69
69
|
* Get distinct values
|
|
70
70
|
*/
|
|
71
71
|
declare function distinct<T = unknown>(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
|
|
72
|
-
session?:
|
|
72
|
+
session?: unknown;
|
|
73
73
|
readPreference?: string;
|
|
74
74
|
}): Promise<T[]>;
|
|
75
75
|
/**
|
|
76
76
|
* Calculate sum
|
|
77
77
|
*/
|
|
78
78
|
declare function sum(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
|
|
79
|
-
session?:
|
|
79
|
+
session?: unknown;
|
|
80
80
|
}): Promise<number>;
|
|
81
81
|
/**
|
|
82
82
|
* Calculate average
|
|
83
83
|
*/
|
|
84
84
|
declare function average(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
|
|
85
|
-
session?:
|
|
85
|
+
session?: unknown;
|
|
86
86
|
}): Promise<number>;
|
|
87
87
|
/**
|
|
88
88
|
* Min/Max
|
|
89
89
|
*/
|
|
90
90
|
declare function minMax(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
|
|
91
|
-
session?:
|
|
91
|
+
session?: unknown;
|
|
92
92
|
}): Promise<MinMaxResult>;
|
|
93
93
|
declare namespace create_d_exports {
|
|
94
94
|
export { create, createDefault, createMany, upsert };
|
|
@@ -109,7 +109,7 @@ declare function createDefault<TDoc = AnyDocument>(Model: Model<TDoc>, overrides
|
|
|
109
109
|
* Upsert (create or update)
|
|
110
110
|
*/
|
|
111
111
|
declare function upsert<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, data: Record<string, unknown>, options?: {
|
|
112
|
-
session?:
|
|
112
|
+
session?: unknown;
|
|
113
113
|
updatePipeline?: boolean;
|
|
114
114
|
}): Promise<TDoc | null>;
|
|
115
115
|
declare namespace delete_d_exports {
|
|
@@ -119,34 +119,34 @@ declare namespace delete_d_exports {
|
|
|
119
119
|
* Delete by ID
|
|
120
120
|
*/
|
|
121
121
|
declare function deleteById<TDoc = AnyDocument>(Model: Model<TDoc>, id: string | ObjectId, options?: {
|
|
122
|
-
session?:
|
|
122
|
+
session?: unknown;
|
|
123
123
|
query?: Record<string, unknown>;
|
|
124
124
|
}): Promise<DeleteResult>;
|
|
125
125
|
/**
|
|
126
126
|
* Delete many documents
|
|
127
127
|
*/
|
|
128
128
|
declare function deleteMany<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, options?: {
|
|
129
|
-
session?:
|
|
129
|
+
session?: unknown;
|
|
130
130
|
}): Promise<DeleteResult>;
|
|
131
131
|
/**
|
|
132
132
|
* Delete by query
|
|
133
133
|
*/
|
|
134
134
|
declare function deleteByQuery(Model: Model<any>, query: Record<string, unknown>, options?: {
|
|
135
|
-
session?:
|
|
135
|
+
session?: unknown;
|
|
136
136
|
throwOnNotFound?: boolean;
|
|
137
137
|
}): Promise<DeleteResult>;
|
|
138
138
|
/**
|
|
139
139
|
* Soft delete (set deleted flag)
|
|
140
140
|
*/
|
|
141
141
|
declare function softDelete<TDoc = AnyDocument>(Model: Model<TDoc>, id: string | ObjectId, options?: {
|
|
142
|
-
session?:
|
|
142
|
+
session?: unknown;
|
|
143
143
|
userId?: string;
|
|
144
144
|
}): Promise<DeleteResult>;
|
|
145
145
|
/**
|
|
146
146
|
* Restore soft deleted document
|
|
147
147
|
*/
|
|
148
148
|
declare function restore<TDoc = AnyDocument>(Model: Model<TDoc>, id: string | ObjectId, options?: {
|
|
149
|
-
session?:
|
|
149
|
+
session?: unknown;
|
|
150
150
|
}): Promise<DeleteResult>;
|
|
151
151
|
declare namespace read_d_exports {
|
|
152
152
|
export { count, exists, getAll, getById, getByQuery, getOrCreate, tryGetByQuery };
|
|
@@ -186,28 +186,28 @@ declare function getAll<TDoc = AnyDocument>(Model: Model<TDoc>, query?: Record<s
|
|
|
186
186
|
limit?: number;
|
|
187
187
|
skip?: number;
|
|
188
188
|
lean?: boolean;
|
|
189
|
-
session?:
|
|
189
|
+
session?: unknown;
|
|
190
190
|
readPreference?: ReadPreferenceType;
|
|
191
191
|
}): Promise<TDoc[]>;
|
|
192
192
|
/**
|
|
193
193
|
* Get or create document (upsert)
|
|
194
194
|
*/
|
|
195
195
|
declare function getOrCreate<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, createData: Record<string, unknown>, options?: {
|
|
196
|
-
session?:
|
|
196
|
+
session?: unknown;
|
|
197
197
|
updatePipeline?: boolean;
|
|
198
198
|
}): Promise<TDoc | null>;
|
|
199
199
|
/**
|
|
200
200
|
* Count documents matching query
|
|
201
201
|
*/
|
|
202
202
|
declare function count<TDoc = AnyDocument>(Model: Model<TDoc>, query?: Record<string, unknown>, options?: {
|
|
203
|
-
session?:
|
|
203
|
+
session?: unknown;
|
|
204
204
|
readPreference?: ReadPreferenceType;
|
|
205
205
|
}): Promise<number>;
|
|
206
206
|
/**
|
|
207
207
|
* Check if document exists
|
|
208
208
|
*/
|
|
209
209
|
declare function exists<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, options?: {
|
|
210
|
-
session?:
|
|
210
|
+
session?: unknown;
|
|
211
211
|
readPreference?: ReadPreferenceType;
|
|
212
212
|
}): Promise<{
|
|
213
213
|
_id: unknown;
|
|
@@ -247,7 +247,7 @@ declare function updateWithValidation<TDoc = AnyDocument>(Model: Model<TDoc>, id
|
|
|
247
247
|
* Update many documents
|
|
248
248
|
*/
|
|
249
249
|
declare function updateMany(Model: Model<unknown>, query: Record<string, unknown>, data: Record<string, unknown>, options?: {
|
|
250
|
-
session?:
|
|
250
|
+
session?: unknown;
|
|
251
251
|
updatePipeline?: boolean;
|
|
252
252
|
arrayFilters?: Record<string, unknown>[];
|
|
253
253
|
}): Promise<UpdateManyResult>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $ as RepositoryContext, A as InferRawDoc, B as OffsetPaginationOptions, C as EventPhase, Ct as IControllerResponse, D as HookMode, Dt as LookupOptions, E as GroupResult, Et as LookupBuilder, F as LookupPopulateOptions, G as PartialBy, H as OperationOptions, I as LookupPopulateResult, J as PluginType, K as Plugin, L as MinMaxResult, M as KeysetPaginationOptions, N as KeysetPaginationResult, O as HttpError, P as Logger, Q as ReadPreferenceType, R as NonNullableFields, S as EventPayload, St as IController, T as FindOneAndUpdateOptions, Tt as IResponseFormatter, U as PaginationConfig, V as OffsetPaginationResult, W as PaginationResult, X as PrioritizedHook, Y as PopulateSpec, Z as ReadOptions, _ as DecodedCursor, _t as UserContext, a as AnyDocument, at as SelectSpec, b as DocField, bt as WithPlugins, c as CacheOperationOptions, ct as SoftDeleteOptions, d as CacheableOptions, dt as SortSpec, et as RepositoryEvent, f as CascadeOptions, ft as Strict, g as CreateOptions, gt as UpdateWithValidationResult, h as CreateInput, ht as UpdateOptions, i as AllPluginMethods, it as RequiredBy, j as KeysOfType, k as InferDocument, l as CacheOptions, lt as SoftDeleteRepository, m as CollationOptions, mt as UpdateManyResult, n as AggregatePaginationOptions, nt as RepositoryOperation, o as AnyModel, ot as SessionOptions, p as CascadeRelation, pt as UpdateInput, q as PluginFunction, r as AggregatePaginationResult, rt as RepositoryOptions, s as CacheAdapter, st as SoftDeleteFilterMode, t as AggregateOptions, tt as RepositoryInstance, u as CacheStats, ut as SortDirection, v as DeepPartial, vt as ValidationChainOptions, w as FieldPreset, wt as IRequestContext, x as EventHandlers, xt as WithTransactionOptions, y as DeleteResult, yt as ValidatorDefinition, z as ObjectId } from "./types-
|
|
2
|
-
import { t as index_d_exports } from "./index-
|
|
1
|
+
import { $ as RepositoryContext, A as InferRawDoc, B as OffsetPaginationOptions, C as EventPhase, Ct as IControllerResponse, D as HookMode, Dt as LookupOptions, E as GroupResult, Et as LookupBuilder, F as LookupPopulateOptions, G as PartialBy, H as OperationOptions, I as LookupPopulateResult, J as PluginType, K as Plugin, L as MinMaxResult, M as KeysetPaginationOptions, N as KeysetPaginationResult, O as HttpError, P as Logger, Q as ReadPreferenceType, R as NonNullableFields, S as EventPayload, St as IController, T as FindOneAndUpdateOptions, Tt as IResponseFormatter, U as PaginationConfig, V as OffsetPaginationResult, W as PaginationResult, X as PrioritizedHook, Y as PopulateSpec, Z as ReadOptions, _ as DecodedCursor, _t as UserContext, a as AnyDocument, at as SelectSpec, b as DocField, bt as WithPlugins, c as CacheOperationOptions, ct as SoftDeleteOptions, d as CacheableOptions, dt as SortSpec, et as RepositoryEvent, f as CascadeOptions, ft as Strict, g as CreateOptions, gt as UpdateWithValidationResult, h as CreateInput, ht as UpdateOptions, i as AllPluginMethods, it as RequiredBy, j as KeysOfType, k as InferDocument, l as CacheOptions, lt as SoftDeleteRepository, m as CollationOptions, mt as UpdateManyResult, n as AggregatePaginationOptions, nt as RepositoryOperation, o as AnyModel, ot as SessionOptions, p as CascadeRelation, pt as UpdateInput, q as PluginFunction, r as AggregatePaginationResult, rt as RepositoryOptions, s as CacheAdapter, st as SoftDeleteFilterMode, t as AggregateOptions, tt as RepositoryInstance, u as CacheStats, ut as SortDirection, v as DeepPartial, vt as ValidationChainOptions, w as FieldPreset, wt as IRequestContext, x as EventHandlers, xt as WithTransactionOptions, y as DeleteResult, yt as ValidatorDefinition, z as ObjectId } from "./types-CYFJa36g.mjs";
|
|
2
|
+
import { t as index_d_exports } from "./index-CNNavGpM.mjs";
|
|
3
3
|
import { PaginationEngine } from "./pagination/PaginationEngine.mjs";
|
|
4
|
-
import { $ as aggregateHelpersPlugin, A as PrefixedIdOptions, B as BatchOperationsMethods, C as methodRegistryPlugin, D as CustomIdOptions, E as elasticSearchPlugin, F as prefixedId, G as AuditQueryOptions, H as batchOperationsPlugin, I as sequentialId, J as AuditTrailOptions, K as AuditQueryResult, L as cascadePlugin, M as customIdPlugin, N as dateSequentialId, O as DateSequentialIdOptions, P as getNextSequence, Q as AggregateHelpersMethods, R as CacheMethods, T as ElasticSearchOptions, U as AuditEntry, V as BulkWriteResult, W as AuditOperation, X as auditTrailPlugin, Y as AuditTrailQuery, Z as auditLogPlugin, _ as observabilityPlugin, a as uniqueField, b as MongoOperationsMethods, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as SequentialIdOptions, k as IdGenerator, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, q as AuditTrailMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MultiTenantOptions, w as fieldFilterPlugin, x as mongoOperationsPlugin, y as multiTenantPlugin, z as cachePlugin } from "./validation-chain.plugin-
|
|
4
|
+
import { $ as aggregateHelpersPlugin, A as PrefixedIdOptions, B as BatchOperationsMethods, C as methodRegistryPlugin, D as CustomIdOptions, E as elasticSearchPlugin, F as prefixedId, G as AuditQueryOptions, H as batchOperationsPlugin, I as sequentialId, J as AuditTrailOptions, K as AuditQueryResult, L as cascadePlugin, M as customIdPlugin, N as dateSequentialId, O as DateSequentialIdOptions, P as getNextSequence, Q as AggregateHelpersMethods, R as CacheMethods, T as ElasticSearchOptions, U as AuditEntry, V as BulkWriteResult, W as AuditOperation, X as auditTrailPlugin, Y as AuditTrailQuery, Z as auditLogPlugin, _ as observabilityPlugin, a as uniqueField, b as MongoOperationsMethods, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as SequentialIdOptions, k as IdGenerator, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, q as AuditTrailMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MultiTenantOptions, w as fieldFilterPlugin, x as mongoOperationsPlugin, y as multiTenantPlugin, z as cachePlugin } from "./validation-chain.plugin-BYJo0Y6g.mjs";
|
|
5
5
|
import { n as SchemaPathsLike, t as FieldType$1 } from "./coercion-oM8G4b6m.mjs";
|
|
6
6
|
import { n as SchemaIndexes } from "./indexes-C26GNZRU.mjs";
|
|
7
|
-
import { a as createFieldPreset, c as getMongooseProjection, d as parseDuplicateKeyError, i as configureLogger, l as createError, n as buildCrudSchemasFromMongooseSchema, o as filterResponseData, r as createMemoryCache, s as getFieldsForUser, t as buildCrudSchemasFromModel, u as isDuplicateKeyError } from "./mongooseToJsonSchema-
|
|
7
|
+
import { a as createFieldPreset, c as getMongooseProjection, d as parseDuplicateKeyError, i as configureLogger, l as createError, n as buildCrudSchemasFromMongooseSchema, o as filterResponseData, r as createMemoryCache, s as getFieldsForUser, t as buildCrudSchemasFromModel, u as isDuplicateKeyError } from "./mongooseToJsonSchema-Bi8hNbj8.mjs";
|
|
8
8
|
import * as _$mongoose from "mongoose";
|
|
9
9
|
import { ClientSession, Expression, Model, PipelineStage, PopulateOptions } from "mongoose";
|
|
10
10
|
import { AggPaginationRequest, AggRequest, AggResult, RepositoryBase } from "@classytic/repo-core/repository";
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { r as warn, t as configureLogger } from "./logger-DJ7egMnd.mjs";
|
|
|
2
2
|
import { b as LookupBuilder } from "./update-CWXfFC6O.mjs";
|
|
3
3
|
import { n as isDuplicateKeyError, r as parseDuplicateKeyError, t as createError } from "./error-CzYwrfUP.mjs";
|
|
4
4
|
import { t as actions_exports } from "./actions/index.mjs";
|
|
5
|
-
import { A as AuditTrailQuery, C as cachePlugin, D as withTransaction, E as isTransactionUnsupported, F as MUTATING_OPERATIONS, I as OP_REGISTRY, L as READ_OPERATIONS, M as auditLogPlugin, N as aggregateHelpersPlugin, O as AggregationBuilder, P as ALL_OPERATIONS, R as operationsByPolicyKey, S as cascadePlugin, T as Repository, _ as customIdPlugin, a as uniqueField, b as prefixedId, c as createTenantContext, d as observabilityPlugin, f as multiTenantPlugin, g as elasticSearchPlugin, h as fieldFilterPlugin, i as requireField, j as auditTrailPlugin, k as batchOperationsPlugin, l as subdocumentPlugin, m as methodRegistryPlugin, n as blockIf, o as validationChainPlugin, p as mongoOperationsPlugin, r as immutableField, s as timestampPlugin, t as autoInject, u as softDeletePlugin, v as dateSequentialId, w as HOOK_PRIORITY, x as sequentialId, y as getNextSequence } from "./validation-chain.plugin-
|
|
5
|
+
import { A as AuditTrailQuery, C as cachePlugin, D as withTransaction, E as isTransactionUnsupported, F as MUTATING_OPERATIONS, I as OP_REGISTRY, L as READ_OPERATIONS, M as auditLogPlugin, N as aggregateHelpersPlugin, O as AggregationBuilder, P as ALL_OPERATIONS, R as operationsByPolicyKey, S as cascadePlugin, T as Repository, _ as customIdPlugin, a as uniqueField, b as prefixedId, c as createTenantContext, d as observabilityPlugin, f as multiTenantPlugin, g as elasticSearchPlugin, h as fieldFilterPlugin, i as requireField, j as auditTrailPlugin, k as batchOperationsPlugin, l as subdocumentPlugin, m as methodRegistryPlugin, n as blockIf, o as validationChainPlugin, p as mongoOperationsPlugin, r as immutableField, s as timestampPlugin, t as autoInject, u as softDeletePlugin, v as dateSequentialId, w as HOOK_PRIORITY, x as sequentialId, y as getNextSequence } from "./validation-chain.plugin-D-yH2f8a.mjs";
|
|
6
6
|
import { t as PaginationEngine } from "./PaginationEngine-B93fLCcO.mjs";
|
|
7
7
|
import { isGeoOperator, parseGeoFilter } from "./query/primitives/geo.mjs";
|
|
8
8
|
import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "./field-selection-dI0m4RBs.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as HttpError, _t as UserContext, s as CacheAdapter, w as FieldPreset } from "./types-
|
|
1
|
+
import { O as HttpError, _t as UserContext, s as CacheAdapter, w as FieldPreset } from "./types-CYFJa36g.mjs";
|
|
2
2
|
import mongoose, { Schema } from "mongoose";
|
|
3
3
|
import { CrudSchemas, SchemaBuilderOptions } from "@classytic/repo-core/schema";
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as OffsetPaginationOptions, M as KeysetPaginationOptions, N as KeysetPaginationResult, U as PaginationConfig, V as OffsetPaginationResult, a as AnyDocument, n as AggregatePaginationOptions, r as AggregatePaginationResult } from "../types-
|
|
1
|
+
import { B as OffsetPaginationOptions, M as KeysetPaginationOptions, N as KeysetPaginationResult, U as PaginationConfig, V as OffsetPaginationResult, a as AnyDocument, n as AggregatePaginationOptions, r as AggregatePaginationResult } from "../types-CYFJa36g.mjs";
|
|
2
2
|
import { Model } from "mongoose";
|
|
3
3
|
|
|
4
4
|
//#region src/pagination/PaginationEngine.d.ts
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as aggregateHelpersPlugin, A as PrefixedIdOptions, B as BatchOperationsMethods, C as methodRegistryPlugin, D as CustomIdOptions, E as elasticSearchPlugin, F as prefixedId, G as AuditQueryOptions, H as batchOperationsPlugin, I as sequentialId, J as AuditTrailOptions, K as AuditQueryResult, L as cascadePlugin, M as customIdPlugin, N as dateSequentialId, O as DateSequentialIdOptions, P as getNextSequence, Q as AggregateHelpersMethods, R as CacheMethods, S as MethodRegistryRepository, T as ElasticSearchOptions, U as AuditEntry, W as AuditOperation, X as auditTrailPlugin, Y as AuditTrailQuery, Z as auditLogPlugin, _ as observabilityPlugin, a as uniqueField, b as MongoOperationsMethods, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as SequentialIdOptions, k as IdGenerator, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, q as AuditTrailMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MultiTenantOptions, w as fieldFilterPlugin, x as mongoOperationsPlugin, y as multiTenantPlugin, z as cachePlugin } from "../validation-chain.plugin-
|
|
1
|
+
import { $ as aggregateHelpersPlugin, A as PrefixedIdOptions, B as BatchOperationsMethods, C as methodRegistryPlugin, D as CustomIdOptions, E as elasticSearchPlugin, F as prefixedId, G as AuditQueryOptions, H as batchOperationsPlugin, I as sequentialId, J as AuditTrailOptions, K as AuditQueryResult, L as cascadePlugin, M as customIdPlugin, N as dateSequentialId, O as DateSequentialIdOptions, P as getNextSequence, Q as AggregateHelpersMethods, R as CacheMethods, S as MethodRegistryRepository, T as ElasticSearchOptions, U as AuditEntry, W as AuditOperation, X as auditTrailPlugin, Y as AuditTrailQuery, Z as auditLogPlugin, _ as observabilityPlugin, a as uniqueField, b as MongoOperationsMethods, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as SequentialIdOptions, k as IdGenerator, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, q as AuditTrailMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MultiTenantOptions, w as fieldFilterPlugin, x as mongoOperationsPlugin, y as multiTenantPlugin, z as cachePlugin } from "../validation-chain.plugin-BYJo0Y6g.mjs";
|
|
2
2
|
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, type TenantContext, type TenantStore, aggregateHelpersPlugin, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, createTenantContext, 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,2 +1,2 @@
|
|
|
1
|
-
import { A as AuditTrailQuery, C as cachePlugin, M as auditLogPlugin, N as aggregateHelpersPlugin, S as cascadePlugin, _ as customIdPlugin, a as uniqueField, b as prefixedId, c as createTenantContext, d as observabilityPlugin, f as multiTenantPlugin, g as elasticSearchPlugin, h as fieldFilterPlugin, i as requireField, j as auditTrailPlugin, k as batchOperationsPlugin, l as subdocumentPlugin, m as methodRegistryPlugin, n as blockIf, o as validationChainPlugin, p as mongoOperationsPlugin, r as immutableField, s as timestampPlugin, t as autoInject, u as softDeletePlugin, v as dateSequentialId, x as sequentialId, y as getNextSequence } from "../validation-chain.plugin-
|
|
1
|
+
import { A as AuditTrailQuery, C as cachePlugin, M as auditLogPlugin, N as aggregateHelpersPlugin, S as cascadePlugin, _ as customIdPlugin, a as uniqueField, b as prefixedId, c as createTenantContext, d as observabilityPlugin, f as multiTenantPlugin, g as elasticSearchPlugin, h as fieldFilterPlugin, i as requireField, j as auditTrailPlugin, k as batchOperationsPlugin, l as subdocumentPlugin, m as methodRegistryPlugin, n as blockIf, o as validationChainPlugin, p as mongoOperationsPlugin, r as immutableField, s as timestampPlugin, t as autoInject, u as softDeletePlugin, v as dateSequentialId, x as sequentialId, y as getNextSequence } from "../validation-chain.plugin-D-yH2f8a.mjs";
|
|
2
2
|
export { AuditTrailQuery, aggregateHelpersPlugin, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, createTenantContext, customIdPlugin, dateSequentialId, elasticSearchPlugin, fieldFilterPlugin, getNextSequence, immutableField, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, observabilityPlugin, prefixedId, requireField, sequentialId, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _$mongoose from "mongoose";
|
|
2
|
-
import {
|
|
2
|
+
import { Document, Model, PipelineStage, PopulateOptions, Types } from "mongoose";
|
|
3
3
|
import * as _$_classytic_repo_core_filter0 from "@classytic/repo-core/filter";
|
|
4
4
|
import * as _$_classytic_repo_core_repository0 from "@classytic/repo-core/repository";
|
|
5
5
|
import { DeleteResult, LookupPopulateResult, UpdateManyResult } from "@classytic/repo-core/repository";
|
|
@@ -27,7 +27,7 @@ interface LookupOptions {
|
|
|
27
27
|
query?: Record<string, unknown>;
|
|
28
28
|
/** Query options (legacy, for aggregate.ts compatibility) */
|
|
29
29
|
options?: {
|
|
30
|
-
session?:
|
|
30
|
+
session?: unknown;
|
|
31
31
|
};
|
|
32
32
|
/** Sanitize pipeline stages (default: true). Set false only for trusted server-side pipelines */
|
|
33
33
|
sanitize?: boolean;
|
|
@@ -496,8 +496,15 @@ type SortDirection = 1 | -1;
|
|
|
496
496
|
type SortSpec = Record<string, SortDirection>;
|
|
497
497
|
/** Populate specification */
|
|
498
498
|
type PopulateSpec = string | string[] | PopulateOptions | PopulateOptions[];
|
|
499
|
-
/**
|
|
500
|
-
|
|
499
|
+
/**
|
|
500
|
+
* Select specification. `readonly string[]` widens the legacy `string[]`
|
|
501
|
+
* form to also accept the immutable variant repo-core's contract uses
|
|
502
|
+
* (`LookupPopulateOptions.select: readonly string[] | Record<string, 0
|
|
503
|
+
* | 1>`), so `Repository<TDoc>` assigns to `StandardRepo<TDoc>` without
|
|
504
|
+
* TS2322 on the `select` field. Any existing mutable-array caller stays
|
|
505
|
+
* compatible — `string[]` is assignable to `readonly string[]`.
|
|
506
|
+
*/
|
|
507
|
+
type SelectSpec = string | readonly string[] | Record<string, 0 | 1>;
|
|
501
508
|
/** Filter query type for MongoDB queries (compatible with Mongoose 8 & 9) */
|
|
502
509
|
type FilterQuery<_T = unknown> = Record<string, unknown>;
|
|
503
510
|
/**
|
|
@@ -652,7 +659,7 @@ interface BasePaginationOptions {
|
|
|
652
659
|
/** Return plain JavaScript objects */
|
|
653
660
|
lean?: boolean;
|
|
654
661
|
/** MongoDB session for transactions */
|
|
655
|
-
session?:
|
|
662
|
+
session?: unknown;
|
|
656
663
|
/** Query hint (index name or document) */
|
|
657
664
|
hint?: string | Record<string, 1 | -1>;
|
|
658
665
|
/** Maximum execution time in milliseconds */
|
|
@@ -693,7 +700,7 @@ interface AggregatePaginationOptions {
|
|
|
693
700
|
/** Number of documents per page */
|
|
694
701
|
limit?: number;
|
|
695
702
|
/** MongoDB session for transactions */
|
|
696
|
-
session?:
|
|
703
|
+
session?: unknown;
|
|
697
704
|
/** Query hint (index name or document) for aggregation */
|
|
698
705
|
hint?: string | Record<string, 1 | -1>;
|
|
699
706
|
/** Maximum execution time in milliseconds */
|
|
@@ -767,7 +774,7 @@ type PaginationResult<T = unknown> = OffsetPaginationResult<T> | KeysetPaginatio
|
|
|
767
774
|
/** Session-only options — shared base for lightweight operations */
|
|
768
775
|
interface SessionOptions {
|
|
769
776
|
/** MongoDB session for transactions */
|
|
770
|
-
session?:
|
|
777
|
+
session?: unknown;
|
|
771
778
|
/** Organization/tenant ID for multi-tenant plugin scoping */
|
|
772
779
|
organizationId?: string | ObjectId;
|
|
773
780
|
/** Extensible — plugins can read custom fields from options */
|
|
@@ -889,7 +896,7 @@ interface AggregateOptions extends ReadOptions {
|
|
|
889
896
|
* assignment — `LookupPopulateOptions<TDoc>` is bit-compatible with
|
|
890
897
|
* `import('@classytic/repo-core/repository').LookupPopulateOptions<TDoc>`.
|
|
891
898
|
*/
|
|
892
|
-
interface LookupPopulateOptions<TBase = unknown>
|
|
899
|
+
interface LookupPopulateOptions<TBase = unknown> {
|
|
893
900
|
/**
|
|
894
901
|
* Base-table filter. Accepts Filter IR from repo-core, a typed
|
|
895
902
|
* `Partial<TBase> & Record<string, unknown>` literal (what arc
|
|
@@ -917,6 +924,19 @@ interface LookupPopulateOptions<TBase = unknown> extends ReadOptions {
|
|
|
917
924
|
collation?: CollationOptions;
|
|
918
925
|
/** Count strategy for offset pagination */
|
|
919
926
|
countStrategy?: 'exact' | 'estimated' | 'none';
|
|
927
|
+
/**
|
|
928
|
+
* Transaction session. Typed `unknown` to match repo-core's
|
|
929
|
+
* `RepositorySession` contract — mongokit narrows to `ClientSession`
|
|
930
|
+
* internally. Not inherited from `ReadOptions` because the repo-core
|
|
931
|
+
* contract type has no `[key: string]: unknown` escape hatch, and
|
|
932
|
+
* arc's `Partial<StandardRepo<TDoc>>` boundary rejects index-signature
|
|
933
|
+
* drift under strict function-type variance.
|
|
934
|
+
*/
|
|
935
|
+
session?: unknown;
|
|
936
|
+
/** Read preference for replica sets (e.g. 'secondaryPreferred') */
|
|
937
|
+
readPreference?: ReadPreferenceType;
|
|
938
|
+
/** Multi-tenant plugin scoping (applied via before:lookupPopulate hook). */
|
|
939
|
+
organizationId?: string | ObjectId;
|
|
920
940
|
}
|
|
921
941
|
/**
|
|
922
942
|
* Union emitted by the validation-chain plugin. Keeps the violation shape
|
|
@@ -968,7 +988,7 @@ interface RepositoryContext {
|
|
|
968
988
|
/** Return lean documents */
|
|
969
989
|
lean?: boolean;
|
|
970
990
|
/** MongoDB session */
|
|
971
|
-
session?:
|
|
991
|
+
session?: unknown;
|
|
972
992
|
/** Read preference for replica sets */
|
|
973
993
|
readPreference?: ReadPreferenceType;
|
|
974
994
|
/** Pagination filters */
|
|
@@ -1168,7 +1188,7 @@ interface SoftDeleteRepository<TDoc = unknown> {
|
|
|
1168
1188
|
* @returns The restored document
|
|
1169
1189
|
*/
|
|
1170
1190
|
restore(id: string | ObjectId, options?: {
|
|
1171
|
-
session?:
|
|
1191
|
+
session?: unknown;
|
|
1172
1192
|
}): Promise<TDoc>;
|
|
1173
1193
|
/**
|
|
1174
1194
|
* Get all soft-deleted documents
|
|
@@ -1185,7 +1205,7 @@ interface SoftDeleteRepository<TDoc = unknown> {
|
|
|
1185
1205
|
select?: SelectSpec;
|
|
1186
1206
|
populate?: PopulateSpec;
|
|
1187
1207
|
lean?: boolean;
|
|
1188
|
-
session?:
|
|
1208
|
+
session?: unknown;
|
|
1189
1209
|
}): Promise<OffsetPaginationResult<TDoc>>;
|
|
1190
1210
|
}
|
|
1191
1211
|
/** Group result */
|
|
@@ -1381,7 +1401,7 @@ type AllPluginMethods<TDoc> = {
|
|
|
1381
1401
|
setMax(id: string | ObjectId, field: DocField<TDoc>, value: unknown, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1382
1402
|
atomicUpdate(id: string | ObjectId, operators: Record<string, Record<string, unknown>>, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1383
1403
|
updateMany(query: Record<string, unknown>, data: Record<string, unknown>, options?: {
|
|
1384
|
-
session?:
|
|
1404
|
+
session?: unknown;
|
|
1385
1405
|
updatePipeline?: boolean;
|
|
1386
1406
|
}): Promise<{
|
|
1387
1407
|
acknowledged: boolean;
|
|
@@ -1395,7 +1415,7 @@ type AllPluginMethods<TDoc> = {
|
|
|
1395
1415
|
deletedCount: number;
|
|
1396
1416
|
}>;
|
|
1397
1417
|
bulkWrite(operations: Record<string, unknown>[], options?: {
|
|
1398
|
-
session?:
|
|
1418
|
+
session?: unknown;
|
|
1399
1419
|
ordered?: boolean;
|
|
1400
1420
|
}): Promise<{
|
|
1401
1421
|
ok: number;
|
|
@@ -1428,7 +1448,7 @@ type AllPluginMethods<TDoc> = {
|
|
|
1428
1448
|
}): Promise<TDoc>;
|
|
1429
1449
|
deleteSubdocument(parentId: string | ObjectId, arrayPath: DocField<TDoc>, subId: string | ObjectId, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1430
1450
|
restore(id: string | ObjectId, options?: {
|
|
1431
|
-
session?:
|
|
1451
|
+
session?: unknown;
|
|
1432
1452
|
}): Promise<TDoc>;
|
|
1433
1453
|
getDeleted(params?: {
|
|
1434
1454
|
filters?: Record<string, unknown>;
|
|
@@ -1439,7 +1459,7 @@ type AllPluginMethods<TDoc> = {
|
|
|
1439
1459
|
select?: SelectSpec;
|
|
1440
1460
|
populate?: PopulateSpec;
|
|
1441
1461
|
lean?: boolean;
|
|
1442
|
-
session?:
|
|
1462
|
+
session?: unknown;
|
|
1443
1463
|
}): Promise<OffsetPaginationResult<TDoc>>;
|
|
1444
1464
|
invalidateCache(id: string): Promise<void>;
|
|
1445
1465
|
invalidateListCache(): Promise<void>;
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Y as PopulateSpec, at as SelectSpec, dt as SortSpec } from "../types-
|
|
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-
|
|
1
|
+
import { Y as PopulateSpec, at as SelectSpec, dt as SortSpec } from "../types-CYFJa36g.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-Bi8hNbj8.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/cache-keys.d.ts
|
|
5
5
|
/**
|
package/dist/{validation-chain.plugin-DAvlX93q.d.mts → validation-chain.plugin-BYJo0Y6g.d.mts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as RepositoryContext, K as Plugin, P as Logger, V as OffsetPaginationResult, Y as PopulateSpec, at as SelectSpec, ct as SoftDeleteOptions, dt as SortSpec, f as CascadeOptions, l as CacheOptions, tt as RepositoryInstance, u as CacheStats, vt as ValidationChainOptions, w as FieldPreset, yt as ValidatorDefinition, z as ObjectId } from "./types-
|
|
2
|
-
import mongoose
|
|
1
|
+
import { $ as RepositoryContext, K as Plugin, P as Logger, V as OffsetPaginationResult, Y as PopulateSpec, at as SelectSpec, ct as SoftDeleteOptions, dt as SortSpec, f as CascadeOptions, l as CacheOptions, tt as RepositoryInstance, u as CacheStats, vt as ValidationChainOptions, w as FieldPreset, yt as ValidatorDefinition, z as ObjectId } from "./types-CYFJa36g.mjs";
|
|
2
|
+
import mongoose from "mongoose";
|
|
3
3
|
import { BulkWriteResult } from "@classytic/repo-core/repository";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
|
|
@@ -266,7 +266,7 @@ interface BatchOperationsMethods {
|
|
|
266
266
|
* @returns Update result with matchedCount, modifiedCount, etc.
|
|
267
267
|
*/
|
|
268
268
|
updateMany(query: Record<string, unknown>, data: Record<string, unknown>, options?: {
|
|
269
|
-
session?:
|
|
269
|
+
session?: unknown;
|
|
270
270
|
updatePipeline?: boolean;
|
|
271
271
|
}): Promise<{
|
|
272
272
|
acknowledged: boolean;
|
|
@@ -287,7 +287,7 @@ interface BatchOperationsMethods {
|
|
|
287
287
|
* @returns Delete result with deletedCount
|
|
288
288
|
*/
|
|
289
289
|
deleteMany(query: Record<string, unknown>, options?: {
|
|
290
|
-
session?:
|
|
290
|
+
session?: unknown;
|
|
291
291
|
mode?: 'hard' | 'soft';
|
|
292
292
|
[key: string]: unknown;
|
|
293
293
|
}): Promise<{
|
|
@@ -311,7 +311,7 @@ interface BatchOperationsMethods {
|
|
|
311
311
|
* console.log(result.insertedCount, result.modifiedCount, result.deletedCount);
|
|
312
312
|
*/
|
|
313
313
|
bulkWrite(operations: Record<string, unknown>[], options?: {
|
|
314
|
-
session?:
|
|
314
|
+
session?: unknown;
|
|
315
315
|
ordered?: boolean;
|
|
316
316
|
}): Promise<BulkWriteResult>;
|
|
317
317
|
}
|
|
@@ -827,6 +827,27 @@ interface MultiTenantOptions {
|
|
|
827
827
|
* `$lookup` and `.populate()` against the referenced collection.
|
|
828
828
|
*/
|
|
829
829
|
fieldType?: 'string' | 'objectId';
|
|
830
|
+
/**
|
|
831
|
+
* When `true` (default), bypass the `required` throw if the operation's
|
|
832
|
+
* policy target already carries the tenant field. This lets hosts that
|
|
833
|
+
* stamp the tenant into the payload themselves (e.g., `data[tenantField]`
|
|
834
|
+
* on writes, `filters[tenantField]` on paginated reads) use the plugin
|
|
835
|
+
* without having to hand-roll a `skipWhen` that duplicates this check.
|
|
836
|
+
*
|
|
837
|
+
* Set to `false` to restore the pre-data-injection strict behavior: the
|
|
838
|
+
* tenant MUST come from `context` or `resolveContext`, otherwise the
|
|
839
|
+
* plugin throws (when `required: true`).
|
|
840
|
+
*
|
|
841
|
+
* Composition: a user-supplied `skipWhen` still runs first and can always
|
|
842
|
+
* opt out. This option controls the behavior after `skipWhen` and
|
|
843
|
+
* `resolveContext` have had their turn.
|
|
844
|
+
*
|
|
845
|
+
* Safety: when the payload supplies the tenant, the plugin skips its own
|
|
846
|
+
* injection (it does not overwrite). Cross-tenant isolation is therefore
|
|
847
|
+
* only as strong as the caller's own stamping — same guarantee as a
|
|
848
|
+
* hand-rolled `skipWhen`.
|
|
849
|
+
*/
|
|
850
|
+
allowDataInjection?: boolean;
|
|
830
851
|
}
|
|
831
852
|
declare function multiTenantPlugin(options?: MultiTenantOptions): Plugin;
|
|
832
853
|
//#endregion
|
|
@@ -928,7 +949,7 @@ interface SoftDeleteMethods<TDoc> {
|
|
|
928
949
|
* @returns Restored document
|
|
929
950
|
*/
|
|
930
951
|
restore(id: string | ObjectId, options?: {
|
|
931
|
-
session?:
|
|
952
|
+
session?: unknown;
|
|
932
953
|
}): Promise<TDoc>;
|
|
933
954
|
/**
|
|
934
955
|
* Get paginated list of soft-deleted documents
|
|
@@ -945,7 +966,7 @@ interface SoftDeleteMethods<TDoc> {
|
|
|
945
966
|
select?: SelectSpec;
|
|
946
967
|
populate?: PopulateSpec;
|
|
947
968
|
lean?: boolean;
|
|
948
|
-
session?:
|
|
969
|
+
session?: unknown;
|
|
949
970
|
}): Promise<OffsetPaginationResult<TDoc>>;
|
|
950
971
|
}
|
|
951
972
|
//#endregion
|
|
@@ -985,12 +985,13 @@ function buildAggPipeline(req) {
|
|
|
985
985
|
//#endregion
|
|
986
986
|
//#region src/actions/aggregate-ir/count.ts
|
|
987
987
|
async function countAggGroups(Model, req, options = {}) {
|
|
988
|
+
const session = options.session;
|
|
988
989
|
const groupCols = normalizeGroupBy(req.groupBy);
|
|
989
990
|
if (req.having) {
|
|
990
991
|
const { pipeline, prePaginationIndex } = buildAggPipeline(req);
|
|
991
992
|
const finalPipeline = [...pipeline.slice(0, prePaginationIndex), { $count: "n" }];
|
|
992
993
|
const aggregation = Model.aggregate(finalPipeline);
|
|
993
|
-
if (
|
|
994
|
+
if (session) aggregation.session(session);
|
|
994
995
|
const [row] = await aggregation.exec();
|
|
995
996
|
return row?.n ?? 0;
|
|
996
997
|
}
|
|
@@ -1001,7 +1002,7 @@ async function countAggGroups(Model, req, options = {}) {
|
|
|
1001
1002
|
pipeline.push({ $limit: 1 });
|
|
1002
1003
|
pipeline.push({ $count: "n" });
|
|
1003
1004
|
const aggregation = Model.aggregate(pipeline);
|
|
1004
|
-
if (
|
|
1005
|
+
if (session) aggregation.session(session);
|
|
1005
1006
|
const [row] = await aggregation.exec();
|
|
1006
1007
|
return row?.n ?? 0;
|
|
1007
1008
|
}
|
|
@@ -1014,16 +1015,17 @@ async function countAggGroups(Model, req, options = {}) {
|
|
|
1014
1015
|
pipeline.push({ $group: { _id: groupId } });
|
|
1015
1016
|
pipeline.push({ $count: "n" });
|
|
1016
1017
|
const aggregation = Model.aggregate(pipeline);
|
|
1017
|
-
if (
|
|
1018
|
+
if (session) aggregation.session(session);
|
|
1018
1019
|
const [row] = await aggregation.exec();
|
|
1019
1020
|
return row?.n ?? 0;
|
|
1020
1021
|
}
|
|
1021
1022
|
//#endregion
|
|
1022
1023
|
//#region src/actions/aggregate-ir/execute.ts
|
|
1023
1024
|
async function executeAgg(Model, req, options = {}) {
|
|
1025
|
+
const session = options.session;
|
|
1024
1026
|
const { pipeline } = buildAggPipeline(req);
|
|
1025
1027
|
const aggregation = Model.aggregate(pipeline);
|
|
1026
|
-
if (
|
|
1028
|
+
if (session) aggregation.session(session);
|
|
1027
1029
|
return await aggregation.exec();
|
|
1028
1030
|
}
|
|
1029
1031
|
//#endregion
|
|
@@ -2712,9 +2714,11 @@ var Repository = class extends RepositoryBase {
|
|
|
2712
2714
|
for (const field of selectSpec) if (field.startsWith("-")) projection[field.substring(1)] = 0;
|
|
2713
2715
|
else projection[field] = 1;
|
|
2714
2716
|
} else projection = { ...selectSpec };
|
|
2715
|
-
if (
|
|
2716
|
-
|
|
2717
|
-
|
|
2717
|
+
if (projection) {
|
|
2718
|
+
if (Object.values(projection).some((v) => v === 1)) for (const lookup of lookups) {
|
|
2719
|
+
const asField = lookup.as || lookup.from;
|
|
2720
|
+
if (!(asField in projection)) projection[asField] = 1;
|
|
2721
|
+
}
|
|
2718
2722
|
}
|
|
2719
2723
|
}
|
|
2720
2724
|
const appendLookupStages = (pipeline) => {
|
|
@@ -4503,8 +4507,57 @@ function mongoOperationsPlugin() {
|
|
|
4503
4507
|
* ]);
|
|
4504
4508
|
* ```
|
|
4505
4509
|
*/
|
|
4510
|
+
/**
|
|
4511
|
+
* True when the op's policy target already has `tenantField` set by the
|
|
4512
|
+
* caller. Used to decide whether the plugin can safely skip injecting a
|
|
4513
|
+
* tenant scope rather than throwing on a missing context.
|
|
4514
|
+
*
|
|
4515
|
+
* - `data` — `context.data[tenantField]` is present
|
|
4516
|
+
* - `dataArray` — every row in `context.dataArray` has `tenantField`
|
|
4517
|
+
* - `query` — `context.query[tenantField]` is present
|
|
4518
|
+
* - `filters` — `context.filters[tenantField]` is present
|
|
4519
|
+
* - `operations` — every bulkWrite sub-op's filter/document has `tenantField`
|
|
4520
|
+
* - `none` — unreachable (the hook isn't registered for these ops)
|
|
4521
|
+
*
|
|
4522
|
+
* For multi-row targets (`dataArray`, `operations`) we require EVERY row to
|
|
4523
|
+
* be stamped. Partial stamping is ambiguous (we have no resolver value to
|
|
4524
|
+
* fill in the gaps) and is safer to treat as "not stamped" so the caller
|
|
4525
|
+
* either stamps all rows or supplies a context/resolver.
|
|
4526
|
+
*/
|
|
4527
|
+
function payloadHasTenantField(context, policyKey, tenantField) {
|
|
4528
|
+
switch (policyKey) {
|
|
4529
|
+
case "data": return context.data?.[tenantField] != null;
|
|
4530
|
+
case "dataArray": {
|
|
4531
|
+
const arr = context.dataArray;
|
|
4532
|
+
if (!Array.isArray(arr) || arr.length === 0) return false;
|
|
4533
|
+
return arr.every((row) => row && row[tenantField] != null);
|
|
4534
|
+
}
|
|
4535
|
+
case "query": return context.query?.[tenantField] != null;
|
|
4536
|
+
case "filters": return context.filters?.[tenantField] != null;
|
|
4537
|
+
case "operations": {
|
|
4538
|
+
const ops = context.operations;
|
|
4539
|
+
if (!Array.isArray(ops) || ops.length === 0) return false;
|
|
4540
|
+
return ops.every((subOp) => {
|
|
4541
|
+
for (const key of [
|
|
4542
|
+
"updateOne",
|
|
4543
|
+
"updateMany",
|
|
4544
|
+
"deleteOne",
|
|
4545
|
+
"deleteMany",
|
|
4546
|
+
"replaceOne"
|
|
4547
|
+
]) {
|
|
4548
|
+
const body = subOp[key];
|
|
4549
|
+
if (body) return body.filter?.[tenantField] != null;
|
|
4550
|
+
}
|
|
4551
|
+
const ins = subOp.insertOne;
|
|
4552
|
+
if (ins) return ins.document?.[tenantField] != null;
|
|
4553
|
+
return false;
|
|
4554
|
+
});
|
|
4555
|
+
}
|
|
4556
|
+
default: return false;
|
|
4557
|
+
}
|
|
4558
|
+
}
|
|
4506
4559
|
function multiTenantPlugin(options = {}) {
|
|
4507
|
-
const { tenantField = "organizationId", contextKey = "organizationId", required = true, skipOperations = [], skipWhen, resolveContext, fieldType = "string" } = options;
|
|
4560
|
+
const { tenantField = "organizationId", contextKey = "organizationId", required = true, skipOperations = [], skipWhen, resolveContext, fieldType = "string", allowDataInjection = true } = options;
|
|
4508
4561
|
const extraOps = [{
|
|
4509
4562
|
op: "getDeleted",
|
|
4510
4563
|
policyKey: "filters"
|
|
@@ -4526,6 +4579,7 @@ function multiTenantPlugin(options = {}) {
|
|
|
4526
4579
|
tenantId = resolveContext();
|
|
4527
4580
|
if (tenantId) context[contextKey] = tenantId;
|
|
4528
4581
|
}
|
|
4582
|
+
if (!tenantId && allowDataInjection && payloadHasTenantField(context, policyKey, tenantField)) return;
|
|
4529
4583
|
if (!tenantId && required) throw new Error(`[mongokit] Multi-tenant: Missing '${contextKey}' in context for '${op}'. Pass it via options or set required: false.`);
|
|
4530
4584
|
if (!tenantId) return;
|
|
4531
4585
|
const castId = fieldType === "objectId" ? new mongoose.Types.ObjectId(tenantId) : tenantId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/mongokit",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.3",
|
|
4
4
|
"description": "Production-grade MongoDB repositories - smart pagination, events, and plugins. Built on @classytic/repo-core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -110,14 +110,15 @@
|
|
|
110
110
|
"test:watch": "vitest --project unit --project integration",
|
|
111
111
|
"test:coverage": "vitest run --coverage",
|
|
112
112
|
"typecheck": "tsc --noEmit",
|
|
113
|
+
"typecheck:tests": "tsc --noEmit -p tsconfig.tests.json",
|
|
113
114
|
"lint": "biome check src/",
|
|
114
115
|
"lint:fix": "biome check src/ --write",
|
|
115
116
|
"format": "biome format src/ --write",
|
|
116
117
|
"check": "biome ci src/ --diagnostic-level=error",
|
|
117
|
-
"prepublishOnly": "npm run check && npm run build && npm run typecheck && npm test",
|
|
118
|
+
"prepublishOnly": "npm run check && npm run build && npm run typecheck && npm run typecheck:tests && npm test",
|
|
118
119
|
"publish:dry": "npm publish --dry-run --access public",
|
|
119
120
|
"publish:npm": "npm publish --access public",
|
|
120
|
-
"release": "npm run check && npm run build && npm run typecheck && npm test && npm publish --access public",
|
|
121
|
+
"release": "npm run check && npm run build && npm run typecheck && npm run typecheck:tests && npm test && npm publish --access public",
|
|
121
122
|
"release:patch": "npm version patch && npm run release",
|
|
122
123
|
"release:minor": "npm version minor && npm run release",
|
|
123
124
|
"release:major": "npm version major && npm run release"
|