@efebia/pino-mongodb 0.0.3 → 1.0.1

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/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export type Options = {
6
6
  collection?: string;
7
7
  unified?: boolean;
8
8
  clientOptions?: MongoClientOptions;
9
+ onError?: (messages: unknown[], error: unknown) => void;
9
10
  } & ({
10
11
  queueOptions?: Omit<QueueOptions<unknown>, 'callback'>;
11
12
  } | {
package/lib/index.js CHANGED
@@ -27,7 +27,7 @@ exports.defaultOption = {
27
27
  }
28
28
  };
29
29
  const bulkTransport = async (opts) => {
30
- const { uri, database: databaseName, collection: collectionName, clientOptions, queueOptions, } = Object.assign(Object.assign({}, exports.defaultOption), opts);
30
+ const { uri, database: databaseName, collection: collectionName, clientOptions, queueOptions, onError } = Object.assign(Object.assign({}, exports.defaultOption), opts);
31
31
  const isImmediate = 'immediate' in opts && opts.immediate;
32
32
  if (!uri)
33
33
  throw new Error(`@efebia/pino-mongodb: URI_NOT_SPECIFIED`);
@@ -41,20 +41,15 @@ const bulkTransport = async (opts) => {
41
41
  return (0, pino_abstract_transport_1.default)(async (source) => {
42
42
  var _a, e_1, _b, _c;
43
43
  try {
44
- for (var _d = true, source_1 = __asyncValues(source), source_1_1; source_1_1 = await source_1.next(), _a = source_1_1.done, !_a;) {
44
+ for (var _d = true, source_1 = __asyncValues(source), source_1_1; source_1_1 = await source_1.next(), _a = source_1_1.done, !_a; _d = true) {
45
45
  _c = source_1_1.value;
46
46
  _d = false;
47
- try {
48
- let obj = _c;
49
- await collection.insertOne((0, log_js_1.default)(obj), { forceServerObjectId: true }).catch((e) => {
50
- if (e instanceof Error) {
51
- console.error(e);
52
- }
53
- });
54
- }
55
- finally {
56
- _d = true;
57
- }
47
+ let obj = _c;
48
+ await collection.insertOne((0, log_js_1.default)(obj), { forceServerObjectId: true }).catch((e) => {
49
+ if (e instanceof Error) {
50
+ console.error(e);
51
+ }
52
+ });
58
53
  }
59
54
  }
60
55
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -75,6 +70,7 @@ const bulkTransport = async (opts) => {
75
70
  document: (0, log_js_1.default)(e)
76
71
  }
77
72
  })), { forceServerObjectId: true }).catch((e) => {
73
+ onError === null || onError === void 0 ? void 0 : onError(messages, e);
78
74
  if (e instanceof Error) {
79
75
  errorCallback === null || errorCallback === void 0 ? void 0 : errorCallback(e);
80
76
  }
@@ -86,9 +82,7 @@ const bulkTransport = async (opts) => {
86
82
  messageQueue.push(chunk, callback);
87
83
  },
88
84
  destroy(err, cb) {
89
- client.close((closeErr) => {
90
- cb(err || closeErr || null);
91
- });
85
+ client.close();
92
86
  }
93
87
  });
94
88
  return (0, pino_abstract_transport_1.default)((source) => {
package/lib/log.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
3
4
  function default_1(data) {
4
5
  let log;
5
6
  try {
@@ -7,6 +8,10 @@ function default_1(data) {
7
8
  if (log.time) {
8
9
  log.time = new Date(log.time);
9
10
  }
11
+ if (log._id) {
12
+ log.__id = log._id;
13
+ delete log._id;
14
+ }
10
15
  }
11
16
  catch (e) {
12
17
  log = {
@@ -15,4 +20,3 @@ function default_1(data) {
15
20
  }
16
21
  return log;
17
22
  }
18
- exports.default = default_1;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@efebia/pino-mongodb",
3
- "version": "0.0.3",
3
+ "version": "1.0.1",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "mongodb": "^4.8.1",
6
+ "mongodb": "^6.15.0",
7
7
  "pino-abstract-transport": "^1.0.0"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@types/node": "18",
11
- "typescript": "^4.7.4"
11
+ "typescript": "~5.8.3"
12
12
  },
13
13
  "files": [
14
14
  "/lib"