@classytic/mongokit 3.0.4 → 3.0.5
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.ts +2 -2
- package/dist/{index-wXrOSYWG.d.ts → index-BljuCDFC.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +249 -11
- package/dist/pagination/PaginationEngine.d.ts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/{queryParser-Bek4yy3x.d.ts → queryParser-CxzCjzXd.d.ts} +55 -2
- package/dist/{types-DAl69QgM.d.ts → types-CHIDluaP.d.ts} +6 -20
- package/dist/utils/index.d.ts +4 -56
- package/dist/utils/index.js +1 -8
- package/package.json +1 -1
package/dist/actions/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { a as aggregate, c as create, _ as deleteActions, r as read, u as update } from '../index-
|
|
1
|
+
export { a as aggregate, c as create, _ as deleteActions, r as read, u as update } from '../index-BljuCDFC.js';
|
|
2
2
|
import 'mongoose';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-CHIDluaP.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Model, ClientSession, PipelineStage } from 'mongoose';
|
|
2
|
-
import { A as AnyDocument, C as CreateOptions,
|
|
2
|
+
import { A as AnyDocument, C as CreateOptions, h as ObjectId, n as OperationOptions, S as SelectSpec, e as PopulateSpec, f as SortSpec, U as UpdateOptions, p as UpdateWithValidationResult, o as UpdateManyResult, D as DeleteResult, W as GroupResult, T as LookupOptions, X as MinMaxResult } from './types-CHIDluaP.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Create Actions
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { A as AnyDocument,
|
|
2
|
-
export { c as AggregatePaginationOptions, j as AnyModel, Y as CacheAdapter, _ as CacheOperationOptions, Z as CacheOptions, $ as CacheStats, a1 as CascadeOptions, a0 as CascadeRelation, C as CreateOptions, z as CrudSchemas, B as DecodedCursor, D as DeleteResult, E as EventPayload, F as FieldPreset, x as FieldRules, w as FilterQuery, W as GroupResult, l as HookMode, J as JsonSchema, K as KeysetPaginationOptions, L as Logger, T as LookupOptions, X as MinMaxResult, O as OffsetPaginationOptions, n as OperationOptions, m as PaginationResult, v as ParsedQuery, r as Plugin, s as PluginFunction, u as RepositoryEvent, t as RepositoryInstance, y as SchemaBuilderOptions, N as SoftDeleteFilterMode, M as SoftDeleteOptions, Q as SoftDeleteRepository, k as SortDirection, o as UpdateManyResult, p as UpdateWithValidationResult, q as UserContext, I as ValidationChainOptions, V as ValidationResult, G as ValidatorDefinition } from './types-
|
|
1
|
+
import { A as AnyDocument, g as PluginType, P as PaginationConfig, R as RepositoryOptions, h as ObjectId, S as SelectSpec, e as PopulateSpec, f as SortSpec, a as OffsetPaginationResult, b as KeysetPaginationResult, U as UpdateOptions, d as AggregatePaginationResult, i as RepositoryContext, H as HttpError } from './types-CHIDluaP.js';
|
|
2
|
+
export { c as AggregatePaginationOptions, j as AnyModel, Y as CacheAdapter, _ as CacheOperationOptions, Z as CacheOptions, $ as CacheStats, a1 as CascadeOptions, a0 as CascadeRelation, C as CreateOptions, z as CrudSchemas, B as DecodedCursor, D as DeleteResult, E as EventPayload, F as FieldPreset, x as FieldRules, w as FilterQuery, W as GroupResult, l as HookMode, J as JsonSchema, K as KeysetPaginationOptions, L as Logger, T as LookupOptions, X as MinMaxResult, O as OffsetPaginationOptions, n as OperationOptions, m as PaginationResult, v as ParsedQuery, r as Plugin, s as PluginFunction, u as RepositoryEvent, t as RepositoryInstance, y as SchemaBuilderOptions, N as SoftDeleteFilterMode, M as SoftDeleteOptions, Q as SoftDeleteRepository, k as SortDirection, o as UpdateManyResult, p as UpdateWithValidationResult, q as UserContext, I as ValidationChainOptions, V as ValidationResult, G as ValidatorDefinition } from './types-CHIDluaP.js';
|
|
3
3
|
import * as mongoose from 'mongoose';
|
|
4
4
|
import { Model, ClientSession, PipelineStage, PopulateOptions } from 'mongoose';
|
|
5
5
|
import { PaginationEngine } from './pagination/PaginationEngine.js';
|
|
6
6
|
export { aggregateHelpersPlugin, auditLogPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, fieldFilterPlugin, immutableField, methodRegistryPlugin, mongoOperationsPlugin, requireField, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin } from './plugins/index.js';
|
|
7
|
-
export { F as FilterValue, O as OperatorMap, Q as QueryParser,
|
|
8
|
-
export { i as actions } from './index-
|
|
7
|
+
export { F as FilterValue, O as OperatorMap, Q as QueryParser, b as QueryParserOptions, h as buildCrudSchemasFromModel, e as buildCrudSchemasFromMongooseSchema, l as createError, c as createFieldPreset, m as createMemoryCache, f as filterResponseData, g as getFieldsForUser, i as getImmutableFields, a as getMongooseProjection, j as getSystemManagedFields, k as isFieldUpdateAllowed, d as queryParser, v as validateUpdateBody } from './queryParser-CxzCjzXd.js';
|
|
8
|
+
export { i as actions } from './index-BljuCDFC.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Repository Pattern - Data Access Layer
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import mongoose4 from 'mongoose';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __export = (target, all) => {
|
|
@@ -521,12 +521,12 @@ function validateCursorVersion(cursorVersion, expectedVersion) {
|
|
|
521
521
|
}
|
|
522
522
|
function serializeValue(value) {
|
|
523
523
|
if (value instanceof Date) return value.toISOString();
|
|
524
|
-
if (value instanceof
|
|
524
|
+
if (value instanceof mongoose4.Types.ObjectId) return value.toString();
|
|
525
525
|
return value;
|
|
526
526
|
}
|
|
527
527
|
function getValueType(value) {
|
|
528
528
|
if (value instanceof Date) return "date";
|
|
529
|
-
if (value instanceof
|
|
529
|
+
if (value instanceof mongoose4.Types.ObjectId) return "objectid";
|
|
530
530
|
if (typeof value === "boolean") return "boolean";
|
|
531
531
|
if (typeof value === "number") return "number";
|
|
532
532
|
if (typeof value === "string") return "string";
|
|
@@ -537,7 +537,7 @@ function rehydrateValue(serialized, type) {
|
|
|
537
537
|
case "date":
|
|
538
538
|
return new Date(serialized);
|
|
539
539
|
case "objectid":
|
|
540
|
-
return new
|
|
540
|
+
return new mongoose4.Types.ObjectId(serialized);
|
|
541
541
|
case "boolean":
|
|
542
542
|
return Boolean(serialized);
|
|
543
543
|
case "number":
|
|
@@ -1109,7 +1109,7 @@ var Repository = class {
|
|
|
1109
1109
|
* Execute callback within a transaction
|
|
1110
1110
|
*/
|
|
1111
1111
|
async withTransaction(callback) {
|
|
1112
|
-
const session = await
|
|
1112
|
+
const session = await mongoose4.startSession();
|
|
1113
1113
|
session.startTransaction();
|
|
1114
1114
|
try {
|
|
1115
1115
|
const result = await callback(session);
|
|
@@ -1172,11 +1172,11 @@ var Repository = class {
|
|
|
1172
1172
|
* Handle errors with proper HTTP status codes
|
|
1173
1173
|
*/
|
|
1174
1174
|
_handleError(error) {
|
|
1175
|
-
if (error instanceof
|
|
1175
|
+
if (error instanceof mongoose4.Error.ValidationError) {
|
|
1176
1176
|
const messages = Object.values(error.errors).map((err) => err.message);
|
|
1177
1177
|
return createError(400, `Validation Error: ${messages.join(", ")}`);
|
|
1178
1178
|
}
|
|
1179
|
-
if (error instanceof
|
|
1179
|
+
if (error instanceof mongoose4.Error.CastError) {
|
|
1180
1180
|
return createError(400, `Invalid ${error.path}: ${error.value}`);
|
|
1181
1181
|
}
|
|
1182
1182
|
if (error.status && error.message) return error;
|
|
@@ -2207,7 +2207,7 @@ function cascadePlugin(options) {
|
|
|
2207
2207
|
}
|
|
2208
2208
|
const isSoftDelete = context.softDeleted === true;
|
|
2209
2209
|
const cascadeDelete = async (relation) => {
|
|
2210
|
-
const RelatedModel =
|
|
2210
|
+
const RelatedModel = mongoose4.models[relation.model];
|
|
2211
2211
|
if (!RelatedModel) {
|
|
2212
2212
|
logger?.warn?.(`Cascade delete skipped: model '${relation.model}' not found`, {
|
|
2213
2213
|
parentModel: context.model,
|
|
@@ -2298,7 +2298,7 @@ function cascadePlugin(options) {
|
|
|
2298
2298
|
}
|
|
2299
2299
|
const isSoftDelete = context.softDeleted === true;
|
|
2300
2300
|
const cascadeDeleteMany = async (relation) => {
|
|
2301
|
-
const RelatedModel =
|
|
2301
|
+
const RelatedModel = mongoose4.models[relation.model];
|
|
2302
2302
|
if (!RelatedModel) {
|
|
2303
2303
|
logger?.warn?.(`Cascade deleteMany skipped: model '${relation.model}' not found`, {
|
|
2304
2304
|
parentModel: context.model
|
|
@@ -2414,6 +2414,244 @@ function createMemoryCache(maxEntries = 1e3) {
|
|
|
2414
2414
|
}
|
|
2415
2415
|
};
|
|
2416
2416
|
}
|
|
2417
|
+
function isMongooseSchema(value) {
|
|
2418
|
+
return value instanceof mongoose4.Schema;
|
|
2419
|
+
}
|
|
2420
|
+
function isPlainObject(value) {
|
|
2421
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
2422
|
+
}
|
|
2423
|
+
function isObjectIdType(t) {
|
|
2424
|
+
return t === mongoose4.Schema.Types.ObjectId || t === mongoose4.Types.ObjectId;
|
|
2425
|
+
}
|
|
2426
|
+
function buildCrudSchemasFromMongooseSchema(mongooseSchema, options = {}) {
|
|
2427
|
+
const tree = mongooseSchema?.obj || {};
|
|
2428
|
+
const jsonCreate = buildJsonSchemaForCreate(tree, options);
|
|
2429
|
+
const jsonUpdate = buildJsonSchemaForUpdate(jsonCreate, options);
|
|
2430
|
+
const jsonParams = {
|
|
2431
|
+
type: "object",
|
|
2432
|
+
properties: { id: { type: "string", pattern: "^[0-9a-fA-F]{24}$" } },
|
|
2433
|
+
required: ["id"]
|
|
2434
|
+
};
|
|
2435
|
+
const jsonQuery = buildJsonSchemaForQuery(tree, options);
|
|
2436
|
+
return { createBody: jsonCreate, updateBody: jsonUpdate, params: jsonParams, listQuery: jsonQuery };
|
|
2437
|
+
}
|
|
2438
|
+
function buildCrudSchemasFromModel(mongooseModel, options = {}) {
|
|
2439
|
+
if (!mongooseModel || !mongooseModel.schema) {
|
|
2440
|
+
throw new Error("Invalid mongoose model");
|
|
2441
|
+
}
|
|
2442
|
+
return buildCrudSchemasFromMongooseSchema(mongooseModel.schema, options);
|
|
2443
|
+
}
|
|
2444
|
+
function getImmutableFields(options = {}) {
|
|
2445
|
+
const immutable = [];
|
|
2446
|
+
const fieldRules = options?.fieldRules || {};
|
|
2447
|
+
Object.entries(fieldRules).forEach(([field, rules]) => {
|
|
2448
|
+
if (rules.immutable || rules.immutableAfterCreate) {
|
|
2449
|
+
immutable.push(field);
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2452
|
+
(options?.update?.omitFields || []).forEach((f) => {
|
|
2453
|
+
if (!immutable.includes(f)) immutable.push(f);
|
|
2454
|
+
});
|
|
2455
|
+
return immutable;
|
|
2456
|
+
}
|
|
2457
|
+
function getSystemManagedFields(options = {}) {
|
|
2458
|
+
const systemManaged = [];
|
|
2459
|
+
const fieldRules = options?.fieldRules || {};
|
|
2460
|
+
Object.entries(fieldRules).forEach(([field, rules]) => {
|
|
2461
|
+
if (rules.systemManaged) {
|
|
2462
|
+
systemManaged.push(field);
|
|
2463
|
+
}
|
|
2464
|
+
});
|
|
2465
|
+
return systemManaged;
|
|
2466
|
+
}
|
|
2467
|
+
function isFieldUpdateAllowed(fieldName, options = {}) {
|
|
2468
|
+
const immutableFields = getImmutableFields(options);
|
|
2469
|
+
const systemManagedFields = getSystemManagedFields(options);
|
|
2470
|
+
return !immutableFields.includes(fieldName) && !systemManagedFields.includes(fieldName);
|
|
2471
|
+
}
|
|
2472
|
+
function validateUpdateBody(body = {}, options = {}) {
|
|
2473
|
+
const violations = [];
|
|
2474
|
+
const immutableFields = getImmutableFields(options);
|
|
2475
|
+
const systemManagedFields = getSystemManagedFields(options);
|
|
2476
|
+
Object.keys(body).forEach((field) => {
|
|
2477
|
+
if (immutableFields.includes(field)) {
|
|
2478
|
+
violations.push({ field, reason: "Field is immutable" });
|
|
2479
|
+
} else if (systemManagedFields.includes(field)) {
|
|
2480
|
+
violations.push({ field, reason: "Field is system-managed" });
|
|
2481
|
+
}
|
|
2482
|
+
});
|
|
2483
|
+
return {
|
|
2484
|
+
valid: violations.length === 0,
|
|
2485
|
+
violations
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
function jsonTypeFor(def, options, seen) {
|
|
2489
|
+
if (Array.isArray(def)) {
|
|
2490
|
+
if (def[0] === mongoose4.Schema.Types.Mixed) {
|
|
2491
|
+
return { type: "array", items: { type: "object", additionalProperties: true } };
|
|
2492
|
+
}
|
|
2493
|
+
return { type: "array", items: jsonTypeFor(def[0] ?? String, options, seen) };
|
|
2494
|
+
}
|
|
2495
|
+
if (isPlainObject(def) && "type" in def) {
|
|
2496
|
+
const typedDef = def;
|
|
2497
|
+
if (typedDef.enum && Array.isArray(typedDef.enum) && typedDef.enum.length) {
|
|
2498
|
+
return { type: "string", enum: typedDef.enum.map(String) };
|
|
2499
|
+
}
|
|
2500
|
+
if (Array.isArray(typedDef.type)) {
|
|
2501
|
+
const inner = typedDef.type[0] !== void 0 ? typedDef.type[0] : String;
|
|
2502
|
+
if (inner === mongoose4.Schema.Types.Mixed) {
|
|
2503
|
+
return { type: "array", items: { type: "object", additionalProperties: true } };
|
|
2504
|
+
}
|
|
2505
|
+
return { type: "array", items: jsonTypeFor(inner, options, seen) };
|
|
2506
|
+
}
|
|
2507
|
+
if (typedDef.type === String) return { type: "string" };
|
|
2508
|
+
if (typedDef.type === Number) return { type: "number" };
|
|
2509
|
+
if (typedDef.type === Boolean) return { type: "boolean" };
|
|
2510
|
+
if (typedDef.type === Date) {
|
|
2511
|
+
const mode = options?.dateAs || "datetime";
|
|
2512
|
+
return mode === "date" ? { type: "string", format: "date" } : { type: "string", format: "date-time" };
|
|
2513
|
+
}
|
|
2514
|
+
if (typedDef.type === Map || typedDef.type === mongoose4.Schema.Types.Map) {
|
|
2515
|
+
const ofSchema = jsonTypeFor(typedDef.of || String, options, seen);
|
|
2516
|
+
return { type: "object", additionalProperties: ofSchema };
|
|
2517
|
+
}
|
|
2518
|
+
if (typedDef.type === mongoose4.Schema.Types.Mixed) {
|
|
2519
|
+
return { type: "object", additionalProperties: true };
|
|
2520
|
+
}
|
|
2521
|
+
if (isObjectIdType(typedDef.type)) {
|
|
2522
|
+
return { type: "string", pattern: "^[0-9a-fA-F]{24}$" };
|
|
2523
|
+
}
|
|
2524
|
+
if (isMongooseSchema(typedDef.type)) {
|
|
2525
|
+
const obj = typedDef.type.obj;
|
|
2526
|
+
if (obj && typeof obj === "object") {
|
|
2527
|
+
if (seen.has(obj)) return { type: "object", additionalProperties: true };
|
|
2528
|
+
seen.add(obj);
|
|
2529
|
+
return convertTreeToJsonSchema(obj, options, seen);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
if (def === String) return { type: "string" };
|
|
2534
|
+
if (def === Number) return { type: "number" };
|
|
2535
|
+
if (def === Boolean) return { type: "boolean" };
|
|
2536
|
+
if (def === Date) {
|
|
2537
|
+
const mode = options?.dateAs || "datetime";
|
|
2538
|
+
return mode === "date" ? { type: "string", format: "date" } : { type: "string", format: "date-time" };
|
|
2539
|
+
}
|
|
2540
|
+
if (isObjectIdType(def)) return { type: "string", pattern: "^[0-9a-fA-F]{24}$" };
|
|
2541
|
+
if (isPlainObject(def)) {
|
|
2542
|
+
if (seen.has(def)) return { type: "object", additionalProperties: true };
|
|
2543
|
+
seen.add(def);
|
|
2544
|
+
return convertTreeToJsonSchema(def, options, seen);
|
|
2545
|
+
}
|
|
2546
|
+
return {};
|
|
2547
|
+
}
|
|
2548
|
+
function convertTreeToJsonSchema(tree, options, seen = /* @__PURE__ */ new WeakSet()) {
|
|
2549
|
+
if (!tree || typeof tree !== "object") {
|
|
2550
|
+
return { type: "object", properties: {} };
|
|
2551
|
+
}
|
|
2552
|
+
if (seen.has(tree)) {
|
|
2553
|
+
return { type: "object", additionalProperties: true };
|
|
2554
|
+
}
|
|
2555
|
+
seen.add(tree);
|
|
2556
|
+
const properties = {};
|
|
2557
|
+
const required = [];
|
|
2558
|
+
for (const [key, val] of Object.entries(tree || {})) {
|
|
2559
|
+
if (key === "__v" || key === "_id" || key === "id") continue;
|
|
2560
|
+
const cfg = isPlainObject(val) && "type" in val ? val : { };
|
|
2561
|
+
properties[key] = jsonTypeFor(val, options, seen);
|
|
2562
|
+
if (cfg.required === true) required.push(key);
|
|
2563
|
+
}
|
|
2564
|
+
const schema = { type: "object", properties };
|
|
2565
|
+
if (required.length) schema.required = required;
|
|
2566
|
+
return schema;
|
|
2567
|
+
}
|
|
2568
|
+
function buildJsonSchemaForCreate(tree, options) {
|
|
2569
|
+
const base = convertTreeToJsonSchema(tree, options, /* @__PURE__ */ new WeakSet());
|
|
2570
|
+
const fieldsToOmit = /* @__PURE__ */ new Set(["createdAt", "updatedAt", "__v"]);
|
|
2571
|
+
(options?.create?.omitFields || []).forEach((f) => fieldsToOmit.add(f));
|
|
2572
|
+
const fieldRules = options?.fieldRules || {};
|
|
2573
|
+
Object.entries(fieldRules).forEach(([field, rules]) => {
|
|
2574
|
+
if (rules.systemManaged) {
|
|
2575
|
+
fieldsToOmit.add(field);
|
|
2576
|
+
}
|
|
2577
|
+
});
|
|
2578
|
+
fieldsToOmit.forEach((field) => {
|
|
2579
|
+
if (base.properties?.[field]) {
|
|
2580
|
+
delete base.properties[field];
|
|
2581
|
+
}
|
|
2582
|
+
if (base.required) {
|
|
2583
|
+
base.required = base.required.filter((k) => k !== field);
|
|
2584
|
+
}
|
|
2585
|
+
});
|
|
2586
|
+
const reqOv = options?.create?.requiredOverrides || {};
|
|
2587
|
+
const optOv = options?.create?.optionalOverrides || {};
|
|
2588
|
+
base.required = base.required || [];
|
|
2589
|
+
for (const [k, v] of Object.entries(reqOv)) {
|
|
2590
|
+
if (v && !base.required.includes(k)) base.required.push(k);
|
|
2591
|
+
}
|
|
2592
|
+
for (const [k, v] of Object.entries(optOv)) {
|
|
2593
|
+
if (v && base.required) base.required = base.required.filter((x) => x !== k);
|
|
2594
|
+
}
|
|
2595
|
+
Object.entries(fieldRules).forEach(([field, rules]) => {
|
|
2596
|
+
if (rules.optional && base.required) {
|
|
2597
|
+
base.required = base.required.filter((x) => x !== field);
|
|
2598
|
+
}
|
|
2599
|
+
});
|
|
2600
|
+
const schemaOverrides = options?.create?.schemaOverrides || {};
|
|
2601
|
+
for (const [k, override] of Object.entries(schemaOverrides)) {
|
|
2602
|
+
if (base.properties?.[k]) {
|
|
2603
|
+
base.properties[k] = override;
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
if (options?.strictAdditionalProperties === true) {
|
|
2607
|
+
base.additionalProperties = false;
|
|
2608
|
+
}
|
|
2609
|
+
return base;
|
|
2610
|
+
}
|
|
2611
|
+
function buildJsonSchemaForUpdate(createJson, options) {
|
|
2612
|
+
const clone = JSON.parse(JSON.stringify(createJson));
|
|
2613
|
+
delete clone.required;
|
|
2614
|
+
const fieldsToOmit = /* @__PURE__ */ new Set();
|
|
2615
|
+
(options?.update?.omitFields || []).forEach((f) => fieldsToOmit.add(f));
|
|
2616
|
+
const fieldRules = options?.fieldRules || {};
|
|
2617
|
+
Object.entries(fieldRules).forEach(([field, rules]) => {
|
|
2618
|
+
if (rules.immutable || rules.immutableAfterCreate) {
|
|
2619
|
+
fieldsToOmit.add(field);
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
fieldsToOmit.forEach((field) => {
|
|
2623
|
+
if (clone.properties?.[field]) {
|
|
2624
|
+
delete clone.properties[field];
|
|
2625
|
+
}
|
|
2626
|
+
});
|
|
2627
|
+
if (options?.strictAdditionalProperties === true) {
|
|
2628
|
+
clone.additionalProperties = false;
|
|
2629
|
+
}
|
|
2630
|
+
return clone;
|
|
2631
|
+
}
|
|
2632
|
+
function buildJsonSchemaForQuery(_tree, options) {
|
|
2633
|
+
const basePagination = {
|
|
2634
|
+
type: "object",
|
|
2635
|
+
properties: {
|
|
2636
|
+
page: { type: "string" },
|
|
2637
|
+
limit: { type: "string" },
|
|
2638
|
+
sort: { type: "string" },
|
|
2639
|
+
populate: { type: "string" },
|
|
2640
|
+
search: { type: "string" },
|
|
2641
|
+
select: { type: "string" },
|
|
2642
|
+
lean: { type: "string" },
|
|
2643
|
+
includeDeleted: { type: "string" }
|
|
2644
|
+
},
|
|
2645
|
+
additionalProperties: true
|
|
2646
|
+
};
|
|
2647
|
+
const filterable = options?.query?.filterableFields || {};
|
|
2648
|
+
for (const [k, v] of Object.entries(filterable)) {
|
|
2649
|
+
if (basePagination.properties) {
|
|
2650
|
+
basePagination.properties[k] = v && typeof v === "object" && "type" in v ? v : { type: "string" };
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
return basePagination;
|
|
2654
|
+
}
|
|
2417
2655
|
var QueryParser = class {
|
|
2418
2656
|
options;
|
|
2419
2657
|
operators = {
|
|
@@ -2687,7 +2925,7 @@ var QueryParser = class {
|
|
|
2687
2925
|
const stringValue = String(value);
|
|
2688
2926
|
if (stringValue === "true") return true;
|
|
2689
2927
|
if (stringValue === "false") return false;
|
|
2690
|
-
if (
|
|
2928
|
+
if (mongoose4.Types.ObjectId.isValid(stringValue) && stringValue.length === 24) {
|
|
2691
2929
|
return stringValue;
|
|
2692
2930
|
}
|
|
2693
2931
|
return stringValue;
|
|
@@ -2784,4 +3022,4 @@ var index_default = Repository;
|
|
|
2784
3022
|
* ```
|
|
2785
3023
|
*/
|
|
2786
3024
|
|
|
2787
|
-
export { PaginationEngine, QueryParser, Repository, actions_exports as actions, aggregateHelpersPlugin, auditLogPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, cascadePlugin, createError, createFieldPreset, createMemoryCache, createRepository, index_default as default, fieldFilterPlugin, filterResponseData, getFieldsForUser, getMongooseProjection, immutableField, methodRegistryPlugin, mongoOperationsPlugin, queryParser_default as queryParser, requireField, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin };
|
|
3025
|
+
export { PaginationEngine, QueryParser, Repository, actions_exports as actions, aggregateHelpersPlugin, auditLogPlugin, autoInject, batchOperationsPlugin, blockIf, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, cachePlugin, cascadePlugin, createError, createFieldPreset, createMemoryCache, createRepository, index_default as default, fieldFilterPlugin, filterResponseData, getFieldsForUser, getImmutableFields, getMongooseProjection, getSystemManagedFields, immutableField, isFieldUpdateAllowed, methodRegistryPlugin, mongoOperationsPlugin, queryParser_default as queryParser, requireField, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validateUpdateBody, validationChainPlugin };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Model } from 'mongoose';
|
|
2
|
-
import { A as AnyDocument, P as PaginationConfig, O as OffsetPaginationOptions, a as OffsetPaginationResult, K as KeysetPaginationOptions, b as KeysetPaginationResult, c as AggregatePaginationOptions, d as AggregatePaginationResult } from '../types-
|
|
2
|
+
import { A as AnyDocument, P as PaginationConfig, O as OffsetPaginationOptions, a as OffsetPaginationResult, K as KeysetPaginationOptions, b as KeysetPaginationResult, c as AggregatePaginationOptions, d as AggregatePaginationResult } from '../types-CHIDluaP.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Pagination Engine
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FieldPreset, r as Plugin, L as Logger, M as SoftDeleteOptions, t as RepositoryInstance, G as ValidatorDefinition, I as ValidationChainOptions, i as RepositoryContext, Z as CacheOptions, a1 as CascadeOptions } from '../types-
|
|
1
|
+
import { F as FieldPreset, r as Plugin, L as Logger, M as SoftDeleteOptions, t as RepositoryInstance, G as ValidatorDefinition, I as ValidationChainOptions, i as RepositoryContext, Z as CacheOptions, a1 as CascadeOptions } from '../types-CHIDluaP.js';
|
|
2
2
|
import 'mongoose';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { q as UserContext, F as FieldPreset, H as HttpError, Y as CacheAdapter, v as ParsedQuery } from './types-
|
|
1
|
+
import { q as UserContext, F as FieldPreset, H as HttpError, Y as CacheAdapter, y as SchemaBuilderOptions, z as CrudSchemas, V as ValidationResult, v as ParsedQuery } from './types-CHIDluaP.js';
|
|
2
|
+
import mongoose__default, { Schema } from 'mongoose';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Field Selection Utilities
|
|
@@ -139,6 +140,58 @@ declare function createError(status: number, message: string): HttpError;
|
|
|
139
140
|
*/
|
|
140
141
|
declare function createMemoryCache(maxEntries?: number): CacheAdapter;
|
|
141
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Mongoose to JSON Schema Converter with Field Rules
|
|
145
|
+
*
|
|
146
|
+
* Generates Fastify JSON schemas from Mongoose models with declarative field rules.
|
|
147
|
+
*
|
|
148
|
+
* Field Rules (options.fieldRules):
|
|
149
|
+
* - immutable: Field cannot be updated (omitted from update schema)
|
|
150
|
+
* - immutableAfterCreate: Alias for immutable
|
|
151
|
+
* - systemManaged: System-only field (omitted from create/update)
|
|
152
|
+
* - optional: Remove from required array
|
|
153
|
+
*
|
|
154
|
+
* Additional Options:
|
|
155
|
+
* - strictAdditionalProperties: Set to true to add "additionalProperties: false" to schemas
|
|
156
|
+
* This makes Fastify reject unknown fields at validation level (default: false for backward compatibility)
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* buildCrudSchemasFromModel(Model, {
|
|
160
|
+
* strictAdditionalProperties: true, // Reject unknown fields
|
|
161
|
+
* fieldRules: {
|
|
162
|
+
* organizationId: { immutable: true },
|
|
163
|
+
* status: { systemManaged: true },
|
|
164
|
+
* },
|
|
165
|
+
* create: { omitFields: ['verifiedAt'] },
|
|
166
|
+
* update: { omitFields: ['customerId'] }
|
|
167
|
+
* })
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Build CRUD schemas from Mongoose schema
|
|
172
|
+
*/
|
|
173
|
+
declare function buildCrudSchemasFromMongooseSchema(mongooseSchema: Schema, options?: SchemaBuilderOptions): CrudSchemas;
|
|
174
|
+
/**
|
|
175
|
+
* Build CRUD schemas from Mongoose model
|
|
176
|
+
*/
|
|
177
|
+
declare function buildCrudSchemasFromModel(mongooseModel: mongoose__default.Model<unknown>, options?: SchemaBuilderOptions): CrudSchemas;
|
|
178
|
+
/**
|
|
179
|
+
* Get fields that are immutable (cannot be updated)
|
|
180
|
+
*/
|
|
181
|
+
declare function getImmutableFields(options?: SchemaBuilderOptions): string[];
|
|
182
|
+
/**
|
|
183
|
+
* Get fields that are system-managed (cannot be set by users)
|
|
184
|
+
*/
|
|
185
|
+
declare function getSystemManagedFields(options?: SchemaBuilderOptions): string[];
|
|
186
|
+
/**
|
|
187
|
+
* Check if field is allowed in update
|
|
188
|
+
*/
|
|
189
|
+
declare function isFieldUpdateAllowed(fieldName: string, options?: SchemaBuilderOptions): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Validate update body against field rules
|
|
192
|
+
*/
|
|
193
|
+
declare function validateUpdateBody(body?: Record<string, unknown>, options?: SchemaBuilderOptions): ValidationResult;
|
|
194
|
+
|
|
142
195
|
/**
|
|
143
196
|
* Query Parser
|
|
144
197
|
*
|
|
@@ -247,4 +300,4 @@ declare class QueryParser {
|
|
|
247
300
|
/** Default query parser instance with standard options */
|
|
248
301
|
declare const defaultQueryParser: QueryParser;
|
|
249
302
|
|
|
250
|
-
export { type FilterValue as F, type OperatorMap as O, QueryParser as Q, getMongooseProjection as a,
|
|
303
|
+
export { type FilterValue as F, type OperatorMap as O, QueryParser as Q, getMongooseProjection as a, type QueryParserOptions as b, createFieldPreset as c, defaultQueryParser as d, buildCrudSchemasFromMongooseSchema as e, filterResponseData as f, getFieldsForUser as g, buildCrudSchemasFromModel as h, getImmutableFields as i, getSystemManagedFields as j, isFieldUpdateAllowed as k, createError as l, createMemoryCache as m, validateUpdateBody as v };
|
|
@@ -348,30 +348,16 @@ interface JsonSchema {
|
|
|
348
348
|
format?: string;
|
|
349
349
|
pattern?: string;
|
|
350
350
|
}
|
|
351
|
-
/** CRUD schemas result */
|
|
351
|
+
/** CRUD schemas result - framework-agnostic JSON schemas */
|
|
352
352
|
interface CrudSchemas {
|
|
353
|
+
/** JSON Schema for create request body */
|
|
353
354
|
createBody: JsonSchema;
|
|
355
|
+
/** JSON Schema for update request body */
|
|
354
356
|
updateBody: JsonSchema;
|
|
357
|
+
/** JSON Schema for route params (id validation) */
|
|
355
358
|
params: JsonSchema;
|
|
359
|
+
/** JSON Schema for list/query parameters */
|
|
356
360
|
listQuery: JsonSchema;
|
|
357
|
-
crudSchemas: {
|
|
358
|
-
create: {
|
|
359
|
-
body: JsonSchema;
|
|
360
|
-
};
|
|
361
|
-
update: {
|
|
362
|
-
body: JsonSchema;
|
|
363
|
-
params: JsonSchema;
|
|
364
|
-
};
|
|
365
|
-
get: {
|
|
366
|
-
params: JsonSchema;
|
|
367
|
-
};
|
|
368
|
-
list: {
|
|
369
|
-
query: JsonSchema;
|
|
370
|
-
};
|
|
371
|
-
remove: {
|
|
372
|
-
params: JsonSchema;
|
|
373
|
-
};
|
|
374
|
-
};
|
|
375
361
|
}
|
|
376
362
|
/** Decoded cursor */
|
|
377
363
|
interface DecodedCursor {
|
|
@@ -580,4 +566,4 @@ interface HttpError extends Error {
|
|
|
580
566
|
}>;
|
|
581
567
|
}
|
|
582
568
|
|
|
583
|
-
export type { CacheStats as $, AnyDocument as A, DecodedCursor as B, CreateOptions as C, DeleteResult as D, EventPayload as E, FieldPreset as F, ValidatorDefinition as G, HttpError as H, ValidationChainOptions as I, JsonSchema as J, KeysetPaginationOptions as K, Logger as L, SoftDeleteOptions as M, SoftDeleteFilterMode as N, OffsetPaginationOptions as O, PaginationConfig as P, SoftDeleteRepository as Q, RepositoryOptions as R, SelectSpec as S, LookupOptions as T, UpdateOptions as U, ValidationResult as V, GroupResult as W, MinMaxResult as X, CacheAdapter as Y, CacheOptions as Z, CacheOperationOptions as _, OffsetPaginationResult as a, CascadeRelation as a0, CascadeOptions as a1, KeysetPaginationResult as b, AggregatePaginationOptions as c, AggregatePaginationResult as d,
|
|
569
|
+
export type { CacheStats as $, AnyDocument as A, DecodedCursor as B, CreateOptions as C, DeleteResult as D, EventPayload as E, FieldPreset as F, ValidatorDefinition as G, HttpError as H, ValidationChainOptions as I, JsonSchema as J, KeysetPaginationOptions as K, Logger as L, SoftDeleteOptions as M, SoftDeleteFilterMode as N, OffsetPaginationOptions as O, PaginationConfig as P, SoftDeleteRepository as Q, RepositoryOptions as R, SelectSpec as S, LookupOptions as T, UpdateOptions as U, ValidationResult as V, GroupResult as W, MinMaxResult as X, CacheAdapter as Y, CacheOptions as Z, CacheOperationOptions as _, OffsetPaginationResult as a, CascadeRelation as a0, CascadeOptions as a1, KeysetPaginationResult as b, AggregatePaginationOptions as c, AggregatePaginationResult as d, PopulateSpec as e, SortSpec as f, PluginType as g, ObjectId as h, RepositoryContext as i, AnyModel as j, SortDirection as k, HookMode as l, PaginationResult as m, OperationOptions as n, UpdateManyResult as o, UpdateWithValidationResult as p, UserContext as q, Plugin as r, PluginFunction as s, RepositoryInstance as t, RepositoryEvent as u, ParsedQuery as v, FilterQuery as w, FieldRules as x, SchemaBuilderOptions as y, CrudSchemas as z };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,58 +1,6 @@
|
|
|
1
|
-
export { F as FilterValue, O as OperatorMap, Q as QueryParser,
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Mongoose to JSON Schema Converter with Field Rules
|
|
7
|
-
*
|
|
8
|
-
* Generates Fastify JSON schemas from Mongoose models with declarative field rules.
|
|
9
|
-
*
|
|
10
|
-
* Field Rules (options.fieldRules):
|
|
11
|
-
* - immutable: Field cannot be updated (omitted from update schema)
|
|
12
|
-
* - immutableAfterCreate: Alias for immutable
|
|
13
|
-
* - systemManaged: System-only field (omitted from create/update)
|
|
14
|
-
* - optional: Remove from required array
|
|
15
|
-
*
|
|
16
|
-
* Additional Options:
|
|
17
|
-
* - strictAdditionalProperties: Set to true to add "additionalProperties: false" to schemas
|
|
18
|
-
* This makes Fastify reject unknown fields at validation level (default: false for backward compatibility)
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* buildCrudSchemasFromModel(Model, {
|
|
22
|
-
* strictAdditionalProperties: true, // Reject unknown fields
|
|
23
|
-
* fieldRules: {
|
|
24
|
-
* organizationId: { immutable: true },
|
|
25
|
-
* status: { systemManaged: true },
|
|
26
|
-
* },
|
|
27
|
-
* create: { omitFields: ['verifiedAt'] },
|
|
28
|
-
* update: { omitFields: ['customerId'] }
|
|
29
|
-
* })
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Build CRUD schemas from Mongoose schema
|
|
34
|
-
*/
|
|
35
|
-
declare function buildCrudSchemasFromMongooseSchema(mongooseSchema: Schema, options?: SchemaBuilderOptions): CrudSchemas;
|
|
36
|
-
/**
|
|
37
|
-
* Build CRUD schemas from Mongoose model
|
|
38
|
-
*/
|
|
39
|
-
declare function buildCrudSchemasFromModel(mongooseModel: mongoose__default.Model<unknown>, options?: SchemaBuilderOptions): CrudSchemas;
|
|
40
|
-
/**
|
|
41
|
-
* Get fields that are immutable (cannot be updated)
|
|
42
|
-
*/
|
|
43
|
-
declare function getImmutableFields(options?: SchemaBuilderOptions): string[];
|
|
44
|
-
/**
|
|
45
|
-
* Get fields that are system-managed (cannot be set by users)
|
|
46
|
-
*/
|
|
47
|
-
declare function getSystemManagedFields(options?: SchemaBuilderOptions): string[];
|
|
48
|
-
/**
|
|
49
|
-
* Check if field is allowed in update
|
|
50
|
-
*/
|
|
51
|
-
declare function isFieldUpdateAllowed(fieldName: string, options?: SchemaBuilderOptions): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Validate update body against field rules
|
|
54
|
-
*/
|
|
55
|
-
declare function validateUpdateBody(body?: Record<string, unknown>, options?: SchemaBuilderOptions): ValidationResult;
|
|
1
|
+
export { F as FilterValue, O as OperatorMap, Q as QueryParser, b as QueryParserOptions, h as buildCrudSchemasFromModel, e as buildCrudSchemasFromMongooseSchema, l as createError, c as createFieldPreset, m as createMemoryCache, f as filterResponseData, g as getFieldsForUser, i as getImmutableFields, a as getMongooseProjection, j as getSystemManagedFields, k as isFieldUpdateAllowed, d as queryParser, v as validateUpdateBody } from '../queryParser-CxzCjzXd.js';
|
|
2
|
+
import { S as SelectSpec, e as PopulateSpec, f as SortSpec } from '../types-CHIDluaP.js';
|
|
3
|
+
import 'mongoose';
|
|
56
4
|
|
|
57
5
|
/**
|
|
58
6
|
* Cache Key Utilities
|
|
@@ -131,4 +79,4 @@ declare function modelPattern(prefix: string, model: string): string;
|
|
|
131
79
|
*/
|
|
132
80
|
declare function listPattern(prefix: string, model: string): string;
|
|
133
81
|
|
|
134
|
-
export {
|
|
82
|
+
export { byIdKey, byQueryKey, listPattern, listQueryKey, modelPattern, versionKey };
|
package/dist/utils/index.js
CHANGED
|
@@ -379,14 +379,7 @@ function buildCrudSchemasFromMongooseSchema(mongooseSchema, options = {}) {
|
|
|
379
379
|
required: ["id"]
|
|
380
380
|
};
|
|
381
381
|
const jsonQuery = buildJsonSchemaForQuery(tree, options);
|
|
382
|
-
|
|
383
|
-
create: { body: jsonCreate },
|
|
384
|
-
update: { body: jsonUpdate, params: jsonParams },
|
|
385
|
-
get: { params: jsonParams },
|
|
386
|
-
list: { query: jsonQuery },
|
|
387
|
-
remove: { params: jsonParams }
|
|
388
|
-
};
|
|
389
|
-
return { createBody: jsonCreate, updateBody: jsonUpdate, params: jsonParams, listQuery: jsonQuery, crudSchemas };
|
|
382
|
+
return { createBody: jsonCreate, updateBody: jsonUpdate, params: jsonParams, listQuery: jsonQuery };
|
|
390
383
|
}
|
|
391
384
|
function buildCrudSchemasFromModel(mongooseModel, options = {}) {
|
|
392
385
|
if (!mongooseModel || !mongooseModel.schema) {
|
package/package.json
CHANGED