@faasjs/knex 3.1.0 → 3.1.2

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/index.d.mts CHANGED
@@ -27,7 +27,7 @@ type KnexConfig = {
27
27
  config?: Knex$1.Config;
28
28
  };
29
29
  declare class Knex implements Plugin {
30
- readonly type: string;
30
+ readonly type = "knex";
31
31
  readonly name: string;
32
32
  config: Knex$1.Config;
33
33
  adapter: Knex$1;
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ type KnexConfig = {
27
27
  config?: Knex$1.Config;
28
28
  };
29
29
  declare class Knex implements Plugin {
30
- readonly type: string;
30
+ readonly type = "knex";
31
31
  readonly name: string;
32
32
  config: Knex$1.Config;
33
33
  adapter: Knex$1;
package/dist/index.js CHANGED
@@ -16,12 +16,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
16
16
  throw Error('Dynamic require of "' + x + '" is not supported');
17
17
  });
18
18
  var originKnex = knex__default.default;
19
- var Name = "knex";
19
+ var Name = "Knex";
20
20
  if (!global.FaasJS_Knex) {
21
21
  global.FaasJS_Knex = {};
22
22
  }
23
23
  var Knex = class {
24
- type = Name;
24
+ type = "knex";
25
25
  name = Name;
26
26
  config;
27
27
  adapter;
@@ -29,10 +29,9 @@ var Knex = class {
29
29
  logger;
30
30
  constructor(config) {
31
31
  if (config) {
32
- this.name = config.name || this.type;
32
+ this.name = config.name || this.name;
33
33
  this.config = config.config || /* @__PURE__ */ Object.create(null);
34
34
  } else {
35
- this.name = this.type;
36
35
  this.config = /* @__PURE__ */ Object.create(null);
37
36
  }
38
37
  }
@@ -42,7 +41,7 @@ var Knex = class {
42
41
  this.config = global.FaasJS_Knex[this.name].config;
43
42
  this.adapter = global.FaasJS_Knex[this.name].adapter;
44
43
  this.query = this.adapter;
45
- this.logger.debug("[%s] use exists adapter", this.name);
44
+ this.logger.debug("use exists adapter");
46
45
  await next();
47
46
  return;
48
47
  }
@@ -97,13 +96,11 @@ var Knex = class {
97
96
  this.config.client = client.default;
98
97
  break;
99
98
  }
100
- console.log(client);
101
99
  throw Error(`Invalid client: ${this.config.client}`);
102
100
  }
103
101
  }
104
102
  break;
105
103
  }
106
- console.log(this.config);
107
104
  this.adapter = knex__default.default(this.config);
