@avytrix/nestjs-drizzle-crud 0.0.0-stage → 3.6.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/AGENT.md +513 -0
- package/AGENTS.template.md +31 -0
- package/CHANGELOG.md +565 -0
- package/CLAUDE.template.md +18 -0
- package/LICENSE +21 -0
- package/README.md +1307 -2
- package/dist/controller/crud-controller.factory.d.ts +28 -0
- package/dist/controller/crud-controller.factory.js +279 -0
- package/dist/controller/crud-controller.factory.js.map +1 -0
- package/dist/core/abstract/sql-base-crud.service.d.ts +230 -0
- package/dist/core/abstract/sql-base-crud.service.js +2899 -0
- package/dist/core/abstract/sql-base-crud.service.js.map +1 -0
- package/dist/core/context/crud-context.d.ts +6 -0
- package/dist/core/context/crud-context.js +27 -0
- package/dist/core/context/crud-context.js.map +1 -0
- package/dist/core/events/crud-event-bus.d.ts +7 -0
- package/dist/core/events/crud-event-bus.js +30 -0
- package/dist/core/events/crud-event-bus.js.map +1 -0
- package/dist/core/interfaces/crud-service.interface.d.ts +54 -0
- package/dist/core/interfaces/crud-service.interface.js +3 -0
- package/dist/core/interfaces/crud-service.interface.js.map +1 -0
- package/dist/core/interfaces/drizzle-crud-config.interface.d.ts +39 -0
- package/dist/core/interfaces/drizzle-crud-config.interface.js +3 -0
- package/dist/core/interfaces/drizzle-crud-config.interface.js.map +1 -0
- package/dist/core/interfaces/events.interface.d.ts +39 -0
- package/dist/core/interfaces/events.interface.js +3 -0
- package/dist/core/interfaces/events.interface.js.map +1 -0
- package/dist/core/interfaces/query.interface.d.ts +112 -0
- package/dist/core/interfaces/query.interface.js +3 -0
- package/dist/core/interfaces/query.interface.js.map +1 -0
- package/dist/core/interfaces/scope.interface.d.ts +3 -0
- package/dist/core/interfaces/scope.interface.js +3 -0
- package/dist/core/interfaces/scope.interface.js.map +1 -0
- package/dist/core/interfaces/sql-crud-config.interface.d.ts +87 -0
- package/dist/core/interfaces/sql-crud-config.interface.js +3 -0
- package/dist/core/interfaces/sql-crud-config.interface.js.map +1 -0
- package/dist/core/types/sql.types.d.ts +7 -0
- package/dist/core/types/sql.types.js +3 -0
- package/dist/core/types/sql.types.js.map +1 -0
- package/dist/core/utils/cursor.d.ts +2 -0
- package/dist/core/utils/cursor.js +44 -0
- package/dist/core/utils/cursor.js.map +1 -0
- package/dist/core/utils/merge-config.d.ts +2 -0
- package/dist/core/utils/merge-config.js +22 -0
- package/dist/core/utils/merge-config.js.map +1 -0
- package/dist/core/utils/query-parser.d.ts +4 -0
- package/dist/core/utils/query-parser.js +538 -0
- package/dist/core/utils/query-parser.js.map +1 -0
- package/dist/decorators/crud-service.decorator.d.ts +4 -0
- package/dist/decorators/crud-service.decorator.js +10 -0
- package/dist/decorators/crud-service.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +6 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/exceptions/crud.exceptions.d.ts +46 -0
- package/dist/exceptions/crud.exceptions.js +93 -0
- package/dist/exceptions/crud.exceptions.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +236 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/modules/drizzle-connection.d.ts +12 -0
- package/dist/modules/drizzle-connection.js +73 -0
- package/dist/modules/drizzle-connection.js.map +1 -0
- package/dist/modules/drizzle-crud.module.d.ts +11 -0
- package/dist/modules/drizzle-crud.module.js +165 -0
- package/dist/modules/drizzle-crud.module.js.map +1 -0
- package/dist/openapi/api-crud.decorators.d.ts +10 -0
- package/dist/openapi/api-crud.decorators.js +216 -0
- package/dist/openapi/api-crud.decorators.js.map +1 -0
- package/dist/test-utils/base-crud.spec-helper.d.ts +64 -0
- package/dist/test-utils/base-crud.spec-helper.js +119 -0
- package/dist/test-utils/base-crud.spec-helper.js.map +1 -0
- package/dist/test-utils/index.d.ts +2 -0
- package/dist/test-utils/index.js +8 -0
- package/dist/test-utils/index.js.map +1 -0
- package/dist/test-utils/test-factory.d.ts +29 -0
- package/dist/test-utils/test-factory.js +81 -0
- package/dist/test-utils/test-factory.js.map +1 -0
- package/package.json +110 -5
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionException = exports.DatabaseConnectionException = exports.BulkOperationException = exports.MissingScopeException = exports.StaleVersionException = exports.EntityInUseException = exports.ForeignKeyViolationException = exports.ValidationFailedException = exports.DuplicateEntityException = exports.EntityNotFoundException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class EntityNotFoundException extends common_1.NotFoundException {
|
|
6
|
+
constructor(entityName, id) {
|
|
7
|
+
super(`${entityName} with id ${id} not found`);
|
|
8
|
+
this.name = "EntityNotFoundException";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.EntityNotFoundException = EntityNotFoundException;
|
|
12
|
+
class DuplicateEntityException extends common_1.ConflictException {
|
|
13
|
+
constructor(entityName, field, value) {
|
|
14
|
+
super(`${entityName} with ${field} '${value}' already exists`);
|
|
15
|
+
this.name = "DuplicateEntityException";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.DuplicateEntityException = DuplicateEntityException;
|
|
19
|
+
class ValidationFailedException extends common_1.BadRequestException {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(`Validation failed: ${message}`);
|
|
22
|
+
this.name = "ValidationFailedException";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ValidationFailedException = ValidationFailedException;
|
|
26
|
+
class ForeignKeyViolationException extends common_1.BadRequestException {
|
|
27
|
+
constructor(entityName, field) {
|
|
28
|
+
super(`Invalid reference for ${entityName}: '${field}' does not refer to an existing record`);
|
|
29
|
+
this.name = "ForeignKeyViolationException";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ForeignKeyViolationException = ForeignKeyViolationException;
|
|
33
|
+
class EntityInUseException extends common_1.ConflictException {
|
|
34
|
+
constructor(entityName) {
|
|
35
|
+
super(`${entityName} is still referenced by other records and cannot be deleted`);
|
|
36
|
+
this.name = "EntityInUseException";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.EntityInUseException = EntityInUseException;
|
|
40
|
+
class StaleVersionException extends common_1.ConflictException {
|
|
41
|
+
constructor(entityName, id) {
|
|
42
|
+
super(`${entityName} with id ${id} was changed by someone else; read it again and retry`);
|
|
43
|
+
this.name = "StaleVersionException";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.StaleVersionException = StaleVersionException;
|
|
47
|
+
class MissingScopeException extends common_1.ForbiddenException {
|
|
48
|
+
constructor(entityName, key) {
|
|
49
|
+
super(`${entityName} is scoped by "${key}", but the context has no value for it`);
|
|
50
|
+
this.name = "MissingScopeException";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.MissingScopeException = MissingScopeException;
|
|
54
|
+
function toItemError(item) {
|
|
55
|
+
const where = item.index !== undefined ? { index: item.index } : { id: item.id };
|
|
56
|
+
if (item.error instanceof common_1.HttpException) {
|
|
57
|
+
return {
|
|
58
|
+
...where,
|
|
59
|
+
status: item.error.getStatus(),
|
|
60
|
+
message: item.error.message,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { ...where, status: 500, message: "Internal server error" };
|
|
64
|
+
}
|
|
65
|
+
class BulkOperationException extends common_1.BadRequestException {
|
|
66
|
+
errors;
|
|
67
|
+
constructor(message, errors) {
|
|
68
|
+
super({
|
|
69
|
+
statusCode: 400,
|
|
70
|
+
error: "Bad Request",
|
|
71
|
+
message: `${message}. ${errors.length} error(s) occurred.`,
|
|
72
|
+
errors: errors.map(toItemError),
|
|
73
|
+
});
|
|
74
|
+
this.errors = errors;
|
|
75
|
+
this.name = "BulkOperationException";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.BulkOperationException = BulkOperationException;
|
|
79
|
+
class DatabaseConnectionException extends common_1.InternalServerErrorException {
|
|
80
|
+
constructor(message = "Database connection failed") {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = "DatabaseConnectionException";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.DatabaseConnectionException = DatabaseConnectionException;
|
|
86
|
+
class TransactionException extends common_1.InternalServerErrorException {
|
|
87
|
+
constructor(message = "Transaction failed") {
|
|
88
|
+
super(message);
|
|
89
|
+
this.name = "TransactionException";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.TransactionException = TransactionException;
|
|
93
|
+
//# sourceMappingURL=crud.exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.exceptions.js","sourceRoot":"","sources":["../../src/exceptions/crud.exceptions.ts"],"names":[],"mappings":";;;AAAA,2CAOwB;AAOxB,6BAAqC,SAAQ,0BAAiB;IAC7D,YAAY,UAAkB,EAAE,EAAO;QACtC,KAAK,CAAC,GAAG,UAAU,YAAY,EAAE,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;;AAED,8BAAsC,SAAQ,0BAAiB;IAC9D,YAAY,UAAkB,EAAE,KAAa,EAAE,KAAU;QACxD,KAAK,CAAC,GAAG,UAAU,SAAS,KAAK,KAAK,KAAK,kBAAkB,CAAC,CAAC;QAC/D,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD;;AAED,+BAAuC,SAAQ,4BAAmB;IACjE,YAAY,OAAe;QAC1B,KAAK,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IACzC,CAAC;CACD;;AAID,kCAA0C,SAAQ,4BAAmB;IACpE,YAAY,UAAkB,EAAE,KAAa;QAC5C,KAAK,CACJ,yBAAyB,UAA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;QAEzE,KAAK,CAAC;YACL,UAAU,EAAE,GAAG;YACf,KAAK,EAAE,aAAa;YACpB,OAAO,EAAE,GAAG,OAAO,KAAK,MAAM,CAAC,MAAM,qBAAqB;YAC1D,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC;SAC/B,CAAC,CAAC;sBAPa,MAAM;QAQtB,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACtC,CAAC;CACD;;AAMD,iCAAyC,SAAQ,qCAA4B;IAC5E,YAAY,OAAO,GAAW,4BAA4B;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC3C,CAAC;CACD;;AAOD,0BAAkC,SAAQ,qCAA4B;IACrE,YAAY,OAAO,GAAW,oBAAoB;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACpC,CAAC;CACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { and, asc, between, desc, eq, gt, gte, ilike, inArray, isNotNull, isNull, like, lt, lte, ne, not, notInArray, or, sql, } from "drizzle-orm";
|
|
2
|
+
export type { CrudControllerInstance, CrudControllerOptions, CrudRouteName, CrudRouteOptions, } from "./controller/crud-controller.factory";
|
|
3
|
+
export { createCrudController } from "./controller/crud-controller.factory";
|
|
4
|
+
export { SqlBaseCrudService } from "./core/abstract/sql-base-crud.service";
|
|
5
|
+
export { CrudContext } from "./core/context/crud-context";
|
|
6
|
+
export { CrudEventBus } from "./core/events/crud-event-bus";
|
|
7
|
+
export type { BulkOperationResult, ICrudService, OperationOptions, PaginationOptions, } from "./core/interfaces/crud-service.interface";
|
|
8
|
+
export type { CrudFeature, CrudFeatureConfig, DrizzleCrudConfig, } from "./core/interfaces/drizzle-crud-config.interface";
|
|
9
|
+
export type { CrudEvent, CrudEventPhase, CrudSubscriber, CrudWriteOperation, } from "./core/interfaces/events.interface";
|
|
10
|
+
export type { BulkMode, CollectionFilter, CollectionQuantifier, ColumnFilter, CountByRow, CrudAllowlists, CrudFilter, CrudPage, CursorPage, CursorPaginationOptions, FilterGroup, FilterOperator, FilterOperators, FilterScalar, ParseCrudQueryOptions, ParsedCrudQuery, RelationCounts, SortInput, UncountedCrudPage, UpsertOptions, } from "./core/interfaces/query.interface";
|
|
11
|
+
export type { CrudContextValue, CrudScope, CrudScopeValues, } from "./core/interfaces/scope.interface";
|
|
12
|
+
export type { RelationConfig, RelationNode, RelationsConfig, RelationType, SelectTree, SqlCrudConfig, SqlOperationOptions, SqlSearchMode, SqlSearchOptions, } from "./core/interfaces/sql-crud-config.interface";
|
|
13
|
+
export { parseCrudQuery } from "./core/utils/query-parser";
|
|
14
|
+
export type { PrimaryKeyType, SortColumn, SortOrder, SqlDialect, } from "./core/types/sql.types";
|
|
15
|
+
export { CrudService } from "./decorators/crud-service.decorator";
|
|
16
|
+
export type { BulkOperationItemError } from "./exceptions/crud.exceptions";
|
|
17
|
+
export { BulkOperationException, DatabaseConnectionException, DuplicateEntityException, EntityInUseException, EntityNotFoundException, ForeignKeyViolationException, MissingScopeException, StaleVersionException, TransactionException, ValidationFailedException, } from "./exceptions/crud.exceptions";
|
|
18
|
+
export { DrizzleCrudModule } from "./modules/drizzle-crud.module";
|
|
19
|
+
export { DRIZZLE_CONNECTION, DRIZZLE_CRUD_CONFIG, DRIZZLE_DB, DrizzleConnection, } from "./modules/drizzle-connection";
|
|
20
|
+
export type { ApiCrudQueryOptions, ApiCrudSource, } from "./openapi/api-crud.decorators";
|
|
21
|
+
export { ApiCrudList, ApiCrudQuery } from "./openapi/api-crud.decorators";
|
|
22
|
+
export { BaseCrudSpecHelper } from "./test-utils/base-crud.spec-helper";
|
|
23
|
+
export { TestCrudFactory } from "./test-utils/test-factory";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestCrudFactory = exports.BaseCrudSpecHelper = exports.ApiCrudQuery = exports.ApiCrudList = exports.DrizzleConnection = exports.DRIZZLE_DB = exports.DRIZZLE_CRUD_CONFIG = exports.DRIZZLE_CONNECTION = exports.DrizzleCrudModule = exports.ValidationFailedException = exports.TransactionException = exports.StaleVersionException = exports.MissingScopeException = exports.ForeignKeyViolationException = exports.EntityNotFoundException = exports.EntityInUseException = exports.DuplicateEntityException = exports.DatabaseConnectionException = exports.BulkOperationException = exports.CrudService = exports.parseCrudQuery = exports.CrudEventBus = exports.CrudContext = exports.SqlBaseCrudService = exports.createCrudController = exports.sql = exports.or = exports.notInArray = exports.not = exports.ne = exports.lte = exports.lt = exports.like = exports.isNull = exports.isNotNull = exports.inArray = exports.ilike = exports.gte = exports.gt = exports.eq = exports.desc = exports.between = exports.asc = exports.and = void 0;
|
|
4
|
+
var drizzle_orm_1 = require("drizzle-orm");
|
|
5
|
+
Object.defineProperty(exports, "and", { enumerable: true, get: function () { return drizzle_orm_1.and; } });
|
|
6
|
+
Object.defineProperty(exports, "asc", { enumerable: true, get: function () { return drizzle_orm_1.asc; } });
|
|
7
|
+
Object.defineProperty(exports, "between", { enumerable: true, get: function () { return drizzle_orm_1.between; } });
|
|
8
|
+
Object.defineProperty(exports, "desc", { enumerable: true, get: function () { return drizzle_orm_1.desc; } });
|
|
9
|
+
Object.defineProperty(exports, "eq", { enumerable: true, get: function () { return drizzle_orm_1.eq; } });
|
|
10
|
+
Object.defineProperty(exports, "gt", { enumerable: true, get: function () { return drizzle_orm_1.gt; } });
|
|
11
|
+
Object.defineProperty(exports, "gte", { enumerable: true, get: function () { return drizzle_orm_1.gte; } });
|
|
12
|
+
Object.defineProperty(exports, "ilike", { enumerable: true, get: function () { return drizzle_orm_1.ilike; } });
|
|
13
|
+
Object.defineProperty(exports, "inArray", { enumerable: true, get: function () { return drizzle_orm_1.inArray; } });
|
|
14
|
+
Object.defineProperty(exports, "isNotNull", { enumerable: true, get: function () { return drizzle_orm_1.isNotNull; } });
|
|
15
|
+
Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return drizzle_orm_1.isNull; } });
|
|
16
|
+
Object.defineProperty(exports, "like", { enumerable: true, get: function () { return drizzle_orm_1.like; } });
|
|
17
|
+
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return drizzle_orm_1.lt; } });
|
|
18
|
+
Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return drizzle_orm_1.lte; } });
|
|
19
|
+
Object.defineProperty(exports, "ne", { enumerable: true, get: function () { return drizzle_orm_1.ne; } });
|
|
20
|
+
Object.defineProperty(exports, "not", { enumerable: true, get: function () { return drizzle_orm_1.not; } });
|
|
21
|
+
Object.defineProperty(exports, "notInArray", { enumerable: true, get: function () { return drizzle_orm_1.notInArray; } });
|
|
22
|
+
Object.defineProperty(exports, "or", { enumerable: true, get: function () { return drizzle_orm_1.or; } });
|
|
23
|
+
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return drizzle_orm_1.sql; } });
|
|
24
|
+
var crud_controller_factory_1 = require("./controller/crud-controller.factory");
|
|
25
|
+
Object.defineProperty(exports, "createCrudController", { enumerable: true, get: function () { return crud_controller_factory_1.createCrudController; } });
|
|
26
|
+
var sql_base_crud_service_1 = require("./core/abstract/sql-base-crud.service");
|
|
27
|
+
Object.defineProperty(exports, "SqlBaseCrudService", { enumerable: true, get: function () { return sql_base_crud_service_1.SqlBaseCrudService; } });
|
|
28
|
+
var crud_context_1 = require("./core/context/crud-context");
|
|
29
|
+
Object.defineProperty(exports, "CrudContext", { enumerable: true, get: function () { return crud_context_1.CrudContext; } });
|
|
30
|
+
var crud_event_bus_1 = require("./core/events/crud-event-bus");
|
|
31
|
+
Object.defineProperty(exports, "CrudEventBus", { enumerable: true, get: function () { return crud_event_bus_1.CrudEventBus; } });
|
|
32
|
+
var query_parser_1 = require("./core/utils/query-parser");
|
|
33
|
+
Object.defineProperty(exports, "parseCrudQuery", { enumerable: true, get: function () { return query_parser_1.parseCrudQuery; } });
|
|
34
|
+
var crud_service_decorator_1 = require("./decorators/crud-service.decorator");
|
|
35
|
+
Object.defineProperty(exports, "CrudService", { enumerable: true, get: function () { return crud_service_decorator_1.CrudService; } });
|
|
36
|
+
var crud_exceptions_1 = require("./exceptions/crud.exceptions");
|
|
37
|
+
Object.defineProperty(exports, "BulkOperationException", { enumerable: true, get: function () { return crud_exceptions_1.BulkOperationException; } });
|
|
38
|
+
Object.defineProperty(exports, "DatabaseConnectionException", { enumerable: true, get: function () { return crud_exceptions_1.DatabaseConnectionException; } });
|
|
39
|
+
Object.defineProperty(exports, "DuplicateEntityException", { enumerable: true, get: function () { return crud_exceptions_1.DuplicateEntityException; } });
|
|
40
|
+
Object.defineProperty(exports, "EntityInUseException", { enumerable: true, get: function () { return crud_exceptions_1.EntityInUseException; } });
|
|
41
|
+
Object.defineProperty(exports, "EntityNotFoundException", { enumerable: true, get: function () { return crud_exceptions_1.EntityNotFoundException; } });
|
|
42
|
+
Object.defineProperty(exports, "ForeignKeyViolationException", { enumerable: true, get: function () { return crud_exceptions_1.ForeignKeyViolationException; } });
|
|
43
|
+
Object.defineProperty(exports, "MissingScopeException", { enumerable: true, get: function () { return crud_exceptions_1.MissingScopeException; } });
|
|
44
|
+
Object.defineProperty(exports, "StaleVersionException", { enumerable: true, get: function () { return crud_exceptions_1.StaleVersionException; } });
|
|
45
|
+
Object.defineProperty(exports, "TransactionException", { enumerable: true, get: function () { return crud_exceptions_1.TransactionException; } });
|
|
46
|
+
Object.defineProperty(exports, "ValidationFailedException", { enumerable: true, get: function () { return crud_exceptions_1.ValidationFailedException; } });
|
|
47
|
+
var drizzle_crud_module_1 = require("./modules/drizzle-crud.module");
|
|
48
|
+
Object.defineProperty(exports, "DrizzleCrudModule", { enumerable: true, get: function () { return drizzle_crud_module_1.DrizzleCrudModule; } });
|
|
49
|
+
var drizzle_connection_1 = require("./modules/drizzle-connection");
|
|
50
|
+
Object.defineProperty(exports, "DRIZZLE_CONNECTION", { enumerable: true, get: function () { return drizzle_connection_1.DRIZZLE_CONNECTION; } });
|
|
51
|
+
Object.defineProperty(exports, "DRIZZLE_CRUD_CONFIG", { enumerable: true, get: function () { return drizzle_connection_1.DRIZZLE_CRUD_CONFIG; } });
|
|
52
|
+
Object.defineProperty(exports, "DRIZZLE_DB", { enumerable: true, get: function () { return drizzle_connection_1.DRIZZLE_DB; } });
|
|
53
|
+
Object.defineProperty(exports, "DrizzleConnection", { enumerable: true, get: function () { return drizzle_connection_1.DrizzleConnection; } });
|
|
54
|
+
var api_crud_decorators_1 = require("./openapi/api-crud.decorators");
|
|
55
|
+
Object.defineProperty(exports, "ApiCrudList", { enumerable: true, get: function () { return api_crud_decorators_1.ApiCrudList; } });
|
|
56
|
+
Object.defineProperty(exports, "ApiCrudQuery", { enumerable: true, get: function () { return api_crud_decorators_1.ApiCrudQuery; } });
|
|
57
|
+
var base_crud_spec_helper_1 = require("./test-utils/base-crud.spec-helper");
|
|
58
|
+
Object.defineProperty(exports, "BaseCrudSpecHelper", { enumerable: true, get: function () { return base_crud_spec_helper_1.BaseCrudSpecHelper; } });
|
|
59
|
+
var test_factory_1 = require("./test-utils/test-factory");
|
|
60
|
+
Object.defineProperty(exports, "TestCrudFactory", { enumerable: true, get: function () { return test_factory_1.TestCrudFactory; } });
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAMA,2CAoBqB;AAnBpB,kGAAA,GAAG,OAAA;AACH,kGAAA,GAAG,OAAA;AACH,sGAAA,OAAO,OAAA;AACP,mGAAA,IAAI,OAAA;AACJ,iGAAA,EAAE,OAAA;AACF,iGAAA,EAAE,OAAA;AACF,kGAAA,GAAG,OAAA;AACH,oGAAA,KAAK,OAAA;AACL,sGAAA,OAAO,OAAA;AACP,wGAAA,SAAS,OAAA;AACT,qGAAA,MAAM,OAAA;AACN,mGAAA,IAAI,OAAA;AACJ,iGAAA,EAAE,OAAA;AACF,kGAAA,GAAG,OAAA;AACH,iGAAA,EAAE,OAAA;AACF,kGAAA,GAAG,OAAA;AACH,yGAAA,UAAU,OAAA;AACV,iGAAA,EAAE,OAAA;AACF,kGAAA,GAAG,OAAA;AASJ,gFAA4E;AAAnE,+HAAA,oBAAoB,OAAA;AAE7B,+EAA2E;AAAlE,2HAAA,kBAAkB,OAAA;AAE3B,4DAA0D;AAAjD,2GAAA,WAAW,OAAA;AAEpB,+DAA4D;AAAnD,8GAAA,YAAY,OAAA;AA2DrB,0DAA2D;AAAlD,8GAAA,cAAc,OAAA;AASvB,8EAAkE;AAAzD,qHAAA,WAAW,OAAA;AAGpB,gEAWsC;AAVrC,yHAAA,sBAAsB,OAAA;AACtB,8HAAA,2BAA2B,OAAA;AAC3B,2HAAA,wBAAwB,OAAA;AACxB,uHAAA,oBAAoB,OAAA;AACpB,0HAAA,uBAAuB,OAAA;AACvB,+HAAA,4BAA4B,OAAA;AAC5B,wHAAA,qBAAqB,OAAA;AACrB,wHAAA,qBAAqB,OAAA;AACrB,uHAAA,oBAAoB,OAAA;AACpB,4HAAA,yBAAyB,OAAA;AAG1B,qEAAkE;AAAzD,wHAAA,iBAAiB,OAAA;AAC1B,mEAKsC;AAJrC,wHAAA,kBAAkB,OAAA;AAClB,yHAAA,mBAAmB,OAAA;AACnB,gHAAA,UAAU,OAAA;AACV,uHAAA,iBAAiB,OAAA;AAOlB,qEAA0E;AAAjE,kHAAA,WAAW,OAAA;AAAE,mHAAA,YAAY,OAAA;AAElC,4EAAwE;AAA/D,2HAAA,kBAAkB,OAAA;AAC3B,0DAA4D;AAAnD,+GAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.handleRequest = handleRequest;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const PROTOCOL_VERSION = "2025-06-18";
|
|
8
|
+
const PACKAGE_ROOT = (0, node_path_1.resolve)(__dirname, "..", "..");
|
|
9
|
+
const DOCS = {
|
|
10
|
+
"agent-guide": {
|
|
11
|
+
file: "AGENT.md",
|
|
12
|
+
title: "Agent guide: how to use the package correctly",
|
|
13
|
+
},
|
|
14
|
+
readme: { file: "README.md", title: "README: full API and options" },
|
|
15
|
+
changelog: { file: "CHANGELOG.md", title: "Release history" },
|
|
16
|
+
};
|
|
17
|
+
function readDoc(name) {
|
|
18
|
+
try {
|
|
19
|
+
return (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(PACKAGE_ROOT, DOCS[name].file), "utf8");
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return `(${DOCS[name].file} is not available in this installation)`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function sections(doc) {
|
|
26
|
+
const out = [];
|
|
27
|
+
let current = { doc, heading: "(intro)", level: 0, body: "" };
|
|
28
|
+
for (const line of readDoc(doc).split("\n")) {
|
|
29
|
+
const match = /^(#{1,6})\s+(.*)$/.exec(line);
|
|
30
|
+
if (match) {
|
|
31
|
+
if (current.body.trim() || current.level > 0)
|
|
32
|
+
out.push(current);
|
|
33
|
+
current = {
|
|
34
|
+
doc,
|
|
35
|
+
heading: match[2].trim(),
|
|
36
|
+
level: match[1].length,
|
|
37
|
+
body: "",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
current.body += `${line}\n`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
out.push(current);
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
function allSections() {
|
|
48
|
+
return Object.keys(DOCS).flatMap(sections);
|
|
49
|
+
}
|
|
50
|
+
function packageVersion() {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.resolve)(PACKAGE_ROOT, "package.json"), "utf8")).version;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return "0.0.0";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function listDocs() {
|
|
59
|
+
return Object.entries(DOCS)
|
|
60
|
+
.map(([name, { title }]) => {
|
|
61
|
+
const headings = sections(name)
|
|
62
|
+
.filter((s) => s.level > 0 && s.level <= 2)
|
|
63
|
+
.map((s) => ` - ${s.heading}`)
|
|
64
|
+
.join("\n");
|
|
65
|
+
return `## ${name}\n${title}\n${headings}`;
|
|
66
|
+
})
|
|
67
|
+
.join("\n\n");
|
|
68
|
+
}
|
|
69
|
+
function getDoc(name, section) {
|
|
70
|
+
if (!DOCS[name]) {
|
|
71
|
+
return `Unknown doc "${name}". Available: ${Object.keys(DOCS).join(", ")}.`;
|
|
72
|
+
}
|
|
73
|
+
if (!section)
|
|
74
|
+
return readDoc(name);
|
|
75
|
+
const wanted = section.toLowerCase();
|
|
76
|
+
const found = sections(name).filter((s) => s.heading.toLowerCase().includes(wanted));
|
|
77
|
+
if (found.length === 0) {
|
|
78
|
+
return `No section matching "${section}" in ${name}. Call list_docs for the headings.`;
|
|
79
|
+
}
|
|
80
|
+
return found
|
|
81
|
+
.map((s) => `${"#".repeat(Math.max(1, s.level))} ${s.heading}\n${s.body}`)
|
|
82
|
+
.join("\n");
|
|
83
|
+
}
|
|
84
|
+
function searchDocs(query, limit = 5) {
|
|
85
|
+
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
86
|
+
if (terms.length === 0)
|
|
87
|
+
return "Empty query.";
|
|
88
|
+
const scored = allSections()
|
|
89
|
+
.map((s) => {
|
|
90
|
+
const heading = s.heading.toLowerCase();
|
|
91
|
+
const body = s.body.toLowerCase();
|
|
92
|
+
let score = 0;
|
|
93
|
+
for (const term of terms) {
|
|
94
|
+
if (heading.includes(term))
|
|
95
|
+
score += 5;
|
|
96
|
+
score += body.split(term).length - 1;
|
|
97
|
+
}
|
|
98
|
+
return { section: s, score };
|
|
99
|
+
})
|
|
100
|
+
.filter((hit) => hit.score > 0)
|
|
101
|
+
.sort((a, b) => b.score - a.score)
|
|
102
|
+
.slice(0, Math.max(1, Math.min(limit, 20)));
|
|
103
|
+
if (scored.length === 0)
|
|
104
|
+
return `No match for "${query}".`;
|
|
105
|
+
return scored
|
|
106
|
+
.map(({ section }) => `## ${section.doc} > ${section.heading}\n${section.body.slice(0, 1500).trim()}`)
|
|
107
|
+
.join("\n\n---\n\n");
|
|
108
|
+
}
|
|
109
|
+
const TOOLS = [
|
|
110
|
+
{
|
|
111
|
+
name: "list_docs",
|
|
112
|
+
description: "List the nestjs-drizzle-crud documents available through this server and their top-level headings. Start here.",
|
|
113
|
+
inputSchema: { type: "object", properties: {} },
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "get_doc",
|
|
117
|
+
description: "Read a nestjs-drizzle-crud document, or one section of it. Use this before writing code that touches the package.",
|
|
118
|
+
inputSchema: {
|
|
119
|
+
type: "object",
|
|
120
|
+
properties: {
|
|
121
|
+
doc: {
|
|
122
|
+
type: "string",
|
|
123
|
+
enum: Object.keys(DOCS),
|
|
124
|
+
description: "Which document to read.",
|
|
125
|
+
},
|
|
126
|
+
section: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "Optional heading to return instead of the whole document (substring match).",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
required: ["doc"],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "search_docs",
|
|
136
|
+
description: "Full-text search across the nestjs-drizzle-crud docs. Returns the most relevant sections, best match first.",
|
|
137
|
+
inputSchema: {
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: {
|
|
140
|
+
query: { type: "string", description: "What to look for." },
|
|
141
|
+
limit: {
|
|
142
|
+
type: "number",
|
|
143
|
+
description: "How many sections to return (default 5, max 20).",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
required: ["query"],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
function callTool(name, args) {
|
|
151
|
+
switch (name) {
|
|
152
|
+
case "list_docs":
|
|
153
|
+
return listDocs();
|
|
154
|
+
case "get_doc":
|
|
155
|
+
return getDoc(String(args.doc ?? ""), args.section);
|
|
156
|
+
case "search_docs":
|
|
157
|
+
return searchDocs(String(args.query ?? ""), Number(args.limit) || 5);
|
|
158
|
+
default:
|
|
159
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function handleRequest(request) {
|
|
163
|
+
const { id, method, params } = request;
|
|
164
|
+
const isNotification = id === undefined || id === null;
|
|
165
|
+
const reply = (result) => ({ jsonrpc: "2.0", id, result });
|
|
166
|
+
const fail = (code, message) => ({
|
|
167
|
+
jsonrpc: "2.0",
|
|
168
|
+
id,
|
|
169
|
+
error: { code, message },
|
|
170
|
+
});
|
|
171
|
+
if (isNotification)
|
|
172
|
+
return null;
|
|
173
|
+
switch (method) {
|
|
174
|
+
case "initialize":
|
|
175
|
+
return reply({
|
|
176
|
+
protocolVersion: params?.protocolVersion ?? PROTOCOL_VERSION,
|
|
177
|
+
capabilities: { tools: {} },
|
|
178
|
+
serverInfo: { name: "nestjs-drizzle-crud", version: packageVersion() },
|
|
179
|
+
});
|
|
180
|
+
case "ping":
|
|
181
|
+
return reply({});
|
|
182
|
+
case "tools/list":
|
|
183
|
+
return reply({ tools: TOOLS });
|
|
184
|
+
case "tools/call":
|
|
185
|
+
try {
|
|
186
|
+
return reply({
|
|
187
|
+
content: [
|
|
188
|
+
{
|
|
189
|
+
type: "text",
|
|
190
|
+
text: callTool(params?.name, params?.arguments ?? {}),
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
return reply({
|
|
197
|
+
content: [{ type: "text", text: error.message }],
|
|
198
|
+
isError: true,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
default:
|
|
202
|
+
return fail(-32601, `Method not found: ${method}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function main() {
|
|
206
|
+
let buffer = "";
|
|
207
|
+
process.stdin.setEncoding("utf8");
|
|
208
|
+
process.stdin.on("data", (chunk) => {
|
|
209
|
+
buffer += chunk;
|
|
210
|
+
let newline = buffer.indexOf("\n");
|
|
211
|
+
while (newline >= 0) {
|
|
212
|
+
const line = buffer.slice(0, newline).trim();
|
|
213
|
+
buffer = buffer.slice(newline + 1);
|
|
214
|
+
newline = buffer.indexOf("\n");
|
|
215
|
+
if (!line)
|
|
216
|
+
continue;
|
|
217
|
+
let response = null;
|
|
218
|
+
try {
|
|
219
|
+
response = handleRequest(JSON.parse(line));
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
response = {
|
|
223
|
+
jsonrpc: "2.0",
|
|
224
|
+
id: null,
|
|
225
|
+
error: { code: -32700, message: "Parse error" },
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (response)
|
|
229
|
+
process.stdout.write(`${JSON.stringify(response)}\n`);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
process.stdin.on("end", () => process.exit(0));
|
|
233
|
+
}
|
|
234
|
+
if (require.main === module)
|
|
235
|
+
main();
|
|
236
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":";;;;AAcA,qCAAuC;AACvC,yCAAoC;AAEpC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AACtC,MAAM,YAAY,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAGpD,MAAM,IAAI,GAAoD;IAC7D,aAAa,EAAE;QACd,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,+CAA+C;KACtD;IACD,MAAM,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K,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OnModuleDestroy } from "@nestjs/common";
|
|
2
|
+
import type { DrizzleCrudConfig } from "../core/interfaces/drizzle-crud-config.interface";
|
|
3
|
+
export declare const DRIZZLE_DB = "DRIZZLE_DB";
|
|
4
|
+
export declare const DRIZZLE_CRUD_CONFIG = "DRIZZLE_CRUD_CONFIG";
|
|
5
|
+
export declare const DRIZZLE_CONNECTION = "DRIZZLE_CONNECTION";
|
|
6
|
+
export declare class DrizzleConnection implements OnModuleDestroy {
|
|
7
|
+
db: any;
|
|
8
|
+
private client?;
|
|
9
|
+
private ownsConnection;
|
|
10
|
+
init(config: DrizzleCrudConfig): Promise<void>;
|
|
11
|
+
onModuleDestroy(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DrizzleConnection = exports.DRIZZLE_CONNECTION = exports.DRIZZLE_CRUD_CONFIG = exports.DRIZZLE_DB = void 0;
|
|
37
|
+
exports.DRIZZLE_DB = "DRIZZLE_DB";
|
|
38
|
+
exports.DRIZZLE_CRUD_CONFIG = "DRIZZLE_CRUD_CONFIG";
|
|
39
|
+
exports.DRIZZLE_CONNECTION = "DRIZZLE_CONNECTION";
|
|
40
|
+
class DrizzleConnection {
|
|
41
|
+
db;
|
|
42
|
+
client;
|
|
43
|
+
ownsConnection = false;
|
|
44
|
+
async init(config) {
|
|
45
|
+
if (config.db) {
|
|
46
|
+
this.db = config.db;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!config.connectionString) {
|
|
50
|
+
throw new Error("DrizzleCrudModule: provide either `db` (a Drizzle instance) or `connectionString`.");
|
|
51
|
+
}
|
|
52
|
+
if (config.dialect === "postgresql") {
|
|
53
|
+
const postgres = (await Promise.resolve().then(() => __importStar(require("postgres")))).default;
|
|
54
|
+
const { drizzle } = await Promise.resolve().then(() => __importStar(require("drizzle-orm/postgres-js")));
|
|
55
|
+
const client = postgres(config.connectionString, { prepare: false });
|
|
56
|
+
this.client = client;
|
|
57
|
+
this.ownsConnection = true;
|
|
58
|
+
this.db = config.schema
|
|
59
|
+
? drizzle(client, { schema: config.schema })
|
|
60
|
+
: drizzle(client);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
throw new Error(`DrizzleCrudModule: building a connection from \`connectionString\` is only supported for the "postgresql" dialect. ` +
|
|
64
|
+
`For "${config.dialect}", construct the Drizzle instance yourself and pass it as \`db\`.`);
|
|
65
|
+
}
|
|
66
|
+
async onModuleDestroy() {
|
|
67
|
+
if (this.ownsConnection && this.client?.end) {
|
|
68
|
+
await this.client.end();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.DrizzleConnection = DrizzleConnection;
|
|
73
|
+
//# sourceMappingURL=drizzle-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-connection.js","sourceRoot":"","sources":["../../src/modules/drizzle-connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGa,QAAA,UAAU,GAAG,YAAY,CAAC;AAC1B,QAAA,mBAAmB,GAAG,qBAAqB,CAAC;AAC5C,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AASvD;IACC,EAAE,CAAM;IACA,MAAM,CAAiC;IACvC,cAAc,GAAG,KAAK,CAAC;IAE/B,KAAK,CAAC,IAAI,CAAC,MAAyB;QACnC,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;YACpB,OAAO;QACR,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACd,oFAAoF,CACpF,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,OAAO,KAAK,YAAY,EAAE,CAAC;YACrC,MAAM,QAAQ,GAAG,CAAC,wDAAa,UAAU,GAAC,CAAC,CAAC,OAAO,CAAC;YACpD,MAAM,EAAE,OAAO,EAAE,GAAG,wDAAa,yBAAyB,GAAC,CAAC;YAC5D,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YACrE,IAAI,CAAC,MAAM,GAAG,MAAiD,CAAC;YAChE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM;gBACtB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;gBAC5C,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACnB,OAAO;QACR,CAAC;QAED,MAAM,IAAI,KAAK,CACd,qHAAqH;YACpH,QAAQ,MAAM,CAAC,OAAO,mEAAmE,CAC1F,CAAC;IACH,CAAC;IAED,KAAK,CAAC,eAAe;QACpB,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;YAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QACzB,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DynamicModule } from "@nestjs/common";
|
|
2
|
+
import type { CrudFeature, DrizzleCrudConfig } from "../core/interfaces/drizzle-crud-config.interface";
|
|
3
|
+
export declare class DrizzleCrudModule {
|
|
4
|
+
static forRoot(config: DrizzleCrudConfig): DynamicModule;
|
|
5
|
+
static forRootAsync(options: {
|
|
6
|
+
imports?: any[];
|
|
7
|
+
useFactory: (...args: any[]) => Promise<DrizzleCrudConfig> | DrizzleCrudConfig;
|
|
8
|
+
inject?: any[];
|
|
9
|
+
}): DynamicModule;
|
|
10
|
+
static forFeature(entities: CrudFeature[]): DynamicModule;
|
|
11
|
+
}
|