@classytic/mongokit 3.19.0 → 3.21.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/dist/{PaginationEngine-BcvaXBQ-.mjs → PaginationEngine-BT1ywu9k.mjs} +327 -6
- package/dist/{PaginationEngine-4SjzfBQE.d.mts → PaginationEngine-DYpOD2wY.d.mts} +1 -2
- package/dist/{Repository-B01VW_fU.mjs → Repository-dbbgOGjK.mjs} +85 -11
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.mjs +2 -2
- package/dist/adapter/index.d.mts +27 -12
- package/dist/adapter/index.mjs +1 -1
- package/dist/{adapter-BSxhT0Ip.mjs → adapter-rTPLUrAV.mjs} +12 -2
- package/dist/ai/index.d.mts +1 -2
- package/dist/ai/index.mjs +3 -2
- package/dist/better-auth/index.d.mts +0 -1
- package/dist/better-auth/index.mjs +2 -2
- package/dist/{create-repository-K0yft2ht.d.mts → create-repository-0TkQhcv-.d.mts} +107 -13
- package/dist/{create-repository-D5YX0wGs.mjs → create-repository-CJATiAKX.mjs} +2 -2
- package/dist/{id-resolution-CnN0YA8t.mjs → id-resolution-P2OzcyRl.mjs} +10 -5
- package/dist/{index-BgSBwlWu.d.mts → index-Cg3SWugF.d.mts} +1 -3
- package/dist/index.d.mts +9 -10
- package/dist/index.mjs +52 -13
- package/dist/lock/index.d.mts +0 -1
- package/dist/memory-cache-DI1jb4dz.mjs +67 -0
- package/dist/{mongooseToJsonSchema-ChtXSrLT.mjs → mongooseToJsonSchema-CVnrKFDq.mjs} +2 -68
- package/dist/{mongooseToJsonSchema-Bz47aMfH.d.mts → mongooseToJsonSchema-D2CyAMIC.d.mts} +9 -5
- package/dist/{multi-tenant.plugin-D6lw3BsI.d.mts → multi-tenant.plugin-CTsWz0XK.d.mts} +1 -2
- package/dist/pagination/PaginationEngine.d.mts +1 -1
- package/dist/pagination/PaginationEngine.mjs +1 -1
- package/dist/plugins/index.d.mts +3 -4
- package/dist/plugins/index.mjs +2 -2
- package/dist/query/primitives/coercion.d.mts +1 -1
- package/dist/query/primitives/coercion.mjs +1 -1
- package/dist/query/primitives/geo.d.mts +1 -1
- package/dist/query/primitives/indexes.d.mts +1 -1
- package/dist/testkit/index.d.mts +1 -2
- package/dist/testkit/index.mjs +1 -1
- package/dist/{timestamp.plugin-B1A9U-P7.mjs → timestamp.plugin-nG9Z1JEk.mjs} +4 -4
- package/dist/{types-BA8oXjFe.d.mts → types-DNFMofHy.d.mts} +51 -22
- package/dist/{update-CvCMv5Cl.mjs → update-1Lq9OMD2.mjs} +5 -5
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.mjs +6 -5
- package/dist/{validation-chain.plugin-DHZbpb4t.mjs → validation-chain.plugin-Dn_wZYLA.mjs} +6 -6
- package/dist/{validation-chain.plugin-CYOPfFGF.d.mts → validation-chain.plugin-buy3uvyk.d.mts} +1 -2
- package/package.json +8 -7
- package/dist/cursor-_SbWVAn-.mjs +0 -254
- package/dist/sort-Ca1BPfvE.mjs +0 -72
- /package/dist/{coercion-BxxHyLjP.d.mts → coercion-BjdPX3YF.d.mts} +0 -0
- /package/dist/{error-BTeepSNL.mjs → error-BuByZwKU.mjs} +0 -0
- /package/dist/{field-selection-d1qdRiMr.mjs → field-selection-FSQFLpsU.mjs} +0 -0
- /package/dist/{indexes-3eHBWNZ2.d.mts → indexes-DIjMpYES.d.mts} +0 -0
- /package/dist/{logger-B8wf-Mtb.mjs → logger-K7dPmu2U.mjs} +0 -0
- /package/dist/{chunk-CfYAbeIz.mjs → rolldown-runtime-D7D4PA-g.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Repository } from "../Repository-
|
|
2
|
-
import { n as createMongooseAdapter } from "../adapter-
|
|
1
|
+
import { n as Repository } from "../Repository-dbbgOGjK.mjs";
|
|
2
|
+
import { n as createMongooseAdapter } from "../adapter-rTPLUrAV.mjs";
|
|
3
3
|
import { pluralizeBetterAuthCollection, resolveBetterAuthCollections } from "@classytic/repo-core/better-auth";
|
|
4
4
|
//#region src/better-auth/index.ts
|
|
5
5
|
/**
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { B as ObjectId, Dt as LookupOptions, Et as LookupBuilder, H as OperationOptions, J as PopulateSpec, M as LookupPopulateOptions, N as LookupPopulateResult, P as Middleware, Q as RepositoryContext, U as PaginationConfig, X as ReadOptions, Y as PrioritizedHook, Z as ReadPreferenceType, _ as DeleteManyResult, at as SessionOptions, c as CacheableOptions, d as CollationOptions, ft as UpdateManyResult, it as SelectSpec, j as Logger, n as AggregatePaginationOptions, nt as RepositoryOptions, p as CreateOptions, pt as UpdateOptions, q as PluginType, st as SoftDeleteOptions, t as AggregateOptions, ut as SortSpec$1, v as DeleteResult, w as FindOneAndUpdateOptions, xt as WithTransactionOptions } from "./types-
|
|
2
|
-
import { _ as RepositoryCachePluginOptions, i as CustomIdOptions, t as MultiTenantOptions, w as AuditTrailOptions } from "./multi-tenant.plugin-
|
|
3
|
-
import { t as PaginationEngine } from "./PaginationEngine-
|
|
4
|
-
import { AggPaginationRequest, AggRequest, AggResult, ChangeEvent, FilterInput, KeysetAggPaginationResult, QueryOptions, RepoCapabilities, RepositoryBase, TenantPurgeOptions, TenantPurgeResult, TenantPurgeStrategy, WatchOptions } from "@classytic/repo-core/repository";
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
1
|
+
import { B as ObjectId, Dt as LookupOptions, Et as LookupBuilder, H as OperationOptions, J as PopulateSpec, M as LookupPopulateOptions, N as LookupPopulateResult, P as Middleware, Q as RepositoryContext, U as PaginationConfig, X as ReadOptions, Y as PrioritizedHook, Z as ReadPreferenceType, _ as DeleteManyResult, at as SessionOptions, c as CacheableOptions, d as CollationOptions, ft as UpdateManyResult, it as SelectSpec, j as Logger, n as AggregatePaginationOptions, nt as RepositoryOptions, p as CreateOptions, pt as UpdateOptions, q as PluginType, st as SoftDeleteOptions, t as AggregateOptions, ut as SortSpec$1, v as DeleteResult, w as FindOneAndUpdateOptions, xt as WithTransactionOptions } from "./types-DNFMofHy.mjs";
|
|
2
|
+
import { _ as RepositoryCachePluginOptions, i as CustomIdOptions, t as MultiTenantOptions, w as AuditTrailOptions } from "./multi-tenant.plugin-CTsWz0XK.mjs";
|
|
3
|
+
import { t as PaginationEngine } from "./PaginationEngine-DYpOD2wY.mjs";
|
|
4
|
+
import { AggPaginationRequest, AggRequest, AggResult, ArchiveOptions, ArchiveResult, ArchiveSink, ChangeEvent, FilterInput, KeysetAggPaginationResult, QueryOptions, RepoCapabilities, RepositoryBase, TenantPurgeOptions, TenantPurgeResult, TenantPurgeStrategy, WatchOptions } from "@classytic/repo-core/repository";
|
|
5
|
+
import { ClientSession, Expression, Model, PipelineStage, PopulateOptions } from "mongoose";
|
|
6
|
+
import { Filter } from "@classytic/repo-core/filter";
|
|
7
7
|
import { UpdateInput } from "@classytic/repo-core/update";
|
|
8
8
|
import { AggregatePaginationResult, KeysetPaginationResult, OffsetPaginationResult, OffsetPaginationResultCore } from "@classytic/repo-core/pagination";
|
|
9
9
|
import { HttpError } from "@classytic/repo-core/errors";
|
|
10
|
-
|
|
11
10
|
//#region src/query/AggregationBuilder.d.ts
|
|
12
11
|
/** Options for $vectorSearch stage (Atlas only) */
|
|
13
12
|
interface VectorSearchOptions {
|
|
@@ -68,7 +67,7 @@ declare class AggregationBuilder {
|
|
|
68
67
|
* .exec(MyModel);
|
|
69
68
|
* ```
|
|
70
69
|
*/
|
|
71
|
-
exec<T = unknown>(model: Model<any>, session?:
|
|
70
|
+
exec<T = unknown>(model: Model<any>, session?: import('mongoose').ClientSession): Promise<T[]>;
|
|
72
71
|
/**
|
|
73
72
|
* Reset the pipeline
|
|
74
73
|
*/
|
|
@@ -428,6 +427,52 @@ declare class AggregationBuilder {
|
|
|
428
427
|
*/
|
|
429
428
|
static startWith(query: Record<string, unknown>): AggregationBuilder;
|
|
430
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* Optimized Aggregation Patterns for Scale
|
|
432
|
+
*
|
|
433
|
+
* 1. **Early Filtering** - Always place $match as early as possible:
|
|
434
|
+
* ```typescript
|
|
435
|
+
* new AggregationBuilder()
|
|
436
|
+
* .match({ status: 'active' }) // ✅ Filter first
|
|
437
|
+
* .lookup(...) // Then join
|
|
438
|
+
* .sort(...)
|
|
439
|
+
* ```
|
|
440
|
+
*
|
|
441
|
+
* 2. **Index Usage** - Ensure indexes on:
|
|
442
|
+
* - Fields in $match
|
|
443
|
+
* - Fields in $sort (especially with $limit)
|
|
444
|
+
* - Fields in $lookup (both local and foreign)
|
|
445
|
+
*
|
|
446
|
+
* 3. **Projection** - Remove unnecessary fields early:
|
|
447
|
+
* ```typescript
|
|
448
|
+
* .project({ password: 0, internalNotes: 0 }) // Remove before joins
|
|
449
|
+
* .lookup(...)
|
|
450
|
+
* ```
|
|
451
|
+
*
|
|
452
|
+
* 4. **Faceted Pagination** - Get count and data in one query:
|
|
453
|
+
* ```typescript
|
|
454
|
+
* .facet({
|
|
455
|
+
* metadata: [{ $count: 'total' }],
|
|
456
|
+
* data: [{ $skip: skip }, { $limit: limit }]
|
|
457
|
+
* })
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* 5. **allowDiskUse** - For large datasets:
|
|
461
|
+
* ```typescript
|
|
462
|
+
* new AggregationBuilder()
|
|
463
|
+
* .match({ status: 'active' })
|
|
464
|
+
* .allowDiskUse()
|
|
465
|
+
* .exec(Model)
|
|
466
|
+
* ```
|
|
467
|
+
*
|
|
468
|
+
* 6. **Vector Search** - Semantic similarity (Atlas only):
|
|
469
|
+
* ```typescript
|
|
470
|
+
* new AggregationBuilder()
|
|
471
|
+
* .vectorSearch({ index: 'vec_idx', path: 'embedding', queryVector: vec, limit: 10 })
|
|
472
|
+
* .withVectorScore()
|
|
473
|
+
* .exec(Model)
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
431
476
|
//#endregion
|
|
432
477
|
//#region src/Repository.d.ts
|
|
433
478
|
/**
|
|
@@ -649,6 +694,36 @@ declare class Repository<TDoc = unknown> extends RepositoryBase {
|
|
|
649
694
|
* Get document by ID
|
|
650
695
|
*/
|
|
651
696
|
getById(id: string | ObjectId, options?: CacheableOptions): Promise<TDoc | null>;
|
|
697
|
+
/**
|
|
698
|
+
* Batch point-read — the `$in` counterpart to {@link getById}. Fetches every
|
|
699
|
+
* doc whose id (the repo's `idField`, default `_id`) is in `ids` in ONE query,
|
|
700
|
+
* routed through `findAll` so tenant + soft-delete scoping and hooks apply
|
|
701
|
+
* exactly as a single read would. Returns a Map keyed by the stringified id;
|
|
702
|
+
* ids are de-duplicated and ids with no matching doc are simply absent (no
|
|
703
|
+
* throw — mirrors `getById(..., { throwOnNotFound: false })`). Structurally
|
|
704
|
+
* INVALID ids (wrong ObjectId shape, non-numeric for a Number id field, ...)
|
|
705
|
+
* are dropped the same way — an id that cannot exist in the collection is
|
|
706
|
+
* unambiguously a miss, and one malformed id must never poison the rest of
|
|
707
|
+
* the batch. Lean by default (findAll semantics) — pass `{ lean: false }`
|
|
708
|
+
* for hydrated docs.
|
|
709
|
+
*
|
|
710
|
+
* The N+1 killer for hosts that resolve many ids in one tick (order-line
|
|
711
|
+
* snapshotting, availability matrices, dashboard row enrichment):
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* const byId = await repo.getByIds(offerIds, ctx);
|
|
715
|
+
* const doc = byId.get(offerId); // O(1); undefined if not found
|
|
716
|
+
*
|
|
717
|
+
* Sizing: there is no library-imposed cap — the bounds are MongoDB's (the
|
|
718
|
+
* `$in` array must fit the 16 MB query document; `$in` on an indexed field
|
|
719
|
+
* is n point-lookups). Keep batches ≤ ~10k ids per call and chunk beyond
|
|
720
|
+
* that. Don't exclude the id field via `select` — result keys derive from
|
|
721
|
+
* it.
|
|
722
|
+
*/
|
|
723
|
+
getByIds(ids: ReadonlyArray<string | ObjectId>, options?: OperationOptions & {
|
|
724
|
+
sort?: SortSpec$1 | string;
|
|
725
|
+
limit?: number;
|
|
726
|
+
}): Promise<Map<string, TDoc>>;
|
|
652
727
|
/**
|
|
653
728
|
* Get single document by query
|
|
654
729
|
*/
|
|
@@ -793,10 +868,14 @@ declare class Repository<TDoc = unknown> extends RepositoryBase {
|
|
|
793
868
|
hint?: string | Record<string, 1 | -1>;
|
|
794
869
|
maxTimeMS?: number;
|
|
795
870
|
countStrategy?: 'exact' | 'estimated' | 'none';
|
|
796
|
-
readPreference?: ReadPreferenceType;
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
871
|
+
readPreference?: ReadPreferenceType;
|
|
872
|
+
/** Advanced populate options (from QueryParser or Arc's BaseController) */
|
|
873
|
+
populateOptions?: PopulateOptions[];
|
|
874
|
+
/** Collation for locale-aware string comparison */
|
|
875
|
+
collation?: CollationOptions;
|
|
876
|
+
/** Lookup configurations for $lookup joins (from QueryParser or manual) */
|
|
877
|
+
lookups?: LookupOptions[];
|
|
878
|
+
/** Skip pagination entirely — returns raw TDoc[] (same as findAll) */
|
|
800
879
|
noPagination?: boolean;
|
|
801
880
|
}, options?: CacheableOptions): Promise<OffsetPaginationResult<TDoc> | KeysetPaginationResult<TDoc> | TDoc[]>;
|
|
802
881
|
/**
|
|
@@ -1233,7 +1312,8 @@ declare class Repository<TDoc = unknown> extends RepositoryBase {
|
|
|
1233
1312
|
*/
|
|
1234
1313
|
delete(id: string | ObjectId, options?: SessionOptions & {
|
|
1235
1314
|
idField?: string;
|
|
1236
|
-
mode?: 'hard' | 'soft';
|
|
1315
|
+
mode?: 'hard' | 'soft';
|
|
1316
|
+
/** Legacy opt-in: throw a 404 error on miss instead of returning `null`. */
|
|
1237
1317
|
throwOnNotFound?: boolean;
|
|
1238
1318
|
}): Promise<DeleteResult | null>;
|
|
1239
1319
|
/**
|
|
@@ -1287,6 +1367,20 @@ declare class Repository<TDoc = unknown> extends RepositoryBase {
|
|
|
1287
1367
|
* the port implementation.
|
|
1288
1368
|
*/
|
|
1289
1369
|
purgeByField(field: string, value: unknown, strategy: TenantPurgeStrategy, options?: TenantPurgeOptions): Promise<TenantPurgeResult>;
|
|
1370
|
+
/**
|
|
1371
|
+
* Chunked cold-storage extraction — see `StandardRepo.archiveByFilter`
|
|
1372
|
+
* for the cross-kit contract (write-before-delete, at-least-once,
|
|
1373
|
+
* duplicate-tolerant sinks). Mongokit composes the kit-agnostic
|
|
1374
|
+
* `runChunkedArchive` orchestrator with `createMongoArchivePort`
|
|
1375
|
+
* (`_id`-ordered lean reads + plugin-routed deleteMany removal). See
|
|
1376
|
+
* [actions/archive.ts](./actions/archive.ts) for the port.
|
|
1377
|
+
*
|
|
1378
|
+
* Accepts Filter IR or a Mongo-shaped filter record — compiled once via
|
|
1379
|
+
* `compileFilterToMongo`, same dual-dialect rule as every other verb.
|
|
1380
|
+
*/
|
|
1381
|
+
archiveByFilter(filter: Record<string, unknown> | Filter, sink: ArchiveSink<TDoc>, options?: ArchiveOptions & {
|
|
1382
|
+
session?: ClientSession;
|
|
1383
|
+
}): Promise<ArchiveResult>;
|
|
1290
1384
|
/**
|
|
1291
1385
|
* Kit-native aggregation pipeline — takes a MongoDB stage array and
|
|
1292
1386
|
* returns the raw pipeline output. Use this for `$lookup`, `$unwind`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Repository } from "./Repository-
|
|
2
|
-
import { a as methodRegistryPlugin, d as cachePlugin, f as batchOperationsPlugin, h as auditLogPlugin, i as multiTenantPlugin, m as auditTrailPlugin, n as softDeletePlugin, o as customIdPlugin, t as timestampPlugin } from "./timestamp.plugin-
|
|
1
|
+
import { n as Repository } from "./Repository-dbbgOGjK.mjs";
|
|
2
|
+
import { a as methodRegistryPlugin, d as cachePlugin, f as batchOperationsPlugin, h as auditLogPlugin, i as multiTenantPlugin, m as auditTrailPlugin, n as softDeletePlugin, o as customIdPlugin, t as timestampPlugin } from "./timestamp.plugin-nG9Z1JEk.mjs";
|
|
3
3
|
//#region src/create-repository.ts
|
|
4
4
|
function isLoggerAudit(value) {
|
|
5
5
|
const v = value;
|
|
@@ -25,9 +25,10 @@ function isObjectIdInstance(instance) {
|
|
|
25
25
|
}
|
|
26
26
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
27
27
|
/**
|
|
28
|
-
* Detect
|
|
28
|
+
* Detect an id path's type from a Mongoose schema. Defaults to the `_id`
|
|
29
|
+
* path; pass `field` to resolve a custom id field (Repository's `idField`).
|
|
29
30
|
*
|
|
30
|
-
*
|
|
31
|
+
* For `_id`, returns 'objectid' as the safe default when:
|
|
31
32
|
* - No schema is provided (mock models, test harnesses)
|
|
32
33
|
* - The schema has no `paths._id` (auto-generated ObjectId)
|
|
33
34
|
* - The instance string is unrecognized
|
|
@@ -35,10 +36,14 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
|
|
35
36
|
* This safe-default means existing callers that don't set _id explicitly
|
|
36
37
|
* get the same ObjectId validation they always had — the behavioral change
|
|
37
38
|
* is strictly opt-in via schema declaration.
|
|
39
|
+
*
|
|
40
|
+
* For a custom `field` with no resolvable path, returns 'unknown' instead —
|
|
41
|
+
* custom id fields carry no ObjectId convention, so validation stays
|
|
42
|
+
* permissive and the DB remains the authority.
|
|
38
43
|
*/
|
|
39
|
-
function getSchemaIdType(schema) {
|
|
40
|
-
const instance = schema?.paths?.
|
|
41
|
-
if (!instance) return "objectid";
|
|
44
|
+
function getSchemaIdType(schema, field = "_id") {
|
|
45
|
+
const instance = schema?.paths?.[field]?.instance;
|
|
46
|
+
if (!instance) return field === "_id" ? "objectid" : "unknown";
|
|
42
47
|
if (isObjectIdInstance(instance)) return "objectid";
|
|
43
48
|
switch (instance) {
|
|
44
49
|
case "String": return "string";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { B as ObjectId, Dt as LookupOptions, H as OperationOptions, I as MinMaxResult, J as PopulateSpec, T as GroupResult, Z as ReadPreferenceType, ft as UpdateManyResult, ht as UpdateWithValidationResult, i as AnyDocument, it as SelectSpec, p as CreateOptions, pt as UpdateOptions, ut as SortSpec, v as DeleteResult, w as FindOneAndUpdateOptions } from "./types-
|
|
1
|
+
import { B as ObjectId, Dt as LookupOptions, H as OperationOptions, I as MinMaxResult, J as PopulateSpec, T as GroupResult, Z as ReadPreferenceType, ft as UpdateManyResult, ht as UpdateWithValidationResult, i as AnyDocument, it as SelectSpec, p as CreateOptions, pt as UpdateOptions, ut as SortSpec, v as DeleteResult, w as FindOneAndUpdateOptions } from "./types-DNFMofHy.mjs";
|
|
2
2
|
import { Model, PipelineStage } from "mongoose";
|
|
3
|
-
|
|
4
|
-
//#region src/actions/aggregate.d.ts
|
|
5
3
|
declare namespace aggregate_d_exports {
|
|
6
4
|
export { aggregate, aggregatePaginate, average, countBy, distinct, facet, groupBy, lookup, minMax, sum, unwind };
|
|
7
5
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { $ as RepositoryEvent, A as KeysetPaginationOptions, B as ObjectId, C as FieldPreset, Ct as IControllerResponse, D as InferDocument, Dt as LookupOptions, E as HookMode, Et as LookupBuilder, F as MiddlewareContext, G as Plugin, H as OperationOptions, I as MinMaxResult, J as PopulateSpec, K as PluginFunction, L as MinimalRepoView, M as LookupPopulateOptions, N as LookupPopulateResult, O as InferRawDoc, P as Middleware, Q as RepositoryContext, R as MongoOperatorUpdate, S as EventPhase, St as IController, T as GroupResult, Tt as IResponseFormatter, U as PaginationConfig, V as OffsetPaginationOptions, W as PartialBy, X as ReadOptions, Y as PrioritizedHook, Z as ReadPreferenceType, _t as ValidationChainOptions, a as AnyModel, at as SessionOptions, b as EventHandlers, bt as WithPlugins, c as CacheableOptions, ct as SoftDeleteRepository, d as CollationOptions, dt as Strict, et as RepositoryInstance, f as CreateInput, ft as UpdateManyResult, g as DeepPartial, gt as UserContext, h as DecodedCursor, ht as UpdateWithValidationResult, i as AnyDocument, it as SelectSpec, j as Logger, k as KeysOfType, l as CascadeOptions, lt as SortDirection, m as CursorPayload, mt as UpdatePatch, n as AggregatePaginationOptions, nt as RepositoryOptions, o as BasePaginationOptions, ot as SoftDeleteFilterMode, p as CreateOptions, pt as UpdateOptions, q as PluginType, r as AllPluginMethods, rt as RequiredBy, s as CacheOperationOptions, st as SoftDeleteOptions, t as AggregateOptions, tt as RepositoryOperation, u as CascadeRelation, ut as SortSpec, v as DeleteResult, vt as ValidatorDefinition, w as FindOneAndUpdateOptions, wt as IRequestContext, x as EventPayload, xt as WithTransactionOptions, y as DocField, yt as ValueType, z as NonNullableFields } from "./types-
|
|
2
|
-
import { t as index_d_exports } from "./index-
|
|
3
|
-
import { C as AuditTrailMethods, E as auditTrailPlugin, S as AuditQueryResult, T as AuditTrailQuery, _ as RepositoryCachePluginOptions, a as DateSequentialIdOptions, b as AuditOperation, c as SequentialIdOptions, d as getNextSequence, f as prefixedId, g as RepositoryCacheHandle, h as CacheOptions, i as CustomIdOptions, l as customIdPlugin, m as CacheAdapter, n as adminBypass, o as IdGenerator, p as sequentialId, r as multiTenantPlugin, s as PrefixedIdOptions, t as MultiTenantOptions, u as dateSequentialId, v as cachePlugin, w as AuditTrailOptions, x as AuditQueryOptions, y as AuditEntry } from "./multi-tenant.plugin-
|
|
4
|
-
import { t as PaginationEngine } from "./PaginationEngine-
|
|
5
|
-
import { a as Repository, i as HOOK_PRIORITY, n as CreateRepositoryConfig, o as AggregationBuilder, r as createRepository, t as AuditConfig } from "./create-repository-
|
|
6
|
-
import { A as BulkWriteResult, C as LeasePluginOptions, D as elasticSearchPlugin, E as ElasticSearchOptions, M as auditLogPlugin, N as AggregateHelpersMethods, O as cascadePlugin, P as aggregateHelpersPlugin, S as LeaseMethods, T as fieldFilterPlugin, _ as observabilityPlugin, a as uniqueField, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as batchOperationsPlugin, k as BatchOperationsMethods, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MongoOperationsMethods, w as leasePlugin, x as methodRegistryPlugin, y as mongoOperationsPlugin } from "./validation-chain.plugin-
|
|
7
|
-
import { n as SchemaPathsLike, t as FieldType$1 } from "./coercion-
|
|
8
|
-
import { n as SchemaIndexes } from "./indexes-
|
|
9
|
-
import { d as filterResponseData, f as getFieldsForUser, g as parseDuplicateKeyError, h as isDuplicateKeyError, i as configureLogger, m as createError, n as buildCrudSchemasFromMongooseSchema, p as getMongooseProjection, r as createMemoryCache, s as idVariants, t as buildCrudSchemasFromModel, u as createFieldPreset } from "./mongooseToJsonSchema-
|
|
1
|
+
import { $ as RepositoryEvent, A as KeysetPaginationOptions, B as ObjectId, C as FieldPreset, Ct as IControllerResponse, D as InferDocument, Dt as LookupOptions, E as HookMode, Et as LookupBuilder, F as MiddlewareContext, G as Plugin, H as OperationOptions, I as MinMaxResult, J as PopulateSpec, K as PluginFunction, L as MinimalRepoView, M as LookupPopulateOptions, N as LookupPopulateResult, O as InferRawDoc, P as Middleware, Q as RepositoryContext, R as MongoOperatorUpdate, S as EventPhase, St as IController, T as GroupResult, Tt as IResponseFormatter, U as PaginationConfig, V as OffsetPaginationOptions, W as PartialBy, X as ReadOptions, Y as PrioritizedHook, Z as ReadPreferenceType, _t as ValidationChainOptions, a as AnyModel, at as SessionOptions, b as EventHandlers, bt as WithPlugins, c as CacheableOptions, ct as SoftDeleteRepository, d as CollationOptions, dt as Strict, et as RepositoryInstance, f as CreateInput, ft as UpdateManyResult, g as DeepPartial, gt as UserContext, h as DecodedCursor, ht as UpdateWithValidationResult, i as AnyDocument, it as SelectSpec, j as Logger, k as KeysOfType, l as CascadeOptions, lt as SortDirection, m as CursorPayload, mt as UpdatePatch, n as AggregatePaginationOptions, nt as RepositoryOptions, o as BasePaginationOptions, ot as SoftDeleteFilterMode, p as CreateOptions, pt as UpdateOptions, q as PluginType, r as AllPluginMethods, rt as RequiredBy, s as CacheOperationOptions, st as SoftDeleteOptions, t as AggregateOptions, tt as RepositoryOperation, u as CascadeRelation, ut as SortSpec, v as DeleteResult, vt as ValidatorDefinition, w as FindOneAndUpdateOptions, wt as IRequestContext, x as EventPayload, xt as WithTransactionOptions, y as DocField, yt as ValueType, z as NonNullableFields } from "./types-DNFMofHy.mjs";
|
|
2
|
+
import { t as index_d_exports } from "./index-Cg3SWugF.mjs";
|
|
3
|
+
import { C as AuditTrailMethods, E as auditTrailPlugin, S as AuditQueryResult, T as AuditTrailQuery, _ as RepositoryCachePluginOptions, a as DateSequentialIdOptions, b as AuditOperation, c as SequentialIdOptions, d as getNextSequence, f as prefixedId, g as RepositoryCacheHandle, h as CacheOptions, i as CustomIdOptions, l as customIdPlugin, m as CacheAdapter, n as adminBypass, o as IdGenerator, p as sequentialId, r as multiTenantPlugin, s as PrefixedIdOptions, t as MultiTenantOptions, u as dateSequentialId, v as cachePlugin, w as AuditTrailOptions, x as AuditQueryOptions, y as AuditEntry } from "./multi-tenant.plugin-CTsWz0XK.mjs";
|
|
4
|
+
import { t as PaginationEngine } from "./PaginationEngine-DYpOD2wY.mjs";
|
|
5
|
+
import { a as Repository, i as HOOK_PRIORITY, n as CreateRepositoryConfig, o as AggregationBuilder, r as createRepository, t as AuditConfig } from "./create-repository-0TkQhcv-.mjs";
|
|
6
|
+
import { A as BulkWriteResult, C as LeasePluginOptions, D as elasticSearchPlugin, E as ElasticSearchOptions, M as auditLogPlugin, N as AggregateHelpersMethods, O as cascadePlugin, P as aggregateHelpersPlugin, S as LeaseMethods, T as fieldFilterPlugin, _ as observabilityPlugin, a as uniqueField, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as batchOperationsPlugin, k as BatchOperationsMethods, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MongoOperationsMethods, w as leasePlugin, x as methodRegistryPlugin, y as mongoOperationsPlugin } from "./validation-chain.plugin-buy3uvyk.mjs";
|
|
7
|
+
import { n as SchemaPathsLike, t as FieldType$1 } from "./coercion-BjdPX3YF.mjs";
|
|
8
|
+
import { n as SchemaIndexes } from "./indexes-DIjMpYES.mjs";
|
|
9
|
+
import { d as filterResponseData, f as getFieldsForUser, g as parseDuplicateKeyError, h as isDuplicateKeyError, i as configureLogger, m as createError, n as buildCrudSchemasFromMongooseSchema, p as getMongooseProjection, r as createMemoryCache, s as idVariants, t as buildCrudSchemasFromModel, u as createFieldPreset } from "./mongooseToJsonSchema-D2CyAMIC.mjs";
|
|
10
10
|
import { RepoCapabilities } from "@classytic/repo-core/repository";
|
|
11
11
|
import { ClientSession, PipelineStage } from "mongoose";
|
|
12
|
-
|
|
13
12
|
//#region src/actions/cascade-references.d.ts
|
|
14
13
|
type PurgeMode = 'hard' | 'soft' | 'anonymize';
|
|
15
14
|
/** Raw collection surface — a native MongoDB `Collection` or a Mongoose `Model`. */
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { n as idVariants } from "./id-resolution-
|
|
2
|
-
import { a as withTransaction, c as MUTATING_OPERATIONS, d as operationsByPolicyKey, f as MONGOKIT_CAPABILITIES, i as isTransactionUnsupported, l as OP_REGISTRY, n as Repository, o as AggregationBuilder, p as createMongoPurgePort, r as batchTransaction, s as ALL_OPERATIONS, t as HOOK_PRIORITY, u as READ_OPERATIONS } from "./Repository-
|
|
3
|
-
import { b as LookupBuilder, x as compileFilterToMongo } from "./update-
|
|
4
|
-
import { n as warn, t as configureLogger } from "./logger-
|
|
5
|
-
import { n as isDuplicateKeyError, r as parseDuplicateKeyError, t as createError } from "./error-
|
|
1
|
+
import { n as idVariants } from "./id-resolution-P2OzcyRl.mjs";
|
|
2
|
+
import { a as withTransaction, c as MUTATING_OPERATIONS, d as operationsByPolicyKey, f as MONGOKIT_CAPABILITIES, i as isTransactionUnsupported, l as OP_REGISTRY, n as Repository, o as AggregationBuilder, p as createMongoPurgePort, r as batchTransaction, s as ALL_OPERATIONS, t as HOOK_PRIORITY, u as READ_OPERATIONS } from "./Repository-dbbgOGjK.mjs";
|
|
3
|
+
import { b as LookupBuilder, x as compileFilterToMongo } from "./update-1Lq9OMD2.mjs";
|
|
4
|
+
import { n as warn, t as configureLogger } from "./logger-K7dPmu2U.mjs";
|
|
5
|
+
import { n as isDuplicateKeyError, r as parseDuplicateKeyError, t as createError } from "./error-BuByZwKU.mjs";
|
|
6
6
|
import { t as actions_exports } from "./actions/index.mjs";
|
|
7
|
-
import { a as methodRegistryPlugin, c as getNextSequence, d as cachePlugin, f as batchOperationsPlugin, h as auditLogPlugin, i as multiTenantPlugin, l as prefixedId, m as auditTrailPlugin, n as softDeletePlugin, o as customIdPlugin, p as AuditTrailQuery, r as adminBypass, s as dateSequentialId, t as timestampPlugin, u as sequentialId } from "./timestamp.plugin-
|
|
8
|
-
import { t as PaginationEngine } from "./PaginationEngine-
|
|
7
|
+
import { a as methodRegistryPlugin, c as getNextSequence, d as cachePlugin, f as batchOperationsPlugin, h as auditLogPlugin, i as multiTenantPlugin, l as prefixedId, m as auditTrailPlugin, n as softDeletePlugin, o as customIdPlugin, p as AuditTrailQuery, r as adminBypass, s as dateSequentialId, t as timestampPlugin, u as sequentialId } from "./timestamp.plugin-nG9Z1JEk.mjs";
|
|
8
|
+
import { t as PaginationEngine } from "./PaginationEngine-BT1ywu9k.mjs";
|
|
9
9
|
import { isGeoOperator, parseGeoFilter } from "./query/primitives/geo.mjs";
|
|
10
|
-
import { t as createRepository } from "./create-repository-
|
|
11
|
-
import { a as uniqueField, c as subdocumentPlugin, d as leasePlugin, f as fieldFilterPlugin, h as aggregateHelpersPlugin, i as requireField, l as observabilityPlugin, m as cascadePlugin, n as blockIf, o as validationChainPlugin, p as elasticSearchPlugin, r as immutableField, s as createTenantContext, t as autoInject, u as mongoOperationsPlugin } from "./validation-chain.plugin-
|
|
12
|
-
import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "./field-selection-
|
|
10
|
+
import { t as createRepository } from "./create-repository-CJATiAKX.mjs";
|
|
11
|
+
import { a as uniqueField, c as subdocumentPlugin, d as leasePlugin, f as fieldFilterPlugin, h as aggregateHelpersPlugin, i as requireField, l as observabilityPlugin, m as cascadePlugin, n as blockIf, o as validationChainPlugin, p as elasticSearchPlugin, r as immutableField, s as createTenantContext, t as autoInject, u as mongoOperationsPlugin } from "./validation-chain.plugin-Dn_wZYLA.mjs";
|
|
12
|
+
import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "./field-selection-FSQFLpsU.mjs";
|
|
13
13
|
import { buildFieldTypeMap, coerceFieldValue, coerceHeuristic } from "./query/primitives/coercion.mjs";
|
|
14
14
|
import { extractSchemaIndexes } from "./query/primitives/indexes.mjs";
|
|
15
|
-
import {
|
|
15
|
+
import { t as createMemoryCache } from "./memory-cache-DI1jb4dz.mjs";
|
|
16
|
+
import { n as buildCrudSchemasFromMongooseSchema, t as buildCrudSchemasFromModel } from "./mongooseToJsonSchema-CVnrKFDq.mjs";
|
|
16
17
|
import { runChunkedPurge } from "@classytic/repo-core/repository";
|
|
17
18
|
import { isControlParam } from "@classytic/repo-core/query-parser";
|
|
18
19
|
//#region src/actions/cascade-references.ts
|
|
@@ -226,7 +227,7 @@ async function cascadePurgeReferences(options) {
|
|
|
226
227
|
* without this guard. Kept as a Set for O(1) lookup; values mirror the
|
|
227
228
|
* reserved-key list at the top of `_parseFilters`.
|
|
228
229
|
*/
|
|
229
|
-
const RESERVED_PAGINATION_KEYS = new Set([
|
|
230
|
+
const RESERVED_PAGINATION_KEYS = /* @__PURE__ */ new Set([
|
|
230
231
|
"page",
|
|
231
232
|
"limit",
|
|
232
233
|
"sort",
|
|
@@ -1043,7 +1044,7 @@ var QueryParser = class {
|
|
|
1043
1044
|
return {};
|
|
1044
1045
|
}
|
|
1045
1046
|
const sanitized = {};
|
|
1046
|
-
const logicalArrayOps = new Set([
|
|
1047
|
+
const logicalArrayOps = /* @__PURE__ */ new Set([
|
|
1047
1048
|
"$or",
|
|
1048
1049
|
"$and",
|
|
1049
1050
|
"$nor"
|
|
@@ -1421,6 +1422,44 @@ function systemContext(extra) {
|
|
|
1421
1422
|
}
|
|
1422
1423
|
//#endregion
|
|
1423
1424
|
//#region src/index.ts
|
|
1425
|
+
/**
|
|
1426
|
+
* MongoKit - Event-driven repository pattern for MongoDB
|
|
1427
|
+
*
|
|
1428
|
+
* Production-grade MongoDB repositories with zero dependencies -
|
|
1429
|
+
* smart pagination, events, and plugins.
|
|
1430
|
+
*
|
|
1431
|
+
* @module @classytic/mongokit
|
|
1432
|
+
* @author Classytic (https://github.com/classytic)
|
|
1433
|
+
* @license MIT
|
|
1434
|
+
*
|
|
1435
|
+
* @example
|
|
1436
|
+
* ```typescript
|
|
1437
|
+
* import { createRepository } from '@classytic/mongokit';
|
|
1438
|
+
*
|
|
1439
|
+
* // Create repository with declarative config (plugins composed in the
|
|
1440
|
+
* // canonical safe order automatically)
|
|
1441
|
+
* const userRepo = createRepository(UserModel, {
|
|
1442
|
+
* timestamps: true,
|
|
1443
|
+
* softDelete: true,
|
|
1444
|
+
* });
|
|
1445
|
+
*
|
|
1446
|
+
* // Create
|
|
1447
|
+
* const user = await userRepo.create({ name: 'John', email: 'john@example.com' });
|
|
1448
|
+
*
|
|
1449
|
+
* // Read with pagination (auto-detects offset vs keyset)
|
|
1450
|
+
* const users = await userRepo.getAll({ page: 1, limit: 20 });
|
|
1451
|
+
*
|
|
1452
|
+
* // Keyset pagination for infinite scroll
|
|
1453
|
+
* const stream = await userRepo.getAll({ sort: { createdAt: -1 }, limit: 50 });
|
|
1454
|
+
* const nextStream = await userRepo.getAll({ after: stream.next, sort: { createdAt: -1 } });
|
|
1455
|
+
*
|
|
1456
|
+
* // Update
|
|
1457
|
+
* await userRepo.update(user._id, { name: 'John Doe' });
|
|
1458
|
+
*
|
|
1459
|
+
* // Delete
|
|
1460
|
+
* await userRepo.delete(user._id);
|
|
1461
|
+
* ```
|
|
1462
|
+
*/
|
|
1424
1463
|
var src_default = Repository;
|
|
1425
1464
|
//#endregion
|
|
1426
1465
|
export { ALL_OPERATIONS, AggregationBuilder, AuditTrailQuery, HOOK_PRIORITY, LookupBuilder, MONGOKIT_CAPABILITIES, MUTATING_OPERATIONS, OP_REGISTRY, PaginationEngine, QueryParser, READ_OPERATIONS, Repository, actions_exports as actions, adminBypass, aggregateHelpersPlugin, auditLogPlugin, auditTrailPlugin, autoInject, batchOperationsPlugin, batchTransaction, blockIf, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, cachePlugin, cascadePlugin, cascadePurgeReferences, compileFilterToMongo, configureLogger, createError, createFieldPreset, createMemoryCache, createOptionsExtractor, createRepository, createTenantContext, customIdPlugin, dateSequentialId, src_default as default, elasticSearchPlugin, fieldFilterPlugin, filterResponseData, getFieldsForUser, getMongooseProjection, getNextSequence, idVariants, immutableField, isDuplicateKeyError, isTransactionUnsupported, leasePlugin, methodRegistryPlugin, mongoOperationsPlugin, multiTenantPlugin, observabilityPlugin, operationsByPolicyKey, parseDuplicateKeyError, prefixedId, repoOptionsFromCtx, requireField, sequentialId, softDeletePlugin, subdocumentPlugin, systemContext, timestampPlugin, uniqueField, validationChainPlugin, withTransaction };
|
package/dist/lock/index.d.mts
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/utils/memory-cache.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates an in-memory cache adapter
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Automatic TTL expiration
|
|
7
|
+
* - Pattern-based clearing (simple glob with *)
|
|
8
|
+
* - Max entries limit to prevent memory leaks
|
|
9
|
+
*
|
|
10
|
+
* @param maxEntries - Maximum cache entries before oldest are evicted (default: 1000)
|
|
11
|
+
*/
|
|
12
|
+
function createMemoryCache(maxEntries = 1e3) {
|
|
13
|
+
const cache = /* @__PURE__ */ new Map();
|
|
14
|
+
let lastCleanup = Date.now();
|
|
15
|
+
const CLEANUP_INTERVAL_MS = 6e4;
|
|
16
|
+
function cleanupIfNeeded() {
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
if (now - lastCleanup < CLEANUP_INTERVAL_MS) return;
|
|
19
|
+
lastCleanup = now;
|
|
20
|
+
for (const [key, entry] of cache) if (entry.expiresAt < now) cache.delete(key);
|
|
21
|
+
}
|
|
22
|
+
function evictOldest() {
|
|
23
|
+
while (cache.size >= maxEntries) {
|
|
24
|
+
const firstKey = cache.keys().next().value;
|
|
25
|
+
if (firstKey) cache.delete(firstKey);
|
|
26
|
+
else break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
async get(key) {
|
|
31
|
+
const entry = cache.get(key);
|
|
32
|
+
if (!entry) return null;
|
|
33
|
+
if (entry.expiresAt < Date.now()) {
|
|
34
|
+
cache.delete(key);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
cache.delete(key);
|
|
38
|
+
cache.set(key, entry);
|
|
39
|
+
return entry.value;
|
|
40
|
+
},
|
|
41
|
+
async set(key, value, ttl) {
|
|
42
|
+
cache.delete(key);
|
|
43
|
+
if (cache.size >= maxEntries) {
|
|
44
|
+
cleanupIfNeeded();
|
|
45
|
+
evictOldest();
|
|
46
|
+
}
|
|
47
|
+
cache.set(key, {
|
|
48
|
+
value,
|
|
49
|
+
expiresAt: Date.now() + ttl * 1e3
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
async delete(key) {
|
|
53
|
+
cache.delete(key);
|
|
54
|
+
},
|
|
55
|
+
async clear(pattern) {
|
|
56
|
+
if (!pattern) {
|
|
57
|
+
cache.clear();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
61
|
+
const regex = new RegExp(`^${escaped}$`);
|
|
62
|
+
for (const key of cache.keys()) if (regex.test(key)) cache.delete(key);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { createMemoryCache as t };
|
|
@@ -1,72 +1,6 @@
|
|
|
1
|
-
import { r as isObjectIdInstance } from "./id-resolution-
|
|
1
|
+
import { r as isObjectIdInstance } from "./id-resolution-P2OzcyRl.mjs";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
3
|
import { applyFieldRules, collectFieldsToOmit } from "@classytic/repo-core/schema";
|
|
4
|
-
//#region src/utils/memory-cache.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates an in-memory cache adapter
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - Automatic TTL expiration
|
|
10
|
-
* - Pattern-based clearing (simple glob with *)
|
|
11
|
-
* - Max entries limit to prevent memory leaks
|
|
12
|
-
*
|
|
13
|
-
* @param maxEntries - Maximum cache entries before oldest are evicted (default: 1000)
|
|
14
|
-
*/
|
|
15
|
-
function createMemoryCache(maxEntries = 1e3) {
|
|
16
|
-
const cache = /* @__PURE__ */ new Map();
|
|
17
|
-
let lastCleanup = Date.now();
|
|
18
|
-
const CLEANUP_INTERVAL_MS = 6e4;
|
|
19
|
-
function cleanupIfNeeded() {
|
|
20
|
-
const now = Date.now();
|
|
21
|
-
if (now - lastCleanup < CLEANUP_INTERVAL_MS) return;
|
|
22
|
-
lastCleanup = now;
|
|
23
|
-
for (const [key, entry] of cache) if (entry.expiresAt < now) cache.delete(key);
|
|
24
|
-
}
|
|
25
|
-
function evictOldest() {
|
|
26
|
-
while (cache.size >= maxEntries) {
|
|
27
|
-
const firstKey = cache.keys().next().value;
|
|
28
|
-
if (firstKey) cache.delete(firstKey);
|
|
29
|
-
else break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
async get(key) {
|
|
34
|
-
const entry = cache.get(key);
|
|
35
|
-
if (!entry) return null;
|
|
36
|
-
if (entry.expiresAt < Date.now()) {
|
|
37
|
-
cache.delete(key);
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
cache.delete(key);
|
|
41
|
-
cache.set(key, entry);
|
|
42
|
-
return entry.value;
|
|
43
|
-
},
|
|
44
|
-
async set(key, value, ttl) {
|
|
45
|
-
cache.delete(key);
|
|
46
|
-
if (cache.size >= maxEntries) {
|
|
47
|
-
cleanupIfNeeded();
|
|
48
|
-
evictOldest();
|
|
49
|
-
}
|
|
50
|
-
cache.set(key, {
|
|
51
|
-
value,
|
|
52
|
-
expiresAt: Date.now() + ttl * 1e3
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
async delete(key) {
|
|
56
|
-
cache.delete(key);
|
|
57
|
-
},
|
|
58
|
-
async clear(pattern) {
|
|
59
|
-
if (!pattern) {
|
|
60
|
-
cache.clear();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
64
|
-
const regex = new RegExp(`^${escaped}$`);
|
|
65
|
-
for (const key of cache.keys()) if (regex.test(key)) cache.delete(key);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
//#endregion
|
|
70
4
|
//#region src/utils/mongooseToJsonSchema.ts
|
|
71
5
|
/**
|
|
72
6
|
* Mongoose → JSON Schema converter.
|
|
@@ -624,4 +558,4 @@ function buildJsonSchemaForQuery(_tree, options) {
|
|
|
624
558
|
return basePagination;
|
|
625
559
|
}
|
|
626
560
|
//#endregion
|
|
627
|
-
export { buildCrudSchemasFromMongooseSchema as n,
|
|
561
|
+
export { buildCrudSchemasFromMongooseSchema as n, buildCrudSchemasFromModel as t };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { C as FieldPreset, gt as UserContext } from "./types-
|
|
1
|
+
import { C as FieldPreset, gt as UserContext } from "./types-DNFMofHy.mjs";
|
|
2
2
|
import mongoose, { Schema } from "mongoose";
|
|
3
3
|
import { CacheAdapter } from "@classytic/repo-core/cache";
|
|
4
4
|
import { CrudSchemas, SchemaBuilderOptions } from "@classytic/repo-core/schema";
|
|
5
5
|
import { HttpError } from "@classytic/repo-core/errors";
|
|
6
|
-
|
|
7
6
|
//#region src/utils/error.d.ts
|
|
8
7
|
/** Optional structured fields for createError. */
|
|
9
8
|
interface CreateErrorOptions {
|
|
@@ -170,9 +169,10 @@ interface SchemaLike {
|
|
|
170
169
|
}>;
|
|
171
170
|
}
|
|
172
171
|
/**
|
|
173
|
-
* Detect
|
|
172
|
+
* Detect an id path's type from a Mongoose schema. Defaults to the `_id`
|
|
173
|
+
* path; pass `field` to resolve a custom id field (Repository's `idField`).
|
|
174
174
|
*
|
|
175
|
-
*
|
|
175
|
+
* For `_id`, returns 'objectid' as the safe default when:
|
|
176
176
|
* - No schema is provided (mock models, test harnesses)
|
|
177
177
|
* - The schema has no `paths._id` (auto-generated ObjectId)
|
|
178
178
|
* - The instance string is unrecognized
|
|
@@ -180,8 +180,12 @@ interface SchemaLike {
|
|
|
180
180
|
* This safe-default means existing callers that don't set _id explicitly
|
|
181
181
|
* get the same ObjectId validation they always had — the behavioral change
|
|
182
182
|
* is strictly opt-in via schema declaration.
|
|
183
|
+
*
|
|
184
|
+
* For a custom `field` with no resolvable path, returns 'unknown' instead —
|
|
185
|
+
* custom id fields carry no ObjectId convention, so validation stays
|
|
186
|
+
* permissive and the DB remains the authority.
|
|
183
187
|
*/
|
|
184
|
-
declare function getSchemaIdType(schema?: SchemaLike | null): IdType;
|
|
188
|
+
declare function getSchemaIdType(schema?: SchemaLike | null, field?: string): IdType;
|
|
185
189
|
/**
|
|
186
190
|
* Validate an id value against a known _id type — WITHOUT hitting the DB.
|
|
187
191
|
*
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { B as ObjectId, G as Plugin, Q as RepositoryContext } from "./types-
|
|
1
|
+
import { B as ObjectId, G as Plugin, Q as RepositoryContext } from "./types-DNFMofHy.mjs";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
3
|
import { CacheAdapter as CacheAdapter$1, CacheOptions, RepositoryCacheHandle, RepositoryCachePluginOptions, cachePlugin } from "@classytic/repo-core/cache";
|
|
4
4
|
import { TenantConfig } from "@classytic/repo-core/tenant";
|
|
5
|
-
|
|
6
5
|
//#region src/plugins/audit-trail.plugin.d.ts
|
|
7
6
|
interface AuditTrailOptions {
|
|
8
7
|
/** Operations to track (default: ['create', 'update', 'delete']) */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as PaginationEngine } from "../PaginationEngine-
|
|
1
|
+
import { t as PaginationEngine } from "../PaginationEngine-DYpOD2wY.mjs";
|
|
2
2
|
export { PaginationEngine };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as PaginationEngine } from "../PaginationEngine-
|
|
1
|
+
import { t as PaginationEngine } from "../PaginationEngine-BT1ywu9k.mjs";
|
|
2
2
|
export { PaginationEngine };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { G as Plugin } from "../types-
|
|
2
|
-
import { C as AuditTrailMethods, E as auditTrailPlugin, S as AuditQueryResult, T as AuditTrailQuery, _ as RepositoryCachePluginOptions, a as DateSequentialIdOptions, b as AuditOperation, c as SequentialIdOptions, d as getNextSequence, f as prefixedId, g as RepositoryCacheHandle, h as CacheOptions, i as CustomIdOptions, l as customIdPlugin, m as CacheAdapter, o as IdGenerator, p as sequentialId, r as multiTenantPlugin, s as PrefixedIdOptions, t as MultiTenantOptions, u as dateSequentialId, v as cachePlugin, w as AuditTrailOptions, x as AuditQueryOptions, y as AuditEntry } from "../multi-tenant.plugin-
|
|
3
|
-
import { C as LeasePluginOptions, D as elasticSearchPlugin, E as ElasticSearchOptions, M as auditLogPlugin, N as AggregateHelpersMethods, O as cascadePlugin, P as aggregateHelpersPlugin, S as LeaseMethods, T as fieldFilterPlugin, _ as observabilityPlugin, a as uniqueField, b as MethodRegistryRepository, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as batchOperationsPlugin, k as BatchOperationsMethods, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MongoOperationsMethods, w as leasePlugin, x as methodRegistryPlugin, y as mongoOperationsPlugin } from "../validation-chain.plugin-
|
|
1
|
+
import { G as Plugin } from "../types-DNFMofHy.mjs";
|
|
2
|
+
import { C as AuditTrailMethods, E as auditTrailPlugin, S as AuditQueryResult, T as AuditTrailQuery, _ as RepositoryCachePluginOptions, a as DateSequentialIdOptions, b as AuditOperation, c as SequentialIdOptions, d as getNextSequence, f as prefixedId, g as RepositoryCacheHandle, h as CacheOptions, i as CustomIdOptions, l as customIdPlugin, m as CacheAdapter, o as IdGenerator, p as sequentialId, r as multiTenantPlugin, s as PrefixedIdOptions, t as MultiTenantOptions, u as dateSequentialId, v as cachePlugin, w as AuditTrailOptions, x as AuditQueryOptions, y as AuditEntry } from "../multi-tenant.plugin-CTsWz0XK.mjs";
|
|
3
|
+
import { C as LeasePluginOptions, D as elasticSearchPlugin, E as ElasticSearchOptions, M as auditLogPlugin, N as AggregateHelpersMethods, O as cascadePlugin, P as aggregateHelpersPlugin, S as LeaseMethods, T as fieldFilterPlugin, _ as observabilityPlugin, a as uniqueField, b as MethodRegistryRepository, c as TenantContext, d as SubdocumentMethods, f as subdocumentPlugin, g as OperationMetric, h as ObservabilityOptions, i as requireField, j as batchOperationsPlugin, k as BatchOperationsMethods, l as TenantStore, m as softDeletePlugin, n as blockIf, o as validationChainPlugin, p as SoftDeleteMethods, r as immutableField, s as timestampPlugin, t as autoInject, u as createTenantContext, v as MongoOperationsMethods, w as leasePlugin, x as methodRegistryPlugin, y as mongoOperationsPlugin } from "../validation-chain.plugin-buy3uvyk.mjs";
|
|
4
4
|
import { ChangeLogStore } from "@classytic/repo-core/sync";
|
|
5
|
-
|
|
6
5
|
//#region src/plugins/change-log.plugin.d.ts
|
|
7
6
|
interface ChangeLogPluginOptions {
|
|
8
7
|
/** Durable feed implementing the repo-core/sync contract. */
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as methodRegistryPlugin, c as getNextSequence, d as cachePlugin, f as batchOperationsPlugin, h as auditLogPlugin, i as multiTenantPlugin, l as prefixedId, m as auditTrailPlugin, n as softDeletePlugin, o as customIdPlugin, p as AuditTrailQuery, s as dateSequentialId, t as timestampPlugin, u as sequentialId } from "../timestamp.plugin-
|
|
2
|
-
import { a as uniqueField, c as subdocumentPlugin, d as leasePlugin, f as fieldFilterPlugin, h as aggregateHelpersPlugin, i as requireField, l as observabilityPlugin, m as cascadePlugin, n as blockIf, o as validationChainPlugin, p as elasticSearchPlugin, r as immutableField, s as createTenantContext, t as autoInject, u as mongoOperationsPlugin } from "../validation-chain.plugin-
|
|
1
|
+
import { a as methodRegistryPlugin, c as getNextSequence, d as cachePlugin, f as batchOperationsPlugin, h as auditLogPlugin, i as multiTenantPlugin, l as prefixedId, m as auditTrailPlugin, n as softDeletePlugin, o as customIdPlugin, p as AuditTrailQuery, s as dateSequentialId, t as timestampPlugin, u as sequentialId } from "../timestamp.plugin-nG9Z1JEk.mjs";
|
|
2
|
+
import { a as uniqueField, c as subdocumentPlugin, d as leasePlugin, f as fieldFilterPlugin, h as aggregateHelpersPlugin, i as requireField, l as observabilityPlugin, m as cascadePlugin, n as blockIf, o as validationChainPlugin, p as elasticSearchPlugin, r as immutableField, s as createTenantContext, t as autoInject, u as mongoOperationsPlugin } from "../validation-chain.plugin-Dn_wZYLA.mjs";
|
|
3
3
|
//#region src/plugins/change-log.plugin.ts
|
|
4
4
|
const PLUGIN_NAME = "changeLog";
|
|
5
5
|
function isSkipped(context) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as coerceHeuristic, i as coerceFieldValue, n as SchemaPathsLike, o as coerceToType, r as buildFieldTypeMap, s as normalizeMongooseType, t as FieldType } from "../../coercion-
|
|
1
|
+
import { a as coerceHeuristic, i as coerceFieldValue, n as SchemaPathsLike, o as coerceToType, r as buildFieldTypeMap, s as normalizeMongooseType, t as FieldType } from "../../coercion-BjdPX3YF.mjs";
|
|
2
2
|
export { FieldType, SchemaPathsLike, buildFieldTypeMap, coerceFieldValue, coerceHeuristic, coerceToType, normalizeMongooseType };
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* `[nearSphere]`, or `[geoWithin]` operator on a field.
|
|
15
15
|
*/
|
|
16
16
|
/** Geo operators recognized by the parser */
|
|
17
|
-
declare const GEO_OPERATORS: readonly [
|
|
17
|
+
declare const GEO_OPERATORS: readonly ['near', 'nearSphere', 'geoWithin', 'withinRadius'];
|
|
18
18
|
type GeoOperator = (typeof GEO_OPERATORS)[number];
|
|
19
19
|
/**
|
|
20
20
|
* True iff `operator` is one of the geo operators we handle.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SchemaIndexes, r as extractSchemaIndexes, t as IndexableSchema } from "../../indexes-
|
|
1
|
+
import { n as SchemaIndexes, r as extractSchemaIndexes, t as IndexableSchema } from "../../indexes-DIjMpYES.mjs";
|
|
2
2
|
export { IndexableSchema, SchemaIndexes, extractSchemaIndexes };
|