@nestjs-kitchen/connextion-postgres 2.0.2 → 2.0.4
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/constants.d.ts +7 -9
- package/dist/constants.js +12 -45
- package/dist/define-postgres.d.ts +6 -14
- package/dist/define-postgres.js +42 -62
- package/dist/errors.d.ts +1 -4
- package/dist/errors.js +16 -41
- package/dist/index.d.ts +3 -9
- package/dist/index.js +8 -31
- package/dist/polyfill.d.ts +1 -2
- package/dist/polyfill.js +4 -2
- package/dist/postgres.instance.d.ts +4 -7
- package/dist/postgres.instance.js +192 -207
- package/dist/transaction.d.ts +3 -4
- package/dist/transaction.js +107 -119
- package/dist/types.d.ts +4 -7
- package/dist/types.js +2 -15
- package/dist/utils.d.ts +16 -19
- package/dist/utils.js +224 -272
- package/package.json +7 -6
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface ALSType {
|
|
1
|
+
import type { PoolClient, PoolConfig } from 'pg';
|
|
2
|
+
export type ALSQueryType = Error | true;
|
|
3
|
+
export interface ALSType {
|
|
5
4
|
client: Promise<PoolClient>;
|
|
6
5
|
queries: Promise<ALSQueryType>[];
|
|
7
6
|
}
|
|
8
|
-
type PostgresInstanceOptions = PoolConfig & {
|
|
7
|
+
export type PostgresInstanceOptions = PoolConfig & {
|
|
9
8
|
debug?: boolean | ((data: Record<any, any>) => void);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
export type { ALSQueryType, ALSType, PostgresInstanceOptions };
|
package/dist/types.js
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var types_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(types_exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
declare const
|
|
5
|
-
declare const
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
declare const
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
declare const debugFactroy: (name: string, queryId: string, logger: (data: Record<any, any>) => void) => {
|
|
1
|
+
import { type PoolClient, type Submittable } from 'pg';
|
|
2
|
+
export declare const isSubmittable: (val: any) => val is Submittable;
|
|
3
|
+
export declare const isObject: (val: any) => val is object;
|
|
4
|
+
export declare const normalizeStrings: (strs?: string[]) => string[];
|
|
5
|
+
export declare const plainPromise: <T>(promise: Promise<T> | T) => Promise<[T, undefined] | [undefined, any]>;
|
|
6
|
+
export declare const truncateString: (str: string, maxLength: number) => string;
|
|
7
|
+
export declare const printTable: (logData: Record<string, any>) => string;
|
|
8
|
+
export declare const getCurrentDateStr: () => string;
|
|
9
|
+
export declare const formatArray: (arr?: any) => string;
|
|
10
|
+
export declare const extraceQueryTextAndValues: (...rest: any[]) => [text: string, values: any[]];
|
|
11
|
+
export declare const createDebugLogger: (defaultLogger: (...rest: any) => void, customFormater?: Boolean | ((data: Record<any, any>) => void)) => (data: Record<any, any>) => void;
|
|
12
|
+
export declare const debugFactroy: (name: string, queryId: string, logger: (data: Record<any, any>) => void) => {
|
|
14
13
|
pool: {
|
|
15
14
|
connect: <T extends () => Promise<PoolClient>>(callback: T) => () => Promise<PoolClient>;
|
|
16
15
|
};
|
|
@@ -19,13 +18,11 @@ declare const debugFactroy: (name: string, queryId: string, logger: (data: Recor
|
|
|
19
18
|
release: <T extends (...rest: unknown[]) => void>(callback: T) => (...rest: Parameters<T>) => void;
|
|
20
19
|
};
|
|
21
20
|
};
|
|
22
|
-
declare const copyMethodMetadata: (from: any, to: any) => void;
|
|
23
|
-
declare const getTransactionMetdata: (target: any) => any;
|
|
24
|
-
declare const setTransactionMetdata: (target: any) => void;
|
|
25
|
-
declare const withResolvers: <T>() => {
|
|
21
|
+
export declare const copyMethodMetadata: (from: any, to: any) => void;
|
|
22
|
+
export declare const getTransactionMetdata: (target: any) => any;
|
|
23
|
+
export declare const setTransactionMetdata: (target: any) => void;
|
|
24
|
+
export declare const withResolvers: <T>() => {
|
|
26
25
|
promise: Promise<T>;
|
|
27
26
|
resolve: (value: T | PromiseLike<T>) => void;
|
|
28
27
|
reject: (reason?: any) => void;
|
|
29
28
|
};
|
|
30
|
-
|
|
31
|
-
export { copyMethodMetadata, createDebugLogger, debugFactroy, extraceQueryTextAndValues, formatArray, getCurrentDateStr, getTransactionMetdata, isObject, isSubmittable, normalizeStrings, plainPromise, printTable, setTransactionMetdata, truncateString, withResolvers };
|
package/dist/utils.js
CHANGED
|
@@ -1,278 +1,230 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
4
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return to;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withResolvers = exports.setTransactionMetdata = exports.getTransactionMetdata = exports.copyMethodMetadata = exports.debugFactroy = exports.createDebugLogger = exports.extraceQueryTextAndValues = exports.formatArray = exports.getCurrentDateStr = exports.printTable = exports.truncateString = exports.plainPromise = exports.normalizeStrings = exports.isObject = exports.isSubmittable = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const isSubmittable = (val) => {
|
|
10
|
+
return val && typeof val.submit === 'function';
|
|
19
11
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
result = await promise;
|
|
67
|
-
} catch (error) {
|
|
68
|
-
err = error;
|
|
69
|
-
}
|
|
70
|
-
return [
|
|
71
|
-
result,
|
|
72
|
-
err
|
|
73
|
-
];
|
|
74
|
-
}, "plainPromise");
|
|
75
|
-
const truncateString = /* @__PURE__ */ __name((str, maxLength) => {
|
|
76
|
-
if (str.length <= maxLength) {
|
|
77
|
-
return str;
|
|
78
|
-
}
|
|
79
|
-
const truncatedLength = maxLength - 3;
|
|
80
|
-
if (truncatedLength <= 0) {
|
|
81
|
-
return "...";
|
|
82
|
-
}
|
|
83
|
-
return str.slice(0, truncatedLength) + "...";
|
|
84
|
-
}, "truncateString");
|
|
85
|
-
const printTable = /* @__PURE__ */ __name((logData) => {
|
|
86
|
-
const maxKeyLength = import_constants.MAX_LENGTH / 3;
|
|
87
|
-
const maxValueLength = import_constants.MAX_LENGTH;
|
|
88
|
-
const separatorTop = "\u2500".repeat(maxKeyLength + 2) + "\u252C" + "\u2500".repeat(maxValueLength + 2);
|
|
89
|
-
const separatorBottom = "\u2500".repeat(maxKeyLength + 2) + "\u2534" + "\u2500".repeat(maxValueLength + 2);
|
|
90
|
-
const lines = [
|
|
91
|
-
`\u250C${separatorTop}\u2510`,
|
|
92
|
-
...Object.entries(logData).filter(([_, value]) => value).map(([key, value]) => `\u2502 ${key.padEnd(maxKeyLength)} \u2502 ${truncateString(String(value), import_constants.MAX_LENGTH).padEnd(maxValueLength)} \u2502`),
|
|
93
|
-
`\u2514${separatorBottom}\u2518`
|
|
94
|
-
];
|
|
95
|
-
return lines.join("\n");
|
|
96
|
-
}, "printTable");
|
|
97
|
-
const getCurrentDateStr = /* @__PURE__ */ __name(() => {
|
|
98
|
-
return (0, import_dayjs.default)().format(import_constants.DATE_FORMAT);
|
|
99
|
-
}, "getCurrentDateStr");
|
|
100
|
-
const formatArray = /* @__PURE__ */ __name((arr) => {
|
|
101
|
-
return Array.isArray(arr) ? `[${arr.map(String).join(", ")}]` : "null";
|
|
102
|
-
}, "formatArray");
|
|
103
|
-
const extraceQueryTextAndValues = /* @__PURE__ */ __name((...rest) => {
|
|
104
|
-
const [arg0, arg1] = rest;
|
|
105
|
-
if (arg0 && (isSubmittable(arg0) || isObject(arg0))) {
|
|
106
|
-
return [
|
|
107
|
-
arg0.text,
|
|
108
|
-
arg1 ?? arg0.values
|
|
12
|
+
exports.isSubmittable = isSubmittable;
|
|
13
|
+
const isObject = (val) => {
|
|
14
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
15
|
+
};
|
|
16
|
+
exports.isObject = isObject;
|
|
17
|
+
const normalizeStrings = (strs) => {
|
|
18
|
+
if (!strs) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return Array.from(new Set(strs.filter(Boolean).map((ele) => ele.trim())));
|
|
22
|
+
};
|
|
23
|
+
exports.normalizeStrings = normalizeStrings;
|
|
24
|
+
const plainPromise = async (promise) => {
|
|
25
|
+
let result = undefined;
|
|
26
|
+
let err = undefined;
|
|
27
|
+
try {
|
|
28
|
+
result = await promise;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
err = error;
|
|
32
|
+
}
|
|
33
|
+
return [result, err];
|
|
34
|
+
};
|
|
35
|
+
exports.plainPromise = plainPromise;
|
|
36
|
+
const truncateString = (str, maxLength) => {
|
|
37
|
+
if (str.length <= maxLength) {
|
|
38
|
+
return str;
|
|
39
|
+
}
|
|
40
|
+
const truncatedLength = maxLength - 3;
|
|
41
|
+
if (truncatedLength <= 0) {
|
|
42
|
+
return '...';
|
|
43
|
+
}
|
|
44
|
+
return str.slice(0, truncatedLength) + '...';
|
|
45
|
+
};
|
|
46
|
+
exports.truncateString = truncateString;
|
|
47
|
+
const printTable = (logData) => {
|
|
48
|
+
const maxKeyLength = constants_1.MAX_LENGTH / 3;
|
|
49
|
+
const maxValueLength = constants_1.MAX_LENGTH;
|
|
50
|
+
const separatorTop = '─'.repeat(maxKeyLength + 2) + '┬' + '─'.repeat(maxValueLength + 2);
|
|
51
|
+
const separatorBottom = '─'.repeat(maxKeyLength + 2) + '┴' + '─'.repeat(maxValueLength + 2);
|
|
52
|
+
const lines = [
|
|
53
|
+
`┌${separatorTop}┐`,
|
|
54
|
+
...Object.entries(logData)
|
|
55
|
+
.filter(([_, value]) => value)
|
|
56
|
+
.map(([key, value]) => `│ ${key.padEnd(maxKeyLength)} │ ${(0, exports.truncateString)(String(value), constants_1.MAX_LENGTH).padEnd(maxValueLength)} │`),
|
|
57
|
+
`└${separatorBottom}┘`
|
|
109
58
|
];
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
59
|
+
return lines.join('\n');
|
|
60
|
+
};
|
|
61
|
+
exports.printTable = printTable;
|
|
62
|
+
const getCurrentDateStr = () => {
|
|
63
|
+
return (0, dayjs_1.default)().format(constants_1.DATE_FORMAT);
|
|
64
|
+
};
|
|
65
|
+
exports.getCurrentDateStr = getCurrentDateStr;
|
|
66
|
+
const formatArray = (arr) => {
|
|
67
|
+
return Array.isArray(arr) ? `[${arr.map(String).join(', ')}]` : 'null';
|
|
68
|
+
};
|
|
69
|
+
exports.formatArray = formatArray;
|
|
70
|
+
const extraceQueryTextAndValues = (...rest) => {
|
|
71
|
+
const [arg0, arg1] = rest;
|
|
72
|
+
if (arg0 && ((0, exports.isSubmittable)(arg0) || (0, exports.isObject)(arg0))) {
|
|
73
|
+
return [arg0.text, arg1 ?? arg0.values];
|
|
74
|
+
}
|
|
75
|
+
return [arg0, arg1];
|
|
76
|
+
};
|
|
77
|
+
exports.extraceQueryTextAndValues = extraceQueryTextAndValues;
|
|
78
|
+
const createDebugLogger = (defaultLogger, customFormater) => {
|
|
79
|
+
if (typeof customFormater === 'function') {
|
|
80
|
+
return (data) => {
|
|
81
|
+
defaultLogger(customFormater(data));
|
|
82
|
+
};
|
|
83
|
+
}
|
|
118
84
|
return (data) => {
|
|
119
|
-
|
|
85
|
+
const firstLine = `Executing Postgres command\n`;
|
|
86
|
+
defaultLogger(firstLine + (0, exports.printTable)(data));
|
|
120
87
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}, "connect")
|
|
153
|
-
},
|
|
154
|
-
client: {
|
|
155
|
-
query: /* @__PURE__ */ __name((callback) => {
|
|
156
|
-
return async (...rest) => {
|
|
157
|
-
const [text, values] = extraceQueryTextAndValues(...rest);
|
|
158
|
-
const submittable = isSubmittable(rest[0]);
|
|
159
|
-
const startOn = getCurrentDateStr();
|
|
160
|
-
let err = void 0;
|
|
161
|
-
if (submittable) {
|
|
162
|
-
rest[0].on("end", () => {
|
|
163
|
-
logger({
|
|
164
|
-
Instance: name,
|
|
165
|
-
Client: queryId,
|
|
166
|
-
Type: "Submittable",
|
|
167
|
-
Text: text,
|
|
168
|
-
Values: formatArray(values),
|
|
169
|
-
"Started On": startOn,
|
|
170
|
-
"Ended On": getCurrentDateStr(),
|
|
171
|
-
Status: "Successful"
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
rest[0].on("error", (err2) => {
|
|
175
|
-
logger({
|
|
176
|
-
Instance: name,
|
|
177
|
-
Client: queryId,
|
|
178
|
-
Type: "Submittable",
|
|
179
|
-
Text: text,
|
|
180
|
-
Values: formatArray(values),
|
|
181
|
-
"Started On": startOn,
|
|
182
|
-
"Ended On": getCurrentDateStr(),
|
|
183
|
-
Status: "Failed",
|
|
184
|
-
Error: err2
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
try {
|
|
189
|
-
return await callback(...rest);
|
|
190
|
-
} catch (error) {
|
|
191
|
-
err = error;
|
|
192
|
-
throw err;
|
|
193
|
-
} finally {
|
|
194
|
-
if (!submittable) {
|
|
195
|
-
logger({
|
|
196
|
-
Instance: name,
|
|
197
|
-
Client: queryId,
|
|
198
|
-
Type: "Query",
|
|
199
|
-
Text: text,
|
|
200
|
-
Values: formatArray(values),
|
|
201
|
-
"Started On": startOn,
|
|
202
|
-
"Ended On": getCurrentDateStr(),
|
|
203
|
-
Status: err ? "Failed" : "Successful",
|
|
204
|
-
Error: err
|
|
205
|
-
});
|
|
88
|
+
};
|
|
89
|
+
exports.createDebugLogger = createDebugLogger;
|
|
90
|
+
const debugFactroy = (name, queryId, logger) => {
|
|
91
|
+
return {
|
|
92
|
+
pool: {
|
|
93
|
+
connect: (callback) => {
|
|
94
|
+
return async () => {
|
|
95
|
+
const startOn = (0, exports.getCurrentDateStr)();
|
|
96
|
+
let err = undefined;
|
|
97
|
+
try {
|
|
98
|
+
return await callback();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
err = error;
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
logger({
|
|
106
|
+
Instance: name,
|
|
107
|
+
Client: queryId,
|
|
108
|
+
Type: 'Request new client',
|
|
109
|
+
'Started On': startOn,
|
|
110
|
+
'Ended On': (0, exports.getCurrentDateStr)(),
|
|
111
|
+
Status: err ? 'Failed' : 'Successful',
|
|
112
|
+
Error: err
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
206
116
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
117
|
+
},
|
|
118
|
+
client: {
|
|
119
|
+
query: (callback) => {
|
|
120
|
+
return async (...rest) => {
|
|
121
|
+
const [text, values] = (0, exports.extraceQueryTextAndValues)(...rest);
|
|
122
|
+
const submittable = (0, exports.isSubmittable)(rest[0]);
|
|
123
|
+
const startOn = (0, exports.getCurrentDateStr)();
|
|
124
|
+
let err = undefined;
|
|
125
|
+
if (submittable) {
|
|
126
|
+
rest[0].on('end', () => {
|
|
127
|
+
logger({
|
|
128
|
+
Instance: name,
|
|
129
|
+
Client: queryId,
|
|
130
|
+
Type: 'Submittable',
|
|
131
|
+
Text: text,
|
|
132
|
+
Values: (0, exports.formatArray)(values),
|
|
133
|
+
'Started On': startOn,
|
|
134
|
+
'Ended On': (0, exports.getCurrentDateStr)(),
|
|
135
|
+
Status: 'Successful'
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
rest[0].on('error', (err) => {
|
|
139
|
+
logger({
|
|
140
|
+
Instance: name,
|
|
141
|
+
Client: queryId,
|
|
142
|
+
Type: 'Submittable',
|
|
143
|
+
Text: text,
|
|
144
|
+
Values: (0, exports.formatArray)(values),
|
|
145
|
+
'Started On': startOn,
|
|
146
|
+
'Ended On': (0, exports.getCurrentDateStr)(),
|
|
147
|
+
Status: 'Failed',
|
|
148
|
+
Error: err
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
return await callback(...rest);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
err = error;
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
if (!submittable) {
|
|
161
|
+
logger({
|
|
162
|
+
Instance: name,
|
|
163
|
+
Client: queryId,
|
|
164
|
+
Type: 'Query',
|
|
165
|
+
Text: text,
|
|
166
|
+
Values: (0, exports.formatArray)(values),
|
|
167
|
+
'Started On': startOn,
|
|
168
|
+
'Ended On': (0, exports.getCurrentDateStr)(),
|
|
169
|
+
Status: err ? 'Failed' : 'Successful',
|
|
170
|
+
Error: err
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
release: (callback) => {
|
|
177
|
+
return (...rest) => {
|
|
178
|
+
const startOn = (0, exports.getCurrentDateStr)();
|
|
179
|
+
let err = undefined;
|
|
180
|
+
try {
|
|
181
|
+
return callback(...rest);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
err = error;
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
logger({
|
|
189
|
+
Instance: name,
|
|
190
|
+
Client: queryId,
|
|
191
|
+
Type: 'Release client',
|
|
192
|
+
'Started On': startOn,
|
|
193
|
+
'Ended On': (0, exports.getCurrentDateStr)(),
|
|
194
|
+
Status: err ? 'Failed' : 'Successful',
|
|
195
|
+
Error: err
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
exports.debugFactroy = debugFactroy;
|
|
204
|
+
// Ref: https://github.com/Papooch/nestjs-cls/blob/main/packages/core/src/utils/copy-method-metadata.ts#L10
|
|
205
|
+
const copyMethodMetadata = (from, to) => {
|
|
206
|
+
const metadataKeys = Reflect.getMetadataKeys(from);
|
|
207
|
+
metadataKeys.map((key) => {
|
|
208
|
+
const value = Reflect.getMetadata(key, from);
|
|
209
|
+
Reflect.defineMetadata(key, value, to);
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
exports.copyMethodMetadata = copyMethodMetadata;
|
|
213
|
+
const getTransactionMetdata = (target) => {
|
|
214
|
+
return Reflect.getMetadata(constants_1.TRANSACTION_META, target);
|
|
215
|
+
};
|
|
216
|
+
exports.getTransactionMetdata = getTransactionMetdata;
|
|
217
|
+
const setTransactionMetdata = (target) => {
|
|
218
|
+
return Reflect.defineMetadata(constants_1.TRANSACTION_META, true, target);
|
|
219
|
+
};
|
|
220
|
+
exports.setTransactionMetdata = setTransactionMetdata;
|
|
221
|
+
const withResolvers = () => {
|
|
222
|
+
let resolve;
|
|
223
|
+
let reject;
|
|
224
|
+
const promise = new Promise((res, rej) => {
|
|
225
|
+
resolve = res;
|
|
226
|
+
reject = rej;
|
|
227
|
+
});
|
|
228
|
+
return { promise, resolve: resolve, reject: reject };
|
|
229
|
+
};
|
|
230
|
+
exports.withResolvers = withResolvers;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@nestjs-kitchen/connextion-postgres",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "A flexible module to provide node-postgres interface in NextJS.",
|
|
5
|
-
"version": "2.0.
|
|
5
|
+
"version": "2.0.4",
|
|
6
6
|
"homepage": "https://github.com/yikenman/nestjs-kitchen",
|
|
7
7
|
"repository": "https://github.com/yikenman/nestjs-kitchen",
|
|
8
8
|
"author": "yikenman",
|
|
@@ -26,12 +26,13 @@
|
|
|
26
26
|
"@types/jest": "^29.5.14",
|
|
27
27
|
"@types/node": "^22.13.9",
|
|
28
28
|
"jest": "^29.7.0",
|
|
29
|
-
"
|
|
29
|
+
"rimraf": "^6.0.1",
|
|
30
|
+
"ts-jest": "^29.3.0",
|
|
30
31
|
"ts-node": "^10.9.2",
|
|
31
32
|
"tsconfig-paths": "^4.2.0",
|
|
32
33
|
"tsup": "^8.4.0",
|
|
33
34
|
"typescript": "^5.8.2",
|
|
34
|
-
"@nestjs-kitchen/connextion": "2.0.
|
|
35
|
+
"@nestjs-kitchen/connextion": "2.0.4"
|
|
35
36
|
},
|
|
36
37
|
"engines": {
|
|
37
38
|
"node": ">=20.13.0"
|
|
@@ -51,11 +52,11 @@
|
|
|
51
52
|
"@types/pg": "^8.11.10",
|
|
52
53
|
"pg": "^8.13.1",
|
|
53
54
|
"reflect-metadata": "^0.2.2",
|
|
54
|
-
"@nestjs-kitchen/connextion": "2.0.
|
|
55
|
+
"@nestjs-kitchen/connextion": "2.0.4"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
|
-
"build": "
|
|
58
|
-
"dev": "
|
|
58
|
+
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
59
|
+
"dev": "rimraf dist && tsc -p tsconfig.build.json --watch",
|
|
59
60
|
"test": "jest",
|
|
60
61
|
"test:ci": "jest --coverage",
|
|
61
62
|
"test:cov": "jest --coverage",
|