@faasjs/knex 2.9.0 → 3.0.0-canary.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
@@ -1,4 +1,4 @@
1
- import { Plugin, DeployData, Next, MountData, InvokeData, UseifyPlugin } from '@faasjs/func';
1
+ import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
2
2
  import { Logger } from '@faasjs/logger';
3
3
  import knex, { Knex as Knex$1 } from 'knex';
4
4
  export { Knex as OriginKnex } from 'knex';
@@ -34,7 +34,6 @@ declare class Knex implements Plugin {
34
34
  query: Knex$1;
35
35
  logger: Logger;
36
36
  constructor(config?: KnexConfig);
37
- onDeploy(data: DeployData, next: Next): Promise<void>;
38
37
  onMount(data: MountData, next: Next): Promise<void>;
39
38
  onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
40
39
  raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin, DeployData, Next, MountData, InvokeData, UseifyPlugin } from '@faasjs/func';
1
+ import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
2
2
  import { Logger } from '@faasjs/logger';
3
3
  import knex, { Knex as Knex$1 } from 'knex';
4
4
  export { Knex as OriginKnex } from 'knex';
@@ -34,7 +34,6 @@ declare class Knex implements Plugin {
34
34
  query: Knex$1;
35
35
  logger: Logger;
36
36
  constructor(config?: KnexConfig);
37
- onDeploy(data: DeployData, next: Next): Promise<void>;
38
37
  onMount(data: MountData, next: Next): Promise<void>;
39
38
  onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
40
39
  raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<Knex$1.Raw<TResult>>;
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var func = require('@faasjs/func');
4
- var logger = require('@faasjs/logger');
5
4
  var deep_merge = require('@faasjs/deep_merge');
6
5
  var knex = require('knex');
7
6
  var crypto = require('crypto');
@@ -22,9 +21,13 @@ if (!global.FaasJS_Knex) {
22
21
  global.FaasJS_Knex = {};
23
22
  }
24
23
  var Knex = class {
24
+ type = Name;
25
+ name = Name;
26
+ config;
27
+ adapter;
28
+ query;
29
+ logger;
25
30
  constructor(config) {
26
- this.type = Name;
27
- this.name = Name;
28
31
  if (config) {
29
32
  this.name = config.name || this.type;
30
33
  this.config = config.config || /* @__PURE__ */ Object.create(null);
@@ -33,17 +36,7 @@ var Knex = class {
33
36
  this.config = /* @__PURE__ */ Object.create(null);
34
37
  }
35
38
  }
36
- async onDeploy(data, next) {
37
- const client = data.config.plugins[this.name].config.client;
38
- if (!client) throw Error("[Knex] client required.");
39
- data.dependencies["@faasjs/knex"] = "*";
40
- if (client === "sqlite3") data.dependencies["better-sqlite3"] = "*";
41
- else data.dependencies[client] = "*";
42
- new logger.Logger(this.name).debug(`add dependencies: ${client}`);
43
- await next();
44
- }
45
39
  async onMount(data, next) {
46
- var _a, _b;
47
40
  this.logger = data.logger;
48
41
  if (global.FaasJS_Knex[this.name]) {
49
42
  this.config = global.FaasJS_Knex[this.name].config;
@@ -66,7 +59,7 @@ var Knex = class {
66
59
  this.config.connection[key.replace("connection_", "")] = value;
67
60
  } else this.config[key] = value;
68
61
  }
69
- if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
62
+ if (data.config.plugins?.[this.name]?.config)
70
63
  this.config = deep_merge.deepMerge(
71
64
  data.config.plugins[this.name].config,
72
65
  this.config
@@ -156,7 +149,7 @@ var Knex = class {
156
149
  */
157
150
  async transaction(scope, config, options) {
158
151
  if (!this.adapter) throw Error(`[${this.name}] Client not initialized.`);
159
- if (options == null ? void 0 : options.trx) return scope(options.trx);
152
+ if (options?.trx) return scope(options.trx);
160
153
  const trx = await this.adapter.transaction(config);
161
154
  const trxId = crypto.randomUUID();
162
155
  this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
@@ -206,7 +199,7 @@ var Knex = class {
206
199
  }
207
200
  };
208
201
  function useKnex(config) {
209
- const name = (config == null ? void 0 : config.name) || Name;
202
+ const name = config?.name || Name;
210
203
  if (global.FaasJS_Knex[name]) return func.usePlugin(global.FaasJS_Knex[name]);
211
204
  return func.usePlugin(new Knex(config));
212
205
  }
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { usePlugin } from '@faasjs/func';
2
- import { Logger } from '@faasjs/logger';
3
2
  import { deepMerge } from '@faasjs/deep_merge';
4
3
  import knex from 'knex';
5
4
  import { randomUUID } from 'node:crypto';
@@ -16,9 +15,13 @@ if (!global.FaasJS_Knex) {
16
15
  global.FaasJS_Knex = {};
17
16
  }
18
17
  var Knex = class {
18
+ type = Name;
19
+ name = Name;
20
+ config;
21
+ adapter;
22
+ query;
23
+ logger;
19
24
  constructor(config) {
20
- this.type = Name;
21
- this.name = Name;
22
25
  if (config) {
23
26
  this.name = config.name || this.type;
24
27
  this.config = config.config || /* @__PURE__ */ Object.create(null);
@@ -27,17 +30,7 @@ var Knex = class {
27
30
  this.config = /* @__PURE__ */ Object.create(null);
28
31
  }
29
32
  }
30
- async onDeploy(data, next) {
31
- const client = data.config.plugins[this.name].config.client;
32
- if (!client) throw Error("[Knex] client required.");
33
- data.dependencies["@faasjs/knex"] = "*";
34
- if (client === "sqlite3") data.dependencies["better-sqlite3"] = "*";
35
- else data.dependencies[client] = "*";
36
- new Logger(this.name).debug(`add dependencies: ${client}`);
37
- await next();
38
- }
39
33
  async onMount(data, next) {
40
- var _a, _b;
41
34
  this.logger = data.logger;
42
35
  if (global.FaasJS_Knex[this.name]) {
43
36
  this.config = global.FaasJS_Knex[this.name].config;
@@ -60,7 +53,7 @@ var Knex = class {
60
53
  this.config.connection[key.replace("connection_", "")] = value;
61
54
  } else this.config[key] = value;
62
55
  }
63
- if ((_b = (_a = data.config.plugins) == null ? void 0 : _a[this.name]) == null ? void 0 : _b.config)
56
+ if (data.config.plugins?.[this.name]?.config)
64
57
  this.config = deepMerge(
65
58
  data.config.plugins[this.name].config,
66
59
  this.config
@@ -150,7 +143,7 @@ var Knex = class {
150
143
  */
151
144
  async transaction(scope, config, options) {
152
145
  if (!this.adapter) throw Error(`[${this.name}] Client not initialized.`);
153
- if (options == null ? void 0 : options.trx) return scope(options.trx);
146
+ if (options?.trx) return scope(options.trx);
154
147
  const trx = await this.adapter.transaction(config);
155
148
  const trxId = randomUUID();
156
149
  this.logger.debug("[%s] [%s] transaction begin", this.name, trxId);
@@ -200,7 +193,7 @@ var Knex = class {
200
193
  }
201
194
  };
202
195
  function useKnex(config) {
203
- const name = (config == null ? void 0 : config.name) || Name;
196
+ const name = config?.name || Name;
204
197
  if (global.FaasJS_Knex[name]) return usePlugin(global.FaasJS_Knex[name]);
205
198
  return usePlugin(new Knex(config));
206
199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/knex",
3
- "version": "2.9.0",
3
+ "version": "3.0.0-canary.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": "2.9.0",
38
- "@faasjs/func": "2.9.0",
39
- "@faasjs/logger": "2.9.0"
37
+ "@faasjs/deep_merge": "3.0.0-canary.2",
38
+ "@faasjs/func": "3.0.0-canary.2",
39
+ "@faasjs/logger": "3.0.0-canary.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "knex": "*"
@@ -52,7 +52,7 @@
52
52
  "tsd": "*"
53
53
  },
54
54
  "engines": {
55
- "npm": ">=9.0.0",
56
- "node": ">=18.0.0"
55
+ "node": ">=22.0.0",
56
+ "npm": ">=10.0.0"
57
57
  }
58
58
  }