108
105
  if (this.config.client === "pg") {
109
106
  const pg = __require("pg");
@@ -123,8 +120,7 @@ var Knex = class {
123
120
  if (!__knexQueryUid) return;
124
121
  this.logger.time(`Knex${this.name}${__knexQueryUid}`);
125
122
  this.logger.debug(
126
- "[%s] [%s] query begin: %s %j",
127
- this.name,
123
+ "[%s] query begin: %s %j",
128
124
  __knexQueryUid,
129
125
  sql,
130
126
  bindings
@@ -133,8 +129,7 @@ var Knex = class {
133
129
  if (!__knexQueryUid) return;
134
130
  this.logger.timeEnd(
135
131
  `Knex${this.name}${__knexQueryUid}`,
136
- "[%s] [%s] query done: %s %j %j",
137
- this.name,
132
+ "[%s] query done: %s %j %j",
138
133
  __knexQueryUid,
139
134
  sql,
140
135
  bindings,
@@ -144,14 +139,13 @@ var Knex = class {
144
139
  if (!__knexQueryUid) return;
145
140
  this.logger.timeEnd(
146
141
  `Knex${this.name}${__knexQueryUid}`,
147
- "[%s] [%s] query failed: %s %j",
148
- this.name,
142
+ "[%s] query failed: %s %j",
149
143
  __knexQueryUid,
150
144
  sql,
151
145
  bindings
152
146
  );
153
147
  });
154
- data.logger.debug("[%s] connected", this.name);
148
+ data.logger.debug("connected");
155
149
  global.FaasJS_Knex[this.name] = this;
156
150
  await next();
157
151
  }
@@ -173,35 +167,21 @@ var Knex = class {
173
167
  if (options?.trx) return scope(options.trx);
174
168
  const trx = await this.adapter.transaction(config);
175
169
  const trxId = crypto.randomUUID();
176
- this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
170
+ this.logger.debug("[%s] transaction begin", trxId);
177
171
  try {
178
172
  const result = await scope(trx);
179
173
  if (trx.isCompleted()) {
180
- this.logger.debug(
181
- "[%s] [%s] transaction has been finished in scope",
182
- this.name,
183
- trxId
184
- );
174
+ this.logger.debug("[%s] transaction has been finished in scope", trxId);
185
175
  return result;
186
176
  }
187
- this.logger.debug("[%s] [%s] transaction begin commit", this.name, trxId);
177
+ this.logger.debug("[%s] transaction begin commit", trxId);
188
178
  await trx.commit();
189
- this.logger.debug(
190
- "[%s] [%s] transaction committed: %j",
191
- this.name,
192
- trxId,
193
- result
194
- );
179
+ this.logger.debug("[%s] transaction committed: %j", trxId, result);
195
180
  trx.emit("commit");
196
181
  return result;
197
182
  } catch (error) {
198
183
  await trx.rollback(error);
199
- this.logger.error(
200
- "[%s] [%s] transaction rollback: %s",
201
- this.name,
202
- trxId,
203
- error
204
- );
184
+ this.logger.error("[%s] transaction rollback: %s", trxId, error);
205
185
  trx.emit("rollback", error);
206
186
  throw error;
207
187
  }
package/dist/index.mjs CHANGED
@@ -10,12 +10,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
  throw Error('Dynamic require of "' + x + '" is not supported');
11
11
  });
12
12
  var originKnex = knex;
13
- var Name = "knex";
13
+ var Name = "Knex";
14
14
  if (!global.FaasJS_Knex) {
15
15
  global.FaasJS_Knex = {};
16
16
  }
17
17
  var Knex = class {
18
- type = Name;
18
+ type = "knex";
19
19
  name = Name;
20
20
  config;
21
21
  adapter;
@@ -23,10 +23,9 @@ var Knex = class {
23
23
  logger;
24
24
  constructor(config) {
25
25
  if (config) {
26
- this.name = config.name || this.type;
26
+ this.name = config.name || this.name;
27
27
  this.config = config.config || /* @__PURE__ */ Object.create(null);
28
28
  } else {
29
- this.name = this.type;
30
29
  this.config = /* @__PURE__ */ Object.create(null);
31
30
  }
32
31
  }
@@ -36,7 +35,7 @@ var Knex = class {
36
35
  this.config = global.FaasJS_Knex[this.name].config;
37
36
  this.adapter = global.FaasJS_Knex[this.name].adapter;
38
37
  this.query = this.adapter;
39
- this.logger.debug("[%s] use exists adapter", this.name);
38
+ this.logger.debug("use exists adapter");
40
39
  await next();
41
40
  return;
42
41
  }
@@ -91,13 +90,11 @@ var Knex = class {
91
90
  this.config.client = client.default;
92
91
  break;
93
92
  }
94
- console.log(client);
95
93
  throw Error(`Invalid client: ${this.config.client}`);
96
94
  }
97
95
  }
98
96
  break;
99
97
  }
100
- console.log(this.config);
101
98
  this.adapter = knex(this.config);
102
99
  if (this.config.client === "pg") {
103
100
  const pg = __require("pg");
@@ -117,8 +114,7 @@ var Knex = class {
117
114
  if (!__knexQueryUid) return;
118
115
  this.logger.time(`Knex${this.name}${__knexQueryUid}`);
119
116
  this.logger.debug(
120
- "[%s] [%s] query begin: %s %j",
121
- this.name,
117
+ "[%s] query begin: %s %j",
122
118
  __knexQueryUid,
123
119
  sql,
124
120
  bindings
@@ -127,8 +123,7 @@ var Knex = class {
127
123
  if (!__knexQueryUid) return;
128
124
  this.logger.timeEnd(
129
125
  `Knex${this.name}${__knexQueryUid}`,
130
- "[%s] [%s] query done: %s %j %j",
131
- this.name,
126
+ "[%s] query done: %s %j %j",
132
127
  __knexQueryUid,
133
128
  sql,
134
129
  bindings,
@@ -138,14 +133,13 @@ var Knex = class {
138
133
  if (!__knexQueryUid) return;
139
134
  this.logger.timeEnd(
140
135
  `Knex${this.name}${__knexQueryUid}`,
141
- "[%s] [%s] query failed: %s %j",
142
- this.name,
136
+ "[%s] query failed: %s %j",
143
137
  __knexQueryUid,
144
138
  sql,
145
139
  bindings
146
140
  );
147
141
  });
148
- data.logger.debug("[%s] connected", this.name);
142
+ data.logger.debug("connected");
149
143
  global.FaasJS_Knex[this.name] = this;
150
144
  await next();
151
145
  }
@@ -167,35 +161,21 @@ var Knex = class {
167
161
  if (options?.trx) return scope(options.trx);
168
162
  const trx = await this.adapter.transaction(config);
169
163
  const trxId = randomUUID();
170
- this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
164
+ this.logger.debug("[%s] transaction begin", trxId);
171
165
  try {
172
166
  const result = await scope(trx);
173
167
  if (trx.isCompleted()) {
174
- this.logger.debug(
175
- "[%s] [%s] transaction has been finished in scope",
176
- this.name,
177
- trxId
178
- );
168
+ this.logger.debug("[%s] transaction has been finished in scope", trxId);
179
169
  return result;
180
170
  }
181
- this.logger.debug("[%s] [%s] transaction begin commit", this.name, trxId);
171
+ this.logger.debug("[%s] transaction begin commit", trxId);
182
172
  await trx.commit();
183
- this.logger.debug(
184
- "[%s] [%s] transaction committed: %j",
185
- this.name,
186
- trxId,
187
- result
188
- );
173
+ this.logger.debug("[%s] transaction committed: %j", trxId, result);
189
174
  trx.emit("commit");
190
175
  return result;
191
176
  } catch (error) {
192
177
  await trx.rollback(error);
193
- this.logger.error(
194
- "[%s] [%s] transaction rollback: %s",
195
- this.name,
196
- trxId,
197
- error
198
- );
178
+ this.logger.error("[%s] transaction rollback: %s", trxId, error);
199
179
  trx.emit("rollback", error);
200
180
  throw error;
201
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/knex",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -34,9 +34,9 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@faasjs/deep_merge": "3.1.0",
38
- "@faasjs/func": "3.1.0",
39
- "@faasjs/logger": "3.1.0"
37
+ "@faasjs/deep_merge": "3.1.2",
38
+ "@faasjs/func": "3.1.2",
39
+ "@faasjs/logger": "3.1.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "knex": "*"