@nest-native/drizzle 0.3.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/README.md +10 -0
- package/dist/client/connection.util.d.ts +2 -0
- package/dist/client/connection.util.js +10 -0
- package/dist/client/connection.util.js.map +1 -0
- package/dist/client/drizzle-connection.manager.d.ts +8 -0
- package/dist/client/drizzle-connection.manager.js +17 -0
- package/dist/client/drizzle-connection.manager.js.map +1 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/drizzle-repository.decorator.d.ts +3 -0
- package/dist/decorators/drizzle-repository.decorator.js +26 -0
- package/dist/decorators/drizzle-repository.decorator.js.map +1 -0
- package/dist/decorators/inject-drizzle.decorator.d.ts +2 -0
- package/dist/decorators/inject-drizzle.decorator.js +9 -0
- package/dist/decorators/inject-drizzle.decorator.js.map +1 -0
- package/dist/decorators/inject-transaction.decorator.d.ts +2 -0
- package/dist/decorators/inject-transaction.decorator.js +34 -0
- package/dist/decorators/inject-transaction.decorator.js.map +1 -0
- package/dist/decorators/transactional.decorator.d.ts +3 -0
- package/dist/decorators/transactional.decorator.js +32 -0
- package/dist/decorators/transactional.decorator.js.map +1 -0
- package/dist/drizzle.module.d.ts +7 -0
- package/dist/drizzle.module.js +95 -0
- package/dist/drizzle.module.js.map +1 -0
- package/dist/errors/drizzle-error.mapper.d.ts +10 -0
- package/dist/errors/drizzle-error.mapper.js +52 -0
- package/dist/errors/drizzle-error.mapper.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +46 -0
- package/dist/interfaces.js +3 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/testing/drizzle-test.module.d.ts +6 -0
- package/dist/testing/drizzle-test.module.js +29 -0
- package/dist/testing/drizzle-test.module.js.map +1 -0
- package/dist/testing/mock-client.d.ts +2 -0
- package/dist/testing/mock-client.js +11 -0
- package/dist/testing/mock-client.js.map +1 -0
- package/dist/tokens.d.ts +6 -0
- package/dist/tokens.js +37 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +101 -0
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @nest-native/drizzle
|
|
2
|
+
|
|
3
|
+
Nest-native Drizzle ORM integration with `DrizzleModule`, `@InjectDrizzle()`,
|
|
4
|
+
`@DrizzleRepository()`, transaction decorator bridges, and testing helpers.
|
|
5
|
+
|
|
6
|
+
See the repository
|
|
7
|
+
[README](https://github.com/nest-native/nest-drizzle-native#readme) and
|
|
8
|
+
[documentation](https://nest-native.github.io/nest-drizzle-native/)
|
|
9
|
+
for quick-start examples, transactions, testing, quality gates, and support
|
|
10
|
+
policy.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDrizzleConnection = resolveDrizzleConnection;
|
|
4
|
+
async function resolveDrizzleConnection(connection) {
|
|
5
|
+
if (typeof connection === 'function') {
|
|
6
|
+
return await connection();
|
|
7
|
+
}
|
|
8
|
+
return connection;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=connection.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.util.js","sourceRoot":"","sources":["../../client/connection.util.ts"],"names":[],"mappings":";;AAEA,4DAQC;AARM,KAAK,UAAU,wBAAwB,CAC5C,UAAsC;IAEtC,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC;QACrC,OAAO,MAAO,UAA+C,EAAE,CAAC;IAClE,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
export declare class DrizzleConnectionManager<TClient = unknown> implements OnModuleDestroy {
|
|
3
|
+
private readonly client;
|
|
4
|
+
private readonly shutdown?;
|
|
5
|
+
constructor(client: TClient, shutdown?: ((client: TClient) => void | Promise<void>) | undefined);
|
|
6
|
+
getClient(): TClient;
|
|
7
|
+
onModuleDestroy(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DrizzleConnectionManager = void 0;
|
|
4
|
+
class DrizzleConnectionManager {
|
|
5
|
+
constructor(client, shutdown) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
this.shutdown = shutdown;
|
|
8
|
+
}
|
|
9
|
+
getClient() {
|
|
10
|
+
return this.client;
|
|
11
|
+
}
|
|
12
|
+
async onModuleDestroy() {
|
|
13
|
+
await this.shutdown?.(this.client);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.DrizzleConnectionManager = DrizzleConnectionManager;
|
|
17
|
+
//# sourceMappingURL=drizzle-connection.manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-connection.manager.js","sourceRoot":"","sources":["../../client/drizzle-connection.manager.ts"],"names":[],"mappings":";;;AAEA,MAAa,wBAAwB;IAGnC,YACmB,MAAe,EACf,QAAoD;QADpD,WAAM,GAAN,MAAM,CAAS;QACf,aAAQ,GAAR,QAAQ,CAA4C;IACpE,CAAC;IAEJ,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACF;AAfD,4DAeC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const DEFAULT_DRIZZLE_CONNECTION_NAME = "default";
|
|
2
|
+
export declare const DRIZZLE_CLIENT = "DRIZZLE_CLIENT";
|
|
3
|
+
export declare const DRIZZLE_CONNECTION_MANAGER = "DRIZZLE_CONNECTION_MANAGER";
|
|
4
|
+
export declare const DRIZZLE_MODULE_OPTIONS = "DRIZZLE_MODULE_OPTIONS";
|
|
5
|
+
export declare const DRIZZLE_REPOSITORY_METADATA = "drizzle:repository";
|
|
6
|
+
export declare const DRIZZLE_SCHEMA = "DRIZZLE_SCHEMA";
|
|
7
|
+
export declare const DRIZZLE_TRANSACTION = "DRIZZLE_TRANSACTION";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DRIZZLE_TRANSACTION = exports.DRIZZLE_SCHEMA = exports.DRIZZLE_REPOSITORY_METADATA = exports.DRIZZLE_MODULE_OPTIONS = exports.DRIZZLE_CONNECTION_MANAGER = exports.DRIZZLE_CLIENT = exports.DEFAULT_DRIZZLE_CONNECTION_NAME = void 0;
|
|
4
|
+
exports.DEFAULT_DRIZZLE_CONNECTION_NAME = 'default';
|
|
5
|
+
exports.DRIZZLE_CLIENT = 'DRIZZLE_CLIENT';
|
|
6
|
+
exports.DRIZZLE_CONNECTION_MANAGER = 'DRIZZLE_CONNECTION_MANAGER';
|
|
7
|
+
exports.DRIZZLE_MODULE_OPTIONS = 'DRIZZLE_MODULE_OPTIONS';
|
|
8
|
+
exports.DRIZZLE_REPOSITORY_METADATA = 'drizzle:repository';
|
|
9
|
+
exports.DRIZZLE_SCHEMA = 'DRIZZLE_SCHEMA';
|
|
10
|
+
exports.DRIZZLE_TRANSACTION = 'DRIZZLE_TRANSACTION';
|
|
11
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,+BAA+B,GAAG,SAAS,CAAC;AAC5C,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAClC,QAAA,0BAA0B,GAAG,4BAA4B,CAAC;AAC1D,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAClD,QAAA,2BAA2B,GAAG,oBAAoB,CAAC;AACnD,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAClC,QAAA,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DrizzleRepositoryMetadata, DrizzleRepositoryOptions } from '../interfaces';
|
|
2
|
+
export declare function DrizzleRepository(options?: string | DrizzleRepositoryOptions): ClassDecorator;
|
|
3
|
+
export declare function getDrizzleRepositoryMetadata(target: object): DrizzleRepositoryMetadata | undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DrizzleRepository = DrizzleRepository;
|
|
4
|
+
exports.getDrizzleRepositoryMetadata = getDrizzleRepositoryMetadata;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const tokens_1 = require("../tokens");
|
|
8
|
+
function DrizzleRepository(options) {
|
|
9
|
+
return target => {
|
|
10
|
+
const repositoryOptions = normalizeRepositoryOptions(options);
|
|
11
|
+
(0, common_1.Injectable)()(target);
|
|
12
|
+
Reflect.defineMetadata(constants_1.DRIZZLE_REPOSITORY_METADATA, repositoryOptions, target);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function getDrizzleRepositoryMetadata(target) {
|
|
16
|
+
return Reflect.getMetadata(constants_1.DRIZZLE_REPOSITORY_METADATA, target);
|
|
17
|
+
}
|
|
18
|
+
function normalizeRepositoryOptions(options) {
|
|
19
|
+
const connectionName = typeof options === 'string'
|
|
20
|
+
? options
|
|
21
|
+
: options?.connectionName;
|
|
22
|
+
return {
|
|
23
|
+
connectionName: (0, tokens_1.normalizeDrizzleConnectionName)(connectionName),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=drizzle-repository.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-repository.decorator.js","sourceRoot":"","sources":["../../decorators/drizzle-repository.decorator.ts"],"names":[],"mappings":";;AAUA,8CAYC;AAED,oEAIC;AA5BD,2CAA4C;AAC5C,4CAEsB;AAKtB,sCAA2D;AAE3D,SAAgB,iBAAiB,CAC/B,OAA2C;IAE3C,OAAO,MAAM,CAAC,EAAE;QACd,MAAM,iBAAiB,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC;QAC9D,IAAA,mBAAU,GAAE,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,CAAC,cAAc,CACpB,uCAA2B,EAC3B,iBAAiB,EACjB,MAAM,CACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,4BAA4B,CAC1C,MAAc;IAEd,OAAO,OAAO,CAAC,WAAW,CAAC,uCAA2B,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,0BAA0B,CACjC,OAA2C;IAE3C,MAAM,cAAc,GAAG,OAAO,OAAO,KAAK,QAAQ;QAChD,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO,EAAE,cAAc,CAAC;IAE5B,OAAO;QACL,cAAc,EAAE,IAAA,uCAA8B,EAAC,cAAc,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectDrizzle = InjectDrizzle;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tokens_1 = require("../tokens");
|
|
6
|
+
function InjectDrizzle(connectionName) {
|
|
7
|
+
return (0, common_1.Inject)((0, tokens_1.getDrizzleClientToken)(connectionName));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=inject-drizzle.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-drizzle.decorator.js","sourceRoot":"","sources":["../../decorators/inject-drizzle.decorator.ts"],"names":[],"mappings":";;AAGA,sCAEC;AALD,2CAAwC;AACxC,sCAAkD;AAElD,SAAgB,aAAa,CAAC,cAAuB;IACnD,OAAO,IAAA,eAAM,EAAC,IAAA,8BAAqB,EAAC,cAAc,CAAC,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectTransaction = InjectTransaction;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tokens_1 = require("../tokens");
|
|
6
|
+
function InjectTransaction(connectionName) {
|
|
7
|
+
const clsDecorator = loadClsInjectTransaction();
|
|
8
|
+
if (clsDecorator) {
|
|
9
|
+
return clsDecorator(connectionName);
|
|
10
|
+
}
|
|
11
|
+
return (0, common_1.Inject)((0, tokens_1.getDrizzleTransactionToken)(connectionName));
|
|
12
|
+
}
|
|
13
|
+
function loadClsInjectTransaction() {
|
|
14
|
+
try {
|
|
15
|
+
const transactionalPackage = require('@nestjs-cls/transactional');
|
|
16
|
+
const decorator = transactionalPackage.InjectTransaction;
|
|
17
|
+
return typeof decorator === 'function'
|
|
18
|
+
? decorator
|
|
19
|
+
: undefined;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (isModuleNotFoundError(error)) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function isModuleNotFoundError(error) {
|
|
29
|
+
return (typeof error === 'object' &&
|
|
30
|
+
error !== null &&
|
|
31
|
+
'code' in error &&
|
|
32
|
+
error.code === 'MODULE_NOT_FOUND');
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=inject-transaction.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-transaction.decorator.js","sourceRoot":"","sources":["../../decorators/inject-transaction.decorator.ts"],"names":[],"mappings":";;AAKA,8CAUC;AAfD,2CAAwC;AACxC,sCAAuD;AAIvD,SAAgB,iBAAiB,CAC/B,cAAuB;IAEvB,MAAM,YAAY,GAAG,wBAAwB,EAAE,CAAC;IAEhD,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC,cAAc,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,IAAA,eAAM,EAAC,IAAA,mCAA0B,EAAC,cAAc,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,wBAAwB;IAC/B,IAAI,CAAC;QACH,MAAM,oBAAoB,GAAG,OAAO,CAAC,2BAA2B,CAG/D,CAAC;QACF,MAAM,SAAS,GAAG,oBAAoB,CAAC,iBAAiB,CAAC;QACzD,OAAO,OAAO,SAAS,KAAK,UAAU;YACpC,CAAC,CAAC,SAAqC;YACvC,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACd,KAA4B,CAAC,IAAI,KAAK,kBAAkB,CAC1D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transactional = Transactional;
|
|
4
|
+
function Transactional(...args) {
|
|
5
|
+
return loadTransactionalDecorator()(...args);
|
|
6
|
+
}
|
|
7
|
+
function loadTransactionalDecorator() {
|
|
8
|
+
const module = loadOptionalTransactionalPackage();
|
|
9
|
+
const transactional = module?.Transactional;
|
|
10
|
+
if (typeof transactional !== 'function') {
|
|
11
|
+
throw new Error('Transactional support requires @nestjs-cls/transactional. Install and configure that package before using @Transactional().');
|
|
12
|
+
}
|
|
13
|
+
return transactional;
|
|
14
|
+
}
|
|
15
|
+
function loadOptionalTransactionalPackage() {
|
|
16
|
+
try {
|
|
17
|
+
return require('@nestjs-cls/transactional');
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (isModuleNotFoundError(error)) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function isModuleNotFoundError(error) {
|
|
27
|
+
return (typeof error === 'object' &&
|
|
28
|
+
error !== null &&
|
|
29
|
+
'code' in error &&
|
|
30
|
+
error.code === 'MODULE_NOT_FOUND');
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=transactional.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactional.decorator.js","sourceRoot":"","sources":["../../decorators/transactional.decorator.ts"],"names":[],"mappings":";;AAGA,sCAEC;AAFD,SAAgB,aAAa,CAAC,GAAG,IAAe;IAC9C,OAAO,0BAA0B,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,0BAA0B;IACjC,MAAM,MAAM,GAAG,gCAAgC,EAAE,CAAC;IAClD,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,CAAC;IAE5C,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,6HAA6H,CAC9H,CAAC;IACJ,CAAC;IAED,OAAO,aAAqC,CAAC;AAC/C,CAAC;AAED,SAAS,gCAAgC;IACvC,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,2BAA2B,CAA4B,CAAC;IACzE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACd,KAA4B,CAAC,IAAI,KAAK,kBAAkB,CAC1D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { DrizzleModuleAsyncOptions, DrizzleModuleOptions, DrizzleRepositoryClass } from './interfaces';
|
|
3
|
+
export declare class DrizzleModule {
|
|
4
|
+
static forRoot<TClient = unknown>(options: DrizzleModuleOptions<TClient>): DynamicModule;
|
|
5
|
+
static forRootAsync<TClient = unknown>(options: DrizzleModuleAsyncOptions<TClient>): DynamicModule;
|
|
6
|
+
static forFeature(repositories?: DrizzleRepositoryClass[]): DynamicModule;
|
|
7
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var DrizzleModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DrizzleModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const drizzle_connection_manager_1 = require("./client/drizzle-connection.manager");
|
|
13
|
+
const connection_util_1 = require("./client/connection.util");
|
|
14
|
+
const tokens_1 = require("./tokens");
|
|
15
|
+
let DrizzleModule = DrizzleModule_1 = class DrizzleModule {
|
|
16
|
+
static forRoot(options) {
|
|
17
|
+
const connectionName = options.connectionName;
|
|
18
|
+
const providers = createConnectionProviders(connectionName);
|
|
19
|
+
return {
|
|
20
|
+
module: DrizzleModule_1,
|
|
21
|
+
global: options.isGlobal ?? true,
|
|
22
|
+
providers: [
|
|
23
|
+
{
|
|
24
|
+
provide: (0, tokens_1.getDrizzleOptionsToken)(connectionName),
|
|
25
|
+
useValue: options,
|
|
26
|
+
},
|
|
27
|
+
...providers,
|
|
28
|
+
],
|
|
29
|
+
exports: [
|
|
30
|
+
(0, tokens_1.getDrizzleClientToken)(connectionName),
|
|
31
|
+
(0, tokens_1.getDrizzleSchemaToken)(connectionName),
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static forRootAsync(options) {
|
|
36
|
+
const connectionName = options.connectionName;
|
|
37
|
+
const providers = createConnectionProviders(connectionName);
|
|
38
|
+
return {
|
|
39
|
+
module: DrizzleModule_1,
|
|
40
|
+
global: options.isGlobal ?? true,
|
|
41
|
+
imports: options.imports ?? [],
|
|
42
|
+
providers: [
|
|
43
|
+
{
|
|
44
|
+
provide: (0, tokens_1.getDrizzleOptionsToken)(connectionName),
|
|
45
|
+
useFactory: options.useFactory,
|
|
46
|
+
inject: options.inject ?? [],
|
|
47
|
+
},
|
|
48
|
+
...(options.extraProviders ?? []),
|
|
49
|
+
...providers,
|
|
50
|
+
],
|
|
51
|
+
exports: [
|
|
52
|
+
(0, tokens_1.getDrizzleClientToken)(connectionName),
|
|
53
|
+
(0, tokens_1.getDrizzleSchemaToken)(connectionName),
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
static forFeature(repositories = []) {
|
|
58
|
+
return {
|
|
59
|
+
module: DrizzleModule_1,
|
|
60
|
+
providers: [...repositories],
|
|
61
|
+
exports: [...repositories],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
exports.DrizzleModule = DrizzleModule;
|
|
66
|
+
exports.DrizzleModule = DrizzleModule = DrizzleModule_1 = __decorate([
|
|
67
|
+
(0, common_1.Module)({})
|
|
68
|
+
], DrizzleModule);
|
|
69
|
+
function createConnectionProviders(connectionName) {
|
|
70
|
+
const optionsToken = (0, tokens_1.getDrizzleOptionsToken)(connectionName);
|
|
71
|
+
const managerToken = (0, tokens_1.getDrizzleConnectionManagerToken)(connectionName);
|
|
72
|
+
const clientToken = (0, tokens_1.getDrizzleClientToken)(connectionName);
|
|
73
|
+
const schemaToken = (0, tokens_1.getDrizzleSchemaToken)(connectionName);
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
provide: managerToken,
|
|
77
|
+
useFactory: async (options) => {
|
|
78
|
+
const client = await (0, connection_util_1.resolveDrizzleConnection)(options.connection);
|
|
79
|
+
return new drizzle_connection_manager_1.DrizzleConnectionManager(client, options.shutdown);
|
|
80
|
+
},
|
|
81
|
+
inject: [optionsToken],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
provide: clientToken,
|
|
85
|
+
useFactory: (manager) => manager.getClient(),
|
|
86
|
+
inject: [managerToken],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
provide: schemaToken,
|
|
90
|
+
useFactory: (options) => options.schema,
|
|
91
|
+
inject: [optionsToken],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=drizzle.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.module.js","sourceRoot":"","sources":["../drizzle.module.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface DrizzleErrorMappingOptions {
|
|
2
|
+
uniqueMessage?: string;
|
|
3
|
+
foreignKeyMessage?: string;
|
|
4
|
+
notNullMessage?: string;
|
|
5
|
+
fallbackMessage?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function mapDrizzleError(error: unknown, options?: DrizzleErrorMappingOptions): Error;
|
|
8
|
+
export declare function isUniqueConstraintError(error: unknown): boolean;
|
|
9
|
+
export declare function isForeignKeyConstraintError(error: unknown): boolean;
|
|
10
|
+
export declare function isNotNullConstraintError(error: unknown): boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapDrizzleError = mapDrizzleError;
|
|
4
|
+
exports.isUniqueConstraintError = isUniqueConstraintError;
|
|
5
|
+
exports.isForeignKeyConstraintError = isForeignKeyConstraintError;
|
|
6
|
+
exports.isNotNullConstraintError = isNotNullConstraintError;
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
function mapDrizzleError(error, options = {}) {
|
|
9
|
+
if (isUniqueConstraintError(error)) {
|
|
10
|
+
return new common_1.ConflictException(options.uniqueMessage ?? 'Resource already exists.');
|
|
11
|
+
}
|
|
12
|
+
if (isForeignKeyConstraintError(error)) {
|
|
13
|
+
return new common_1.BadRequestException(options.foreignKeyMessage ?? 'Related resource does not exist.');
|
|
14
|
+
}
|
|
15
|
+
if (isNotNullConstraintError(error)) {
|
|
16
|
+
return new common_1.BadRequestException(options.notNullMessage ?? 'Required value is missing.');
|
|
17
|
+
}
|
|
18
|
+
return error instanceof Error
|
|
19
|
+
? error
|
|
20
|
+
: new common_1.InternalServerErrorException(options.fallbackMessage ?? 'Database operation failed.');
|
|
21
|
+
}
|
|
22
|
+
function isUniqueConstraintError(error) {
|
|
23
|
+
return errorHasAnyCode(error, ['23505', 'ER_DUP_ENTRY', 'SQLITE_CONSTRAINT_UNIQUE']);
|
|
24
|
+
}
|
|
25
|
+
function isForeignKeyConstraintError(error) {
|
|
26
|
+
return errorHasAnyCode(error, ['23503', 'ER_NO_REFERENCED_ROW_2', 'SQLITE_CONSTRAINT_FOREIGNKEY']);
|
|
27
|
+
}
|
|
28
|
+
function isNotNullConstraintError(error) {
|
|
29
|
+
return errorHasAnyCode(error, ['23502', 'ER_BAD_NULL_ERROR', 'SQLITE_CONSTRAINT_NOTNULL']);
|
|
30
|
+
}
|
|
31
|
+
function errorHasAnyCode(error, expectedCodes) {
|
|
32
|
+
const codes = collectErrorCodes(error);
|
|
33
|
+
return codes.some(code => expectedCodes.includes(code));
|
|
34
|
+
}
|
|
35
|
+
function collectErrorCodes(error) {
|
|
36
|
+
if (typeof error !== 'object' || error === null) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const maybeError = error;
|
|
40
|
+
const currentCodes = [
|
|
41
|
+
maybeError.code,
|
|
42
|
+
maybeError.errno,
|
|
43
|
+
maybeError.extendedCode,
|
|
44
|
+
]
|
|
45
|
+
.filter((code) => typeof code === 'string' || typeof code === 'number')
|
|
46
|
+
.map(code => String(code));
|
|
47
|
+
return [
|
|
48
|
+
...currentCodes,
|
|
49
|
+
...collectErrorCodes(maybeError.cause),
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=drizzle-error.mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-error.mapper.js","sourceRoot":"","sources":["../../errors/drizzle-error.mapper.ts"],"names":[],"mappings":";;AAaA,0CA2BC;AAED,0DAEC;AAED,kEAEC;AAED,4DAEC;AApDD,2CAIwB;AASxB,SAAgB,eAAe,CAC7B,KAAc,EACd,UAAsC,EAAE;IAExC,IAAI,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,IAAI,0BAAiB,CAC1B,OAAO,CAAC,aAAa,IAAI,0BAA0B,CACpD,CAAC;IACJ,CAAC;IAED,IAAI,2BAA2B,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,IAAI,4BAAmB,CAC5B,OAAO,CAAC,iBAAiB,IAAI,kCAAkC,CAChE,CAAC;IACJ,CAAC;IAED,IAAI,wBAAwB,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,IAAI,4BAAmB,CAC5B,OAAO,CAAC,cAAc,IAAI,4BAA4B,CACvD,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,YAAY,KAAK;QAC3B,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,IAAI,qCAA4B,CAChC,OAAO,CAAC,eAAe,IAAI,4BAA4B,CACxD,CAAC;AACN,CAAC;AAED,SAAgB,uBAAuB,CAAC,KAAc;IACpD,OAAO,eAAe,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,0BAA0B,CAAC,CAAC,CAAC;AACvF,CAAC;AAED,SAAgB,2BAA2B,CAAC,KAAc;IACxD,OAAO,eAAe,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,wBAAwB,EAAE,8BAA8B,CAAC,CAAC,CAAC;AACrG,CAAC;AAED,SAAgB,wBAAwB,CAAC,KAAc;IACrD,OAAO,eAAe,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,aAAuB;IAC9D,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,UAAU,GAAG,KAAgC,CAAC;IACpD,MAAM,YAAY,GAAG;QACnB,UAAU,CAAC,IAAI;QACf,UAAU,CAAC,KAAK;QAChB,UAAU,CAAC,YAAY;KACxB;SACE,MAAM,CAAC,CAAC,IAAI,EAA2B,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC;SAC/F,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7B,OAAO;QACL,GAAG,YAAY;QACf,GAAG,iBAAiB,CAAC,UAAU,CAAC,KAAK,CAAC;KACvC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './client/drizzle-connection.manager';
|
|
2
|
+
export * from './constants';
|
|
3
|
+
export * from './decorators/drizzle-repository.decorator';
|
|
4
|
+
export * from './decorators/inject-drizzle.decorator';
|
|
5
|
+
export * from './decorators/inject-transaction.decorator';
|
|
6
|
+
export * from './decorators/transactional.decorator';
|
|
7
|
+
export * from './drizzle.module';
|
|
8
|
+
export * from './errors/drizzle-error.mapper';
|
|
9
|
+
export * from './interfaces';
|
|
10
|
+
export * from './testing/drizzle-test.module';
|
|
11
|
+
export * from './testing/mock-client';
|
|
12
|
+
export * from './tokens';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client/drizzle-connection.manager"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./decorators/drizzle-repository.decorator"), exports);
|
|
20
|
+
__exportStar(require("./decorators/inject-drizzle.decorator"), exports);
|
|
21
|
+
__exportStar(require("./decorators/inject-transaction.decorator"), exports);
|
|
22
|
+
__exportStar(require("./decorators/transactional.decorator"), exports);
|
|
23
|
+
__exportStar(require("./drizzle.module"), exports);
|
|
24
|
+
__exportStar(require("./errors/drizzle-error.mapper"), exports);
|
|
25
|
+
__exportStar(require("./interfaces"), exports);
|
|
26
|
+
__exportStar(require("./testing/drizzle-test.module"), exports);
|
|
27
|
+
__exportStar(require("./testing/mock-client"), exports);
|
|
28
|
+
__exportStar(require("./tokens"), exports);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,8CAA4B;AAC5B,4EAA0D;AAC1D,wEAAsD;AACtD,4EAA0D;AAC1D,uEAAqD;AACrD,mDAAiC;AACjC,gEAA8C;AAC9C,+CAA6B;AAC7B,gEAA8C;AAC9C,wDAAsC;AACtC,2CAAyB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ModuleMetadata, Provider, Type } from '@nestjs/common';
|
|
2
|
+
export type DrizzleSchema = Record<string, unknown>;
|
|
3
|
+
export type DrizzleConnection<TClient = unknown> = TClient | (() => TClient | Promise<TClient>);
|
|
4
|
+
export interface DrizzleModuleOptions<TClient = unknown, TSchema extends DrizzleSchema = DrizzleSchema> {
|
|
5
|
+
/**
|
|
6
|
+
* Standard Drizzle schema object. It is stored as-is and never transformed.
|
|
7
|
+
*/
|
|
8
|
+
schema?: TSchema;
|
|
9
|
+
/**
|
|
10
|
+
* Existing Drizzle client or a factory that creates one.
|
|
11
|
+
*/
|
|
12
|
+
connection: DrizzleConnection<TClient>;
|
|
13
|
+
/**
|
|
14
|
+
* Optional connection name for applications with multiple Drizzle clients.
|
|
15
|
+
*/
|
|
16
|
+
connectionName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to register this module globally.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
isGlobal?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Optional shutdown hook for closing database drivers owned by this module.
|
|
24
|
+
*/
|
|
25
|
+
shutdown?: (client: TClient) => void | Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export interface DrizzleModuleAsyncOptions<TClient = unknown, TSchema extends DrizzleSchema = DrizzleSchema> extends Pick<ModuleMetadata, 'imports'> {
|
|
28
|
+
connectionName?: string;
|
|
29
|
+
inject?: any[];
|
|
30
|
+
extraProviders?: Provider[];
|
|
31
|
+
isGlobal?: boolean;
|
|
32
|
+
useFactory: (...args: any[]) => DrizzleModuleOptions<TClient, TSchema> | Promise<DrizzleModuleOptions<TClient, TSchema>>;
|
|
33
|
+
}
|
|
34
|
+
export interface DrizzleRepositoryOptions {
|
|
35
|
+
connectionName?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface DrizzleRepositoryMetadata {
|
|
38
|
+
connectionName: string;
|
|
39
|
+
}
|
|
40
|
+
export type DrizzleRepositoryClass<TRepository = unknown> = Type<TRepository>;
|
|
41
|
+
export interface DrizzleTestModuleOptions<TClient = unknown, TSchema extends DrizzleSchema = DrizzleSchema> {
|
|
42
|
+
client: TClient;
|
|
43
|
+
schema?: TSchema;
|
|
44
|
+
connectionName?: string;
|
|
45
|
+
isGlobal?: boolean;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { DrizzleRepositoryClass, DrizzleTestModuleOptions } from '../interfaces';
|
|
3
|
+
export declare class DrizzleTestModule {
|
|
4
|
+
static forRoot<TClient = unknown>(options: DrizzleTestModuleOptions<TClient>): DynamicModule;
|
|
5
|
+
static forFeature(repositories?: DrizzleRepositoryClass[]): DynamicModule;
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DrizzleTestModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const drizzle_module_1 = require("../drizzle.module");
|
|
12
|
+
let DrizzleTestModule = class DrizzleTestModule {
|
|
13
|
+
static forRoot(options) {
|
|
14
|
+
return drizzle_module_1.DrizzleModule.forRoot({
|
|
15
|
+
connection: options.client,
|
|
16
|
+
connectionName: options.connectionName,
|
|
17
|
+
isGlobal: options.isGlobal,
|
|
18
|
+
schema: options.schema,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
static forFeature(repositories = []) {
|
|
22
|
+
return drizzle_module_1.DrizzleModule.forFeature(repositories);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.DrizzleTestModule = DrizzleTestModule;
|
|
26
|
+
exports.DrizzleTestModule = DrizzleTestModule = __decorate([
|
|
27
|
+
(0, common_1.Module)({})
|
|
28
|
+
], DrizzleTestModule);
|
|
29
|
+
//# sourceMappingURL=drizzle-test.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-test.module.js","sourceRoot":"","sources":["../../testing/drizzle-test.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAuD;AACvD,sDAAkD;AAO3C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CACZ,OAA0C;QAE1C,OAAO,8BAAa,CAAC,OAAO,CAAC;YAC3B,UAAU,EAAE,OAAO,CAAC,MAAM;YAC1B,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,UAAU,CACf,eAAyC,EAAE;QAE3C,OAAO,8BAAa,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;CACF,CAAA;AAjBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,iBAAiB,CAiB7B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function createDrizzleMockClient<TClient extends Record<PropertyKey, unknown> = Record<string, unknown>>(overrides?: Partial<TClient>): TClient;
|
|
2
|
+
export declare function createDrizzleRepositoryMock<TRepository extends Record<PropertyKey, unknown>>(methods: Partial<TRepository>): TRepository;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDrizzleMockClient = createDrizzleMockClient;
|
|
4
|
+
exports.createDrizzleRepositoryMock = createDrizzleRepositoryMock;
|
|
5
|
+
function createDrizzleMockClient(overrides = {}) {
|
|
6
|
+
return { ...overrides };
|
|
7
|
+
}
|
|
8
|
+
function createDrizzleRepositoryMock(methods) {
|
|
9
|
+
return { ...methods };
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=mock-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-client.js","sourceRoot":"","sources":["../../testing/mock-client.ts"],"names":[],"mappings":";;AAAA,0DAIC;AAED,kEAIC;AAVD,SAAgB,uBAAuB,CAErC,YAA8B,EAAE;IAChC,OAAO,EAAE,GAAG,SAAS,EAAa,CAAC;AACrC,CAAC;AAED,SAAgB,2BAA2B,CAEzC,OAA6B;IAC7B,OAAO,EAAE,GAAG,OAAO,EAAiB,CAAC;AACvC,CAAC"}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function normalizeDrizzleConnectionName(connectionName?: string): string;
|
|
2
|
+
export declare function getDrizzleClientToken(connectionName?: string): string;
|
|
3
|
+
export declare function getDrizzleConnectionManagerToken(connectionName?: string): string;
|
|
4
|
+
export declare function getDrizzleOptionsToken(connectionName?: string): string;
|
|
5
|
+
export declare function getDrizzleSchemaToken(connectionName?: string): string;
|
|
6
|
+
export declare function getDrizzleTransactionToken(connectionName?: string): string;
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeDrizzleConnectionName = normalizeDrizzleConnectionName;
|
|
4
|
+
exports.getDrizzleClientToken = getDrizzleClientToken;
|
|
5
|
+
exports.getDrizzleConnectionManagerToken = getDrizzleConnectionManagerToken;
|
|
6
|
+
exports.getDrizzleOptionsToken = getDrizzleOptionsToken;
|
|
7
|
+
exports.getDrizzleSchemaToken = getDrizzleSchemaToken;
|
|
8
|
+
exports.getDrizzleTransactionToken = getDrizzleTransactionToken;
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
function normalizeDrizzleConnectionName(connectionName) {
|
|
11
|
+
const normalized = connectionName?.trim();
|
|
12
|
+
return normalized && normalized.length > 0
|
|
13
|
+
? normalized
|
|
14
|
+
: constants_1.DEFAULT_DRIZZLE_CONNECTION_NAME;
|
|
15
|
+
}
|
|
16
|
+
function getDrizzleClientToken(connectionName) {
|
|
17
|
+
return buildDrizzleToken(constants_1.DRIZZLE_CLIENT, connectionName);
|
|
18
|
+
}
|
|
19
|
+
function getDrizzleConnectionManagerToken(connectionName) {
|
|
20
|
+
return buildDrizzleToken(constants_1.DRIZZLE_CONNECTION_MANAGER, connectionName);
|
|
21
|
+
}
|
|
22
|
+
function getDrizzleOptionsToken(connectionName) {
|
|
23
|
+
return buildDrizzleToken(constants_1.DRIZZLE_MODULE_OPTIONS, connectionName);
|
|
24
|
+
}
|
|
25
|
+
function getDrizzleSchemaToken(connectionName) {
|
|
26
|
+
return buildDrizzleToken(constants_1.DRIZZLE_SCHEMA, connectionName);
|
|
27
|
+
}
|
|
28
|
+
function getDrizzleTransactionToken(connectionName) {
|
|
29
|
+
return buildDrizzleToken(constants_1.DRIZZLE_TRANSACTION, connectionName);
|
|
30
|
+
}
|
|
31
|
+
function buildDrizzleToken(prefix, connectionName) {
|
|
32
|
+
const normalized = normalizeDrizzleConnectionName(connectionName);
|
|
33
|
+
return normalized === constants_1.DEFAULT_DRIZZLE_CONNECTION_NAME
|
|
34
|
+
? prefix
|
|
35
|
+
: `${prefix}:${normalized}`;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../tokens.ts"],"names":[],"mappings":";;AASA,wEAKC;AAED,sDAEC;AAED,4EAEC;AAED,wDAEC;AAED,sDAEC;AAED,gEAEC;AAlCD,2CAOqB;AAErB,SAAgB,8BAA8B,CAAC,cAAuB;IACpE,MAAM,UAAU,GAAG,cAAc,EAAE,IAAI,EAAE,CAAC;IAC1C,OAAO,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;QACxC,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,2CAA+B,CAAC;AACtC,CAAC;AAED,SAAgB,qBAAqB,CAAC,cAAuB;IAC3D,OAAO,iBAAiB,CAAC,0BAAc,EAAE,cAAc,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,gCAAgC,CAAC,cAAuB;IACtE,OAAO,iBAAiB,CAAC,sCAA0B,EAAE,cAAc,CAAC,CAAC;AACvE,CAAC;AAED,SAAgB,sBAAsB,CAAC,cAAuB;IAC5D,OAAO,iBAAiB,CAAC,kCAAsB,EAAE,cAAc,CAAC,CAAC;AACnE,CAAC;AAED,SAAgB,qBAAqB,CAAC,cAAuB;IAC3D,OAAO,iBAAiB,CAAC,0BAAc,EAAE,cAAc,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,0BAA0B,CAAC,cAAuB;IAChE,OAAO,iBAAiB,CAAC,+BAAmB,EAAE,cAAc,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc,EAAE,cAAuB;IAChE,MAAM,UAAU,GAAG,8BAA8B,CAAC,cAAc,CAAC,CAAC;IAClE,OAAO,UAAU,KAAK,2CAA+B;QACnD,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,GAAG,MAAM,IAAI,UAAU,EAAE,CAAC;AAChC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nest-native/drizzle",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Nest-native Drizzle ORM integration with DI, repositories, and transaction decorators",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nestjs",
|
|
7
|
+
"drizzle",
|
|
8
|
+
"drizzle-orm",
|
|
9
|
+
"orm",
|
|
10
|
+
"sql",
|
|
11
|
+
"decorators",
|
|
12
|
+
"dependency-injection",
|
|
13
|
+
"transactions",
|
|
14
|
+
"typescript"
|
|
15
|
+
],
|
|
16
|
+
"author": "Rodrigo Nogueira",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"homepage": "https://github.com/nest-native/nest-drizzle-native#readme",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/nest-native/nest-drizzle-native.git",
|
|
22
|
+
"directory": "packages/drizzle"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/nest-native/nest-drizzle-native/issues"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"require": "./dist/index.js",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/**/*.d.ts",
|
|
39
|
+
"dist/**/*.js",
|
|
40
|
+
"dist/**/*.js.map"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
50
|
+
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
51
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@libsql/client": "*",
|
|
55
|
+
"@nestjs-cls/transactional": "*",
|
|
56
|
+
"@nestjs/common": "^11.0.0",
|
|
57
|
+
"@nestjs/core": "^11.0.0",
|
|
58
|
+
"@nestjs/swagger": "^11.4.4",
|
|
59
|
+
"better-sqlite3": "*",
|
|
60
|
+
"class-validator": "^0.15.1",
|
|
61
|
+
"drizzle-orm": ">=0.30.0 <2.0.0",
|
|
62
|
+
"drizzle-zod": "*",
|
|
63
|
+
"mysql2": "*",
|
|
64
|
+
"pg": "*",
|
|
65
|
+
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
66
|
+
"rxjs": "^7.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"@libsql/client": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"@nestjs-cls/transactional": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@nestjs/swagger": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"better-sqlite3": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"class-validator": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"drizzle-zod": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"mysql2": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"pg": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"devDependencies": {
|
|
95
|
+
"@nestjs/common": "^11.1.24",
|
|
96
|
+
"@nestjs/core": "^11.1.24",
|
|
97
|
+
"reflect-metadata": "^0.2.2",
|
|
98
|
+
"rxjs": "^7.8.1",
|
|
99
|
+
"typescript": "^6.0.3"
|
|
100
|
+
}
|
|
101
|
+
}
|