@nestjs-cls/transactional-adapter-mongodb 1.1.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +18 -0
- package/dist/src/lib/transactional-adapter-mongodb.d.ts +30 -0
- package/dist/src/lib/transactional-adapter-mongodb.js +25 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ondřej Švanda (Papooch)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/transactional-adapter-mongodb';
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./lib/transactional-adapter-mongodb"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TransactionalAdapter } from '@nestjs-cls/transactional';
|
|
2
|
+
import { ClientSession, ClientSessionOptions, MongoClient, TransactionOptions } from 'mongodb';
|
|
3
|
+
export type MongoDBTransactionOptions = TransactionOptions & {
|
|
4
|
+
/**
|
|
5
|
+
* Options for the encompassing `session` that hosts the transaction.
|
|
6
|
+
*/
|
|
7
|
+
sessionOptions?: ClientSessionOptions;
|
|
8
|
+
};
|
|
9
|
+
export interface MongoDBTransactionalAdapterOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The injection token for the MongoClient instance.
|
|
12
|
+
*/
|
|
13
|
+
mongoClientToken: any;
|
|
14
|
+
/**
|
|
15
|
+
* Default options for the transaction. These will be merged with any transaction-specific options
|
|
16
|
+
* passed to the `@Transactional` decorator or the `TransactionHost#withTransaction` method.
|
|
17
|
+
*/
|
|
18
|
+
defaultTxOptions?: Partial<MongoDBTransactionOptions>;
|
|
19
|
+
}
|
|
20
|
+
export declare class TransactionalAdapterMongoDB implements TransactionalAdapter<MongoClient, ClientSession | undefined, MongoDBTransactionOptions> {
|
|
21
|
+
connectionToken: any;
|
|
22
|
+
defaultTxOptions?: Partial<TransactionOptions>;
|
|
23
|
+
constructor(options: MongoDBTransactionalAdapterOptions);
|
|
24
|
+
/** cannot proxy an `undefined` value */
|
|
25
|
+
supportsTransactionProxy: boolean;
|
|
26
|
+
optionsFactory(mongoClient: MongoClient): {
|
|
27
|
+
wrapWithTransaction: (options: MongoDBTransactionOptions, fn: (...args: any[]) => Promise<any>, setTx: (tx?: ClientSession) => void) => Promise<any>;
|
|
28
|
+
getFallbackInstance: () => undefined;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionalAdapterMongoDB = void 0;
|
|
4
|
+
class TransactionalAdapterMongoDB {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
/** cannot proxy an `undefined` value */
|
|
7
|
+
this.supportsTransactionProxy = false;
|
|
8
|
+
this.connectionToken = options.mongoClientToken;
|
|
9
|
+
this.defaultTxOptions = options.defaultTxOptions;
|
|
10
|
+
}
|
|
11
|
+
optionsFactory(mongoClient) {
|
|
12
|
+
return {
|
|
13
|
+
wrapWithTransaction: async (options, fn, setTx) => {
|
|
14
|
+
var _a;
|
|
15
|
+
return mongoClient.withSession((_a = options.sessionOptions) !== null && _a !== void 0 ? _a : {}, async (session) => session.withTransaction(() => {
|
|
16
|
+
setTx(session);
|
|
17
|
+
return fn();
|
|
18
|
+
}, options));
|
|
19
|
+
},
|
|
20
|
+
getFallbackInstance: () => undefined,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TransactionalAdapterMongoDB = TransactionalAdapterMongoDB;
|
|
25
|
+
//# sourceMappingURL=transactional-adapter-mongodb.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nestjs-cls/transactional-adapter-mongodb",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "A mongodb adapter for @nestjs-cls/transactional",
|
|
5
|
+
"author": "papooch",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Papooch/nestjs-cls.git"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://papooch.github.io/nestjs-cls/",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"nest",
|
|
20
|
+
"nestjs",
|
|
21
|
+
"cls",
|
|
22
|
+
"continuation-local-storage",
|
|
23
|
+
"als",
|
|
24
|
+
"AsyncLocalStorage",
|
|
25
|
+
"async_hooks",
|
|
26
|
+
"request context",
|
|
27
|
+
"async context",
|
|
28
|
+
"transaction",
|
|
29
|
+
"transactional",
|
|
30
|
+
"transactional decorator",
|
|
31
|
+
"aop",
|
|
32
|
+
"mongodb"
|
|
33
|
+
],
|
|
34
|
+
"main": "dist/src/index.js",
|
|
35
|
+
"types": "dist/src/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist/src/**/!(*.spec).d.ts",
|
|
38
|
+
"dist/src/**/!(*.spec).js"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"prepack": "cp ../../../LICENSE ./LICENSE",
|
|
42
|
+
"prebuild": "rimraf dist",
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"test": "jest",
|
|
45
|
+
"test:watch": "jest --watch",
|
|
46
|
+
"test:cov": "jest --coverage"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@nestjs-cls/transactional": "^2.4.0",
|
|
50
|
+
"mongodb": "> 6",
|
|
51
|
+
"nestjs-cls": "^4.3.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@nestjs/cli": "^10.0.2",
|
|
55
|
+
"@nestjs/common": "^10.3.7",
|
|
56
|
+
"@nestjs/core": "^10.3.7",
|
|
57
|
+
"@nestjs/testing": "^10.3.7",
|
|
58
|
+
"@types/jest": "^28.1.2",
|
|
59
|
+
"@types/node": "^18.0.0",
|
|
60
|
+
"jest": "^29.7.0",
|
|
61
|
+
"mongodb": "^6.7.0",
|
|
62
|
+
"mongodb-memory-server": "^9.4.0",
|
|
63
|
+
"reflect-metadata": "^0.1.13",
|
|
64
|
+
"rimraf": "^3.0.2",
|
|
65
|
+
"rxjs": "^7.5.5",
|
|
66
|
+
"sqlite3": "^5.1.7",
|
|
67
|
+
"ts-jest": "^29.1.2",
|
|
68
|
+
"ts-loader": "^9.3.0",
|
|
69
|
+
"ts-node": "^10.8.1",
|
|
70
|
+
"tsconfig-paths": "^4.0.0",
|
|
71
|
+
"typescript": "5.0"
|
|
72
|
+
}
|
|
73
|
+
}
|