@classytic/mongokit 3.6.4 → 3.8.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-CunXkR9p.mjs → PaginationEngine-C2_tAvAD.mjs} +8 -5
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.mjs +1 -1
- package/dist/ai/index.d.mts +23 -1
- package/dist/ai/index.mjs +194 -12
- package/dist/{cursor-CHToazHy.mjs → cursor-J84rR6wG.mjs} +11 -7
- package/dist/error-Lw9GEAro.mjs +46 -0
- package/dist/{index-jzO5hMtF.d.mts → index-DlSAFIc9.d.mts} +10 -2
- package/dist/index.d.mts +97 -9
- package/dist/index.mjs +53 -12
- package/dist/logger-DJ7egMnd.mjs +30 -0
- package/dist/{mongooseToJsonSchema-BvD1NDl9.d.mts → mongooseToJsonSchema-BZaKOXXI.d.mts} +18 -2
- package/dist/{mongooseToJsonSchema-BlfkI9LC.mjs → mongooseToJsonSchema-DUwXPStK.mjs} +1 -1
- package/dist/pagination/PaginationEngine.d.mts +3 -1
- package/dist/pagination/PaginationEngine.mjs +1 -1
- package/dist/plugins/index.d.mts +2 -2
- 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/indexes.d.mts +1 -1
- package/dist/{sort-C-BJEWUZ.mjs → sort-CrZjTK25.mjs} +19 -4
- package/dist/{types-BoH1qdHo.d.mts → types-D57SZJeE.d.mts} +83 -3
- package/dist/{update-AVfKWNGt.mjs → update-yjSoNnWy.mjs} +26 -2
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +5 -4
- package/dist/{validation-chain.plugin-7A5qGEQq.mjs → validation-chain.plugin-DwoOOWse.mjs} +460 -144
- package/dist/{validation-chain.plugin-BXx6Ogpp.d.mts → validation-chain.plugin-wGF34Ym-.d.mts} +27 -4
- package/package.json +8 -3
- package/dist/error-Bpbi_NKo.mjs +0 -63
- /package/dist/{coercion-B19MD38s.d.mts → coercion-oM8G4b6m.d.mts} +0 -0
- /package/dist/{field-selection-C5o7jyyA.mjs → field-selection-dI0m4RBs.mjs} +0 -0
- /package/dist/{id-resolution-LZ-cCwR5.mjs → id-resolution-e4BT9zAV.mjs} +0 -0
- /package/dist/{indexes-qIBCZ3mY.d.mts → indexes-C26GNZRU.d.mts} +0 -0
package/dist/{validation-chain.plugin-BXx6Ogpp.d.mts → validation-chain.plugin-wGF34Ym-.d.mts}
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ct as ValidatorDefinition, H as ObjectId, L as Logger, Q as PopulateSpec, T as FieldPreset, W as OffsetPaginationResult, Y as Plugin, ct as SelectSpec, dt as SoftDeleteOptions, f as CascadeOptions, l as CacheOptions, mt as SortSpec, rt as RepositoryInstance, tt as RepositoryContext, u as CacheStats, xt as ValidationChainOptions } from "./types-D57SZJeE.mjs";
|
|
2
2
|
import mongoose, { ClientSession } from "mongoose";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
4
|
|
|
4
5
|
//#region src/plugins/aggregate-helpers.plugin.d.ts
|
|
5
6
|
/**
|
|
@@ -118,7 +119,7 @@ interface AuditTrailOptions {
|
|
|
118
119
|
*/
|
|
119
120
|
excludeFields?: string[];
|
|
120
121
|
}
|
|
121
|
-
type AuditOperation = 'create' | 'update' | 'delete';
|
|
122
|
+
type AuditOperation = 'create' | 'update' | 'delete' | 'findOneAndUpdate';
|
|
122
123
|
interface AuditEntry {
|
|
123
124
|
model: string;
|
|
124
125
|
operation: AuditOperation;
|
|
@@ -1062,6 +1063,28 @@ interface SubdocumentMethods<TDoc> {
|
|
|
1062
1063
|
deleteSubdocument(parentId: string | ObjectId, arrayPath: string, subId: string | ObjectId, options?: Record<string, unknown>): Promise<TDoc>;
|
|
1063
1064
|
}
|
|
1064
1065
|
//#endregion
|
|
1066
|
+
//#region src/plugins/tenant-context.d.ts
|
|
1067
|
+
interface TenantStore {
|
|
1068
|
+
tenantId: string | undefined;
|
|
1069
|
+
[key: string]: unknown;
|
|
1070
|
+
}
|
|
1071
|
+
interface TenantContext {
|
|
1072
|
+
/** Run `fn` with the given tenant store active for its entire async tree. */
|
|
1073
|
+
run<T>(store: TenantStore, fn: () => T): T;
|
|
1074
|
+
/** Current tenant ID, or undefined if no context is active. */
|
|
1075
|
+
getTenantId(): string | undefined;
|
|
1076
|
+
/** Full store for the current context (use for extra per-request metadata). */
|
|
1077
|
+
getStore(): TenantStore | undefined;
|
|
1078
|
+
/**
|
|
1079
|
+
* Assert that a tenant context is active; throw otherwise.
|
|
1080
|
+
* Useful in hot paths where a missing tenant must fail loud, not silent.
|
|
1081
|
+
*/
|
|
1082
|
+
requireTenantId(): string;
|
|
1083
|
+
/** Underlying AsyncLocalStorage — escape hatch for advanced composition. */
|
|
1084
|
+
readonly storage: AsyncLocalStorage<TenantStore>;
|
|
1085
|
+
}
|
|
1086
|
+
declare function createTenantContext(): TenantContext;
|
|
1087
|
+
//#endregion
|
|
1065
1088
|
//#region src/plugins/timestamp.plugin.d.ts
|
|
1066
1089
|
/**
|
|
1067
1090
|
* Timestamp plugin that auto-injects timestamps
|
|
@@ -1072,7 +1095,7 @@ interface SubdocumentMethods<TDoc> {
|
|
|
1072
1095
|
declare function timestampPlugin(): Plugin;
|
|
1073
1096
|
//#endregion
|
|
1074
1097
|
//#region src/plugins/validation-chain.plugin.d.ts
|
|
1075
|
-
type OperationType = 'create' | 'createMany' | 'update' | 'delete';
|
|
1098
|
+
type OperationType = 'create' | 'createMany' | 'update' | 'findOneAndUpdate' | 'delete';
|
|
1076
1099
|
/**
|
|
1077
1100
|
* Validation chain plugin
|
|
1078
1101
|
*
|
|
@@ -1110,4 +1133,4 @@ declare function immutableField(field: string): ValidatorDefinition;
|
|
|
1110
1133
|
*/
|
|
1111
1134
|
declare function uniqueField(field: string, errorMessage?: string): ValidatorDefinition;
|
|
1112
1135
|
//#endregion
|
|
1113
|
-
export {
|
|
1136
|
+
export { aggregateHelpersPlugin as $, PrefixedIdOptions as A, BatchOperationsMethods as B, methodRegistryPlugin as C, CustomIdOptions as D, elasticSearchPlugin as E, prefixedId as F, AuditQueryOptions as G, batchOperationsPlugin as H, sequentialId as I, AuditTrailOptions as J, AuditQueryResult as K, cascadePlugin as L, customIdPlugin as M, dateSequentialId as N, DateSequentialIdOptions as O, getNextSequence as P, AggregateHelpersMethods as Q, CacheMethods as R, MethodRegistryRepository as S, ElasticSearchOptions as T, AuditEntry as U, BulkWriteResult as V, AuditOperation as W, auditTrailPlugin as X, AuditTrailQuery as Y, auditLogPlugin as Z, observabilityPlugin as _, uniqueField as a, MongoOperationsMethods as b, TenantContext as c, SubdocumentMethods as d, subdocumentPlugin as f, OperationMetric as g, ObservabilityOptions as h, requireField as i, SequentialIdOptions as j, IdGenerator as k, TenantStore as l, softDeletePlugin as m, blockIf as n, validationChainPlugin as o, SoftDeleteMethods as p, AuditTrailMethods as q, immutableField as r, timestampPlugin as s, autoInject as t, createTenantContext as u, MultiTenantOptions as v, fieldFilterPlugin as w, mongoOperationsPlugin as x, multiTenantPlugin as y, cachePlugin as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/mongokit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Production-grade MongoDB repositories with zero dependencies - smart pagination, events, and plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -101,8 +101,12 @@
|
|
|
101
101
|
"scripts": {
|
|
102
102
|
"build": "tsdown",
|
|
103
103
|
"dev": "tsdown --watch",
|
|
104
|
-
"test": "vitest run",
|
|
105
|
-
"test:
|
|
104
|
+
"test": "vitest run --project unit --project integration",
|
|
105
|
+
"test:unit": "vitest run --project unit",
|
|
106
|
+
"test:integration": "vitest run --project integration",
|
|
107
|
+
"test:e2e": "vitest run --project e2e",
|
|
108
|
+
"test:all": "vitest run --project unit --project integration --project e2e",
|
|
109
|
+
"test:watch": "vitest --project unit --project integration",
|
|
106
110
|
"test:coverage": "vitest run --coverage",
|
|
107
111
|
"typecheck": "tsc --noEmit",
|
|
108
112
|
"lint": "biome check src/",
|
|
@@ -124,6 +128,7 @@
|
|
|
124
128
|
"@vitest/coverage-v8": "^3.2.4",
|
|
125
129
|
"ajv": "^8.18.0",
|
|
126
130
|
"ajv-formats": "^3.0.1",
|
|
131
|
+
"dotenv": "^17.4.2",
|
|
127
132
|
"knip": "^6.3.0",
|
|
128
133
|
"mongodb-memory-server": "^10.4.3",
|
|
129
134
|
"mongoose": "^9.4.1",
|
package/dist/error-Bpbi_NKo.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
//#region src/utils/logger.ts
|
|
2
|
-
const noop = () => {};
|
|
3
|
-
let current = {
|
|
4
|
-
warn: console.warn.bind(console),
|
|
5
|
-
debug: noop
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Configure the internal logger.
|
|
9
|
-
* Pass `false` to silence all output.
|
|
10
|
-
*/
|
|
11
|
-
function configureLogger(config) {
|
|
12
|
-
if (config === false) current = {
|
|
13
|
-
warn: noop,
|
|
14
|
-
debug: noop
|
|
15
|
-
};
|
|
16
|
-
else current = {
|
|
17
|
-
...current,
|
|
18
|
-
...config
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/** Emit a warning — security blocks, config issues, performance hints */
|
|
22
|
-
function warn(message, ...args) {
|
|
23
|
-
current.warn(message, ...args);
|
|
24
|
-
}
|
|
25
|
-
/** Emit debug info — only visible when debug is enabled */
|
|
26
|
-
function debug(message, ...args) {
|
|
27
|
-
current.debug(message, ...args);
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/utils/error.ts
|
|
31
|
-
/**
|
|
32
|
-
* Creates an error with HTTP status code
|
|
33
|
-
*
|
|
34
|
-
* @param status - HTTP status code
|
|
35
|
-
* @param message - Error message
|
|
36
|
-
* @returns Error with status property
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* throw createError(404, 'Document not found');
|
|
40
|
-
* throw createError(400, 'Invalid input');
|
|
41
|
-
* throw createError(403, 'Access denied');
|
|
42
|
-
*/
|
|
43
|
-
function createError(status, message) {
|
|
44
|
-
const error = new Error(message);
|
|
45
|
-
error.status = status;
|
|
46
|
-
return error;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Detect and convert a MongoDB E11000 duplicate-key error into
|
|
50
|
-
* a 409 HttpError with an actionable message.
|
|
51
|
-
*
|
|
52
|
-
* Returns `null` when the error is not a duplicate-key error.
|
|
53
|
-
*/
|
|
54
|
-
function parseDuplicateKeyError(error) {
|
|
55
|
-
if (!error || typeof error !== "object") return null;
|
|
56
|
-
const mongoErr = error;
|
|
57
|
-
if (mongoErr.code !== 11e3) return null;
|
|
58
|
-
const fields = mongoErr.keyPattern ? Object.keys(mongoErr.keyPattern) : [];
|
|
59
|
-
const values = mongoErr.keyValue ? Object.entries(mongoErr.keyValue).map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join(", ") : "";
|
|
60
|
-
return createError(409, fields.length ? `Duplicate value for ${fields.join(", ")}${values ? ` (${values})` : ""}` : "Duplicate key error");
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { warn as a, debug as i, parseDuplicateKeyError as n, configureLogger as r, createError as t };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|