@faasjs/knex 0.0.3-beta.99 → 0.0.4-beta.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/README.md CHANGED
@@ -120,7 +120,7 @@ ___
120
120
  | Name | Type |
121
121
  | :------ | :------ |
122
122
  | `scope` | (`trx`: `Transaction`<`any`, `any`\>) => `void` \| `Promise`<`TResult`\> |
123
- | `config?` | `any` |
123
+ | `config?` | `TransactionConfig` |
124
124
 
125
125
  #### Returns
126
126
 
package/dist/index.d.mts CHANGED
@@ -20,7 +20,7 @@ declare class Knex implements Plugin {
20
20
  onMount(data: MountData, next: Next): Promise<void>;
21
21
  onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
22
22
  raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
23
- transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: any): Promise<TResult>;
23
+ transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
24
24
  schema(): Knex$1.SchemaBuilder;
25
25
  quit(): Promise<void>;
26
26
  }
@@ -35,7 +35,7 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
35
35
  _unionProps: never;
36
36
  }[]>;
37
37
  declare function query<TName extends {} = any, TResult = any[]>(table: string): Knex$1.QueryBuilder<TName, TResult>;
38
- declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: any): Promise<TResult>;
38
+ declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
39
39
  declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult>;
40
40
 
41
41
  export { Knex, KnexConfig, query, raw, transaction, useKnex };
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ declare class Knex implements Plugin {
20
20
  onMount(data: MountData, next: Next): Promise<void>;
21
21
  onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
22
22
  raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
23
- transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: any): Promise<TResult>;
23
+ transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
24
24
  schema(): Knex$1.SchemaBuilder;
25
25
  quit(): Promise<void>;
26
26
  }
@@ -35,7 +35,7 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
35
35
  _unionProps: never;
36
36
  }[]>;
37
37
  declare function query<TName extends {} = any, TResult = any[]>(table: string): Knex$1.QueryBuilder<TName, TResult>;
38
- declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: any): Promise<TResult>;
38
+ declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig): Promise<TResult>;
39
39
  declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult>;
40
40
 
41
41
  export { Knex, KnexConfig, query, raw, transaction, useKnex };
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
17
17
  throw Error('Dynamic require of "' + x + '" is not supported');
18
18
  });
19
19
  var Name = "knex";
20
- if (!global["FaasJS_Knex"]) {
20
+ if (!global.FaasJS_Knex) {
21
21
  global.FaasJS_Knex = {};
22
22
  }
23
23
  var Knex = class {
@@ -41,11 +41,11 @@ var Knex = class {
41
41
  data.dependencies["better-sqlite3"] = "*";
42
42
  else
43
43
  data.dependencies[client] = "*";
44
- new logger.Logger(this.name).debug("add dependencies: " + client);
44
+ new logger.Logger(this.name).debug(`add dependencies: ${client}`);
45
45
  await next();
46
46
  }
47
47
  async onMount(data, next) {
48
- var _a, _b;
48
+ var _a, _b, _c;
49
49
  this.logger = data.logger;
50
50
  if (global.FaasJS_Knex[this.name]) {
51
51
  this.config = global.FaasJS_Knex[this.name].config;
@@ -68,65 +68,65 @@ var Knex = class {
68
68
  } else
69
69
  this.config[key] = value;
70
70
  }
71
- if (data.config.plugins && ((_a = data.config.plugins[this.name]) == null ? void 0 : _a.config))
72
- this.config = deep_merge.deepMerge(data.config.plugins[this.name].config, this.config);
71
+ if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
72
+ this.config = deep_merge.deepMerge(
73
+ data.config.plugins[this.name].config,
74
+ this.config
75
+ );
73
76
  if (this.config.client === "sqlite3")
74
77
  this.config.client = "better-sqlite3";
75
- if (this.config.client === "pg" && typeof ((_b = this.config.pool) == null ? void 0 : _b.propagateCreateError) === "undefined") {
78
+ if (this.config.client === "pg" && typeof ((_c = this.config.pool) == null ? void 0 : _c.propagateCreateError) === "undefined") {
76
79
  if (!this.config.pool)
77
80
  this.config.pool = /* @__PURE__ */ Object.create(null);
78
- this.config.pool = Object.assign({
79
- propagateCreateError: false,
80
- min: 0,
81
- max: 10,
82
- acquireTimeoutMillis: 5e3,
83
- idleTimeoutMillis: 3e4
84
- }, this.config.pool);
81
+ this.config.pool = Object.assign(
82
+ {
83
+ propagateCreateError: false,
84
+ min: 0,
85
+ max: 10,
86
+ acquireTimeoutMillis: 5e3,
87
+ idleTimeoutMillis: 3e4
88
+ },
89
+ this.config.pool
90
+ );
85
91
  if (typeof this.config.connection === "string" && !this.config.connection.includes("json=true"))
86
- this.config.connection = this.config.connection + "?json=true";
92
+ this.config.connection = `${this.config.connection}?json=true`;
87
93
  }
88
94
  this.adapter = knex__default.default(this.config);
89
95
  if (this.config.client === "pg") {
90
96
  const pg = __require("pg");
91
- const intTypes = [
92
- "INT2",
93
- "INT4",
94
- "INT8"
95
- ];
96
- intTypes.forEach((t) => pg.types.setTypeParser(
97
- pg.types.builtins[t],
98
- (v) => parseInt(v)
99
- ));
100
- const floatTypes = [
101
- "FLOAT4",
102
- "FLOAT8",
103
- "NUMERIC"
104
- ];
105
- floatTypes.forEach((t) => pg.types.setTypeParser(
106
- pg.types.builtins[t],
107
- (v) => parseFloat(v)
108
- ));
97
+ const intTypes = ["INT2", "INT4", "INT8"];
98
+ intTypes.forEach(
99
+ (t) => pg.types.setTypeParser(pg.types.builtins[t], (v) => parseInt(v))
100
+ );
101
+ const floatTypes = ["FLOAT4", "FLOAT8", "NUMERIC"];
102
+ floatTypes.forEach(
103
+ (t) => pg.types.setTypeParser(
104
+ pg.types.builtins[t],
105
+ (v) => parseFloat(v)
106
+ )
107
+ );
109
108
  }
110
109
  this.query = this.adapter;
111
- this.query.on("query", ({
112
- sql,
113
- __knexQueryUid,
114
- bindings
115
- }) => {
110
+ this.query.on("query", ({ sql, __knexQueryUid, bindings }) => {
116
111
  this.logger.time(`Knex${__knexQueryUid}`);
117
112
  this.logger.debug("[%s] query begin: %s %j", this.name, sql, bindings);
118
- }).on("query-response", (response, {
119
- sql,
120
- __knexQueryUid,
121
- bindings
122
- }) => {
123
- this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query done: %s %j %j", this.name, sql, bindings, response);
124
- }).on("query-error", (_, {
125
- __knexQueryUid,
126
- sql,
127
- bindings
128
- }) => {
129
- this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query failed: %s %j", this.name, sql, bindings);
113
+ }).on("query-response", (response, { sql, __knexQueryUid, bindings }) => {
114
+ this.logger.timeEnd(
115
+ `Knex${__knexQueryUid}`,
116
+ "[%s] query done: %s %j %j",
117
+ this.name,
118
+ sql,
119
+ bindings,
120
+ response
121
+ );
122
+ }).on("query-error", (_, { __knexQueryUid, sql, bindings }) => {
123
+ this.logger.timeEnd(
124
+ `Knex${__knexQueryUid}`,
125
+ "[%s] query failed: %s %j",
126
+ this.name,
127
+ sql,
128
+ bindings
129
+ );
130
130
  });
131
131
  data.logger.debug("[%s] connected", this.name);
132
132
  global.FaasJS_Knex[this.name] = this;
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  throw Error('Dynamic require of "' + x + '" is not supported');
12
12
  });
13
13
  var Name = "knex";
14
- if (!global["FaasJS_Knex"]) {
14
+ if (!global.FaasJS_Knex) {
15
15
  global.FaasJS_Knex = {};
16
16
  }
17
17
  var Knex = class {
@@ -35,11 +35,11 @@ var Knex = class {
35
35
  data.dependencies["better-sqlite3"] = "*";
36
36
  else
37
37
  data.dependencies[client] = "*";
38
- new Logger(this.name).debug("add dependencies: " + client);
38
+ new Logger(this.name).debug(`add dependencies: ${client}`);
39
39
  await next();
40
40
  }
41
41
  async onMount(data, next) {
42
- var _a, _b;
42
+ var _a, _b, _c;
43
43
  this.logger = data.logger;
44
44
  if (global.FaasJS_Knex[this.name]) {
45
45
  this.config = global.FaasJS_Knex[this.name].config;
@@ -62,65 +62,65 @@ var Knex = class {
62
62
  } else
63
63
  this.config[key] = value;
64
64
  }
65
- if (data.config.plugins && ((_a = data.config.plugins[this.name]) == null ? void 0 : _a.config))
66
- this.config = deepMerge(data.config.plugins[this.name].config, this.config);
65
+ if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
66
+ this.config = deepMerge(
67
+ data.config.plugins[this.name].config,
68
+ this.config
69
+ );
67
70
  if (this.config.client === "sqlite3")
68
71
  this.config.client = "better-sqlite3";
69
- if (this.config.client === "pg" && typeof ((_b = this.config.pool) == null ? void 0 : _b.propagateCreateError) === "undefined") {
72
+ if (this.config.client === "pg" && typeof ((_c = this.config.pool) == null ? void 0 : _c.propagateCreateError) === "undefined") {
70
73
  if (!this.config.pool)
71
74
  this.config.pool = /* @__PURE__ */ Object.create(null);
72
- this.config.pool = Object.assign({
73
- propagateCreateError: false,
74
- min: 0,
75
- max: 10,
76
- acquireTimeoutMillis: 5e3,
77
- idleTimeoutMillis: 3e4
78
- }, this.config.pool);
75
+ this.config.pool = Object.assign(
76
+ {
77
+ propagateCreateError: false,
78
+ min: 0,
79
+ max: 10,
80
+ acquireTimeoutMillis: 5e3,
81
+ idleTimeoutMillis: 3e4
82
+ },
83
+ this.config.pool
84
+ );
79
85
  if (typeof this.config.connection === "string" && !this.config.connection.includes("json=true"))
80
- this.config.connection = this.config.connection + "?json=true";
86
+ this.config.connection = `${this.config.connection}?json=true`;
81
87
  }
82
88
  this.adapter = knex(this.config);
83
89
  if (this.config.client === "pg") {
84
90
  const pg = __require("pg");
85
- const intTypes = [
86
- "INT2",
87
- "INT4",
88
- "INT8"
89
- ];
90
- intTypes.forEach((t) => pg.types.setTypeParser(
91
- pg.types.builtins[t],
92
- (v) => parseInt(v)
93
- ));
94
- const floatTypes = [
95
- "FLOAT4",
96
- "FLOAT8",
97
- "NUMERIC"
98
- ];
99
- floatTypes.forEach((t) => pg.types.setTypeParser(
100
- pg.types.builtins[t],
101
- (v) => parseFloat(v)
102
- ));
91
+ const intTypes = ["INT2", "INT4", "INT8"];
92
+ intTypes.forEach(
93
+ (t) => pg.types.setTypeParser(pg.types.builtins[t], (v) => parseInt(v))
94
+ );
95
+ const floatTypes = ["FLOAT4", "FLOAT8", "NUMERIC"];
96
+ floatTypes.forEach(
97
+ (t) => pg.types.setTypeParser(
98
+ pg.types.builtins[t],
99
+ (v) => parseFloat(v)
100
+ )
101
+ );
103
102
  }
104
103
  this.query = this.adapter;
105
- this.query.on("query", ({
106
- sql,
107
- __knexQueryUid,
108
- bindings
109
- }) => {
104
+ this.query.on("query", ({ sql, __knexQueryUid, bindings }) => {
110
105
  this.logger.time(`Knex${__knexQueryUid}`);
111
106
  this.logger.debug("[%s] query begin: %s %j", this.name, sql, bindings);
112
- }).on("query-response", (response, {
113
- sql,
114
- __knexQueryUid,
115
- bindings
116
- }) => {
117
- this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query done: %s %j %j", this.name, sql, bindings, response);
118
- }).on("query-error", (_, {
119
- __knexQueryUid,
120
- sql,
121
- bindings
122
- }) => {
123
- this.logger.timeEnd(`Knex${__knexQueryUid}`, "[%s] query failed: %s %j", this.name, sql, bindings);
107
+ }).on("query-response", (response, { sql, __knexQueryUid, bindings }) => {
108
+ this.logger.timeEnd(
109
+ `Knex${__knexQueryUid}`,
110
+ "[%s] query done: %s %j %j",
111
+ this.name,
112
+ sql,
113
+ bindings,
114
+ response
115
+ );
116
+ }).on("query-error", (_, { __knexQueryUid, sql, bindings }) => {
117
+ this.logger.timeEnd(
118
+ `Knex${__knexQueryUid}`,
119
+ "[%s] query failed: %s %j",
120
+ this.name,
121
+ sql,
122
+ bindings
123
+ );
124
124
  });
125
125
  data.logger.debug("[%s] connected", this.name);
126
126
  global.FaasJS_Knex[this.name] = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/knex",
3
- "version": "0.0.3-beta.99",
3
+ "version": "0.0.4-beta.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,13 +20,17 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
- "dependencies": {
24
- "@faasjs/deep_merge": "0.0.3-beta.99",
25
- "@faasjs/func": "0.0.3-beta.99",
26
- "@faasjs/logger": "0.0.3-beta.99",
23
+ "peerDependencies": {
24
+ "@faasjs/deep_merge": "0.0.4-beta.2",
25
+ "@faasjs/func": "0.0.4-beta.2",
26
+ "@faasjs/logger": "0.0.4-beta.2",
27
27
  "knex": "*"
28
28
  },
29
29
  "devDependencies": {
30
+ "@faasjs/deep_merge": "0.0.4-beta.2",
31
+ "@faasjs/func": "0.0.4-beta.2",
32
+ "@faasjs/logger": "0.0.4-beta.2",
33
+ "knex": "*",
30
34
  "@types/mysql": "*",
31
35
  "@types/node": "*",
32
36
  "@types/pg": "*",
@@ -36,7 +40,7 @@
36
40
  "tsd": "*"
37
41
  },
38
42
  "engines": {
39
- "npm": ">=8.0.0",
40
- "node": ">=16.0.0"
43
+ "npm": ">=9.0.0",
44
+ "node": ">=18.0.0"
41
45
  }
42
46
  }