@faasjs/knex 0.0.4-beta.4 → 0.0.4-beta.6

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
@@ -21,6 +21,7 @@ FaasJS's sql plugin, base on [Knex](https://knexjs.org/).
21
21
 
22
22
  ### Functions
23
23
 
24
+ - [originKnex](#originknex)
24
25
  - [query](#query)
25
26
  - [raw](#raw)
26
27
  - [transaction](#transaction)
@@ -36,14 +37,39 @@ FaasJS's sql plugin, base on [Knex](https://knexjs.org/).
36
37
 
37
38
  | Name | Type |
38
39
  | :------ | :------ |
39
- | `config?` | `K.Config` |
40
+ | `config?` | `OriginKnex.Config` |
40
41
  | `name?` | `string` |
41
42
 
42
43
  ## Functions
43
44
 
45
+ ### originKnex
46
+
47
+ ▸ **originKnex**<`TRecord`, `TResult`\>(`config`): `Knex`<`TRecord`, `TResult`\>
48
+
49
+ Origin [knex](https://knexjs.org/) instance.
50
+
51
+ #### Type parameters
52
+
53
+ | Name | Type |
54
+ | :------ | :------ |
55
+ | `TRecord` | extends `Object` = `any` |
56
+ | `TResult` | `unknown`[] |
57
+
58
+ #### Parameters
59
+
60
+ | Name | Type |
61
+ | :------ | :------ |
62
+ | `config` | `string` \| `Config`<`any`\> |
63
+
64
+ #### Returns
65
+
66
+ `Knex`<`TRecord`, `TResult`\>
67
+
68
+ ___
69
+
44
70
  ### query
45
71
 
46
- ▸ **query**<`TName`\>(`table`): `K.QueryBuilder`<`K.TableType`<`TName`\>, { `_aliases`: {} ; `_base`: `K.ResolveTableType`<`K.TableType`<`TName`\>, ``"base"``\> ; `_hasSelection`: ``false`` ; `_intersectProps`: {} ; `_keys`: `never` ; `_single`: ``false`` ; `_unionProps`: `never` }[]\>
72
+ ▸ **query**<`TName`\>(`table`): `OriginKnex.QueryBuilder`<`OriginKnex.TableType`<`TName`\>, { `_aliases`: {} ; `_base`: `OriginKnex.ResolveTableType`<`OriginKnex.TableType`<`TName`\>, ``"base"``\> ; `_hasSelection`: ``false`` ; `_intersectProps`: {} ; `_keys`: `never` ; `_single`: ``false`` ; `_unionProps`: `never` }[]\>
47
73
 
48
74
  #### Type parameters
49
75
 
@@ -59,9 +85,9 @@ FaasJS's sql plugin, base on [Knex](https://knexjs.org/).
59
85
 
60
86
  #### Returns
61
87
 
62
- `K.QueryBuilder`<`K.TableType`<`TName`\>, { `_aliases`: {} ; `_base`: `K.ResolveTableType`<`K.TableType`<`TName`\>, ``"base"``\> ; `_hasSelection`: ``false`` ; `_intersectProps`: {} ; `_keys`: `never` ; `_single`: ``false`` ; `_unionProps`: `never` }[]\>
88
+ `OriginKnex.QueryBuilder`<`OriginKnex.TableType`<`TName`\>, { `_aliases`: {} ; `_base`: `OriginKnex.ResolveTableType`<`OriginKnex.TableType`<`TName`\>, ``"base"``\> ; `_hasSelection`: ``false`` ; `_intersectProps`: {} ; `_keys`: `never` ; `_single`: ``false`` ; `_unionProps`: `never` }[]\>
63
89
 
64
- ▸ **query**<`TName`, `TResult`\>(`table`): `K.QueryBuilder`<`TName`, `TResult`\>
90
+ ▸ **query**<`TName`, `TResult`\>(`table`): `OriginKnex.QueryBuilder`<`TName`, `TResult`\>
65
91
 
66
92
  #### Type parameters
67
93
 
@@ -78,7 +104,7 @@ FaasJS's sql plugin, base on [Knex](https://knexjs.org/).
78
104
 
79
105
  #### Returns
80
106
 
81
- `K.QueryBuilder`<`TName`, `TResult`\>
107
+ `OriginKnex.QueryBuilder`<`TName`, `TResult`\>
82
108
 
83
109
  ___
84
110
 
@@ -107,7 +133,7 @@ ___
107
133
 
108
134
  ### transaction
109
135
 
110
- ▸ **transaction**<`TResult`\>(`scope`, `config?`): `Promise`<`TResult`\>
136
+ ▸ **transaction**<`TResult`\>(`scope`, `config?`, `options?`): `Promise`<`TResult` \| `void`\>
111
137
 
112
138
  #### Type parameters
113
139
 
@@ -121,10 +147,12 @@ ___
121
147
  | :------ | :------ |
122
148
  | `scope` | (`trx`: `Transaction`<`any`, `any`\>) => `void` \| `Promise`<`TResult`\> |
123
149
  | `config?` | `TransactionConfig` |
150
+ | `options?` | `Object` |
151
+ | `options.trx?` | `Transaction`<`any`, `any`[]\> |
124
152
 
125
153
  #### Returns
126
154
 
127
- `Promise`<`TResult`\>
155
+ `Promise`<`TResult` \| `void`\>
128
156
 
129
157
  ___
130
158
 
package/dist/index.d.mts CHANGED
@@ -1,13 +1,17 @@
1
1
  import { Plugin, DeployData, Next, MountData, InvokeData, UseifyPlugin } from '@faasjs/func';
2
2
  import { Logger } from '@faasjs/logger';
3
- import { Knex as Knex$1 } from 'knex';
4
- export { Knex as K } from 'knex';
3
+ import knex, { Knex as Knex$1 } from 'knex';
4
+ export { Knex as OriginKnex } from 'knex';
5
+
6
+ /**
7
+ * Origin [knex](https://knexjs.org/) instance.
8
+ */
9
+ declare const originKnex: typeof knex;
5
10
 
6
11
  type KnexConfig = {
7
12
  name?: string;
8
13
  config?: Knex$1.Config;
9
14
  };
10
-
11
15
  declare class Knex implements Plugin {
12
16
  readonly type: string;
13
17
  readonly name: string;
@@ -20,7 +24,9 @@ declare class Knex implements Plugin {
20
24
  onMount(data: MountData, next: Next): Promise<void>;
21
25
  onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
22
26
  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?: Knex$1.TransactionConfig): Promise<TResult>;
27
+ transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig, options?: {
28
+ trx?: Knex$1.Transaction;
29
+ }): Promise<TResult | void>;
24
30
  schema(): Knex$1.SchemaBuilder;
25
31
  quit(): Promise<void>;
26
32
  }
@@ -35,7 +41,9 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
35
41
  _unionProps: never;
36
42
  }[]>;
37
43
  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?: Knex$1.TransactionConfig): Promise<TResult>;
44
+ declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig, options?: {
45
+ trx?: Knex$1.Transaction;
46
+ }): Promise<TResult | void>;
39
47
  declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult>;
40
48
 
41
- export { Knex, KnexConfig, query, raw, transaction, useKnex };
49
+ export { Knex, KnexConfig, originKnex, query, raw, transaction, useKnex };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  import { Plugin, DeployData, Next, MountData, InvokeData, UseifyPlugin } from '@faasjs/func';
2
2
  import { Logger } from '@faasjs/logger';
3
- import { Knex as Knex$1 } from 'knex';
4
- export { Knex as K } from 'knex';
3
+ import knex, { Knex as Knex$1 } from 'knex';
4
+ export { Knex as OriginKnex } from 'knex';
5
+
6
+ /**
7
+ * Origin [knex](https://knexjs.org/) instance.
8
+ */
9
+ declare const originKnex: typeof knex;
5
10
 
6
11
  type KnexConfig = {
7
12
  name?: string;
8
13
  config?: Knex$1.Config;
9
14
  };
10
-
11
15
  declare class Knex implements Plugin {
12
16
  readonly type: string;
13
17
  readonly name: string;
@@ -20,7 +24,9 @@ declare class Knex implements Plugin {
20
24
  onMount(data: MountData, next: Next): Promise<void>;
21
25
  onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
22
26
  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?: Knex$1.TransactionConfig): Promise<TResult>;
27
+ transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig, options?: {
28
+ trx?: Knex$1.Transaction;
29
+ }): Promise<TResult | void>;
24
30
  schema(): Knex$1.SchemaBuilder;
25
31
  quit(): Promise<void>;
26
32
  }
@@ -35,7 +41,9 @@ declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.Qu
35
41
  _unionProps: never;
36
42
  }[]>;
37
43
  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?: Knex$1.TransactionConfig): Promise<TResult>;
44
+ declare function transaction<TResult = any>(scope: (trx: Knex$1.Transaction<any, any>) => Promise<TResult> | void, config?: Knex$1.TransactionConfig, options?: {
45
+ trx?: Knex$1.Transaction;
46
+ }): Promise<TResult | void>;
39
47
  declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult>;
40
48
 
41
- export { Knex, KnexConfig, query, raw, transaction, useKnex };
49
+ export { Knex, KnexConfig, originKnex, query, raw, transaction, useKnex };
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
16
16
  return require.apply(this, arguments);
17
17
  throw Error('Dynamic require of "' + x + '" is not supported');
18
18
  });
19
+ var originKnex = knex__default.default;
19
20
  var Name = "knex";
20
21
  if (!global.FaasJS_Knex) {
21
22
  global.FaasJS_Knex = {};
@@ -141,9 +142,11 @@ var Knex = class {
141
142
  throw Error("[Knex] Client not initialized.");
142
143
  return this.adapter.raw(sql, bindings);
143
144
  }
144
- async transaction(scope, config) {
145
+ async transaction(scope, config, options) {
145
146
  if (!this.adapter)
146
147
  throw Error(`[${this.name}] Client not initialized.`);
148
+ if (options == null ? void 0 : options.trx)
149
+ return scope(options.trx);
147
150
  return this.adapter.transaction(scope, config);
148
151
  }
149
152
  schema() {
@@ -167,16 +170,19 @@ function useKnex(config) {
167
170
  return func.usePlugin(new Knex(config));
168
171
  }
169
172
  function query(table) {
170
- return useKnex().query(table);
173
+ return useKnex().query(
174
+ table
175
+ );
171
176
  }
172
- async function transaction(scope, config) {
173
- return useKnex().transaction(scope, config);
177
+ async function transaction(scope, config, options) {
178
+ return useKnex().transaction(scope, config, options);
174
179
  }
175
180
  async function raw(sql, bindings = []) {
176
181
  return useKnex().raw(sql, bindings);
177
182
  }
178
183
 
179
184
  exports.Knex = Knex;
185
+ exports.originKnex = originKnex;
180
186
  exports.query = query;
181
187
  exports.raw = raw;
182
188
  exports.transaction = transaction;
package/dist/index.mjs CHANGED
@@ -10,6 +10,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
  return require.apply(this, arguments);
11
11
  throw Error('Dynamic require of "' + x + '" is not supported');
12
12
  });
13
+ var originKnex = knex;
13
14
  var Name = "knex";
14
15
  if (!global.FaasJS_Knex) {
15
16
  global.FaasJS_Knex = {};
@@ -135,9 +136,11 @@ var Knex = class {
135
136
  throw Error("[Knex] Client not initialized.");
136
137
  return this.adapter.raw(sql, bindings);
137
138
  }
138
- async transaction(scope, config) {
139
+ async transaction(scope, config, options) {
139
140
  if (!this.adapter)
140
141
  throw Error(`[${this.name}] Client not initialized.`);
142
+ if (options == null ? void 0 : options.trx)
143
+ return scope(options.trx);
141
144
  return this.adapter.transaction(scope, config);
142
145
  }
143
146
  schema() {
@@ -161,13 +164,15 @@ function useKnex(config) {
161
164
  return usePlugin(new Knex(config));
162
165
  }
163
166
  function query(table) {
164
- return useKnex().query(table);
167
+ return useKnex().query(
168
+ table
169
+ );
165
170
  }
166
- async function transaction(scope, config) {
167
- return useKnex().transaction(scope, config);
171
+ async function transaction(scope, config, options) {
172
+ return useKnex().transaction(scope, config, options);
168
173
  }
169
174
  async function raw(sql, bindings = []) {
170
175
  return useKnex().raw(sql, bindings);
171
176
  }
172
177
 
173
- export { Knex, query, raw, transaction, useKnex };
178
+ export { Knex, originKnex, query, raw, transaction, useKnex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/knex",
3
- "version": "0.0.4-beta.4",
3
+ "version": "0.0.4-beta.6",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,16 +20,15 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
+ "dependencies": {
24
+ "@faasjs/deep_merge": "0.0.4-beta.6",
25
+ "@faasjs/func": "0.0.4-beta.6",
26
+ "@faasjs/logger": "0.0.4-beta.6"
27
+ },
23
28
  "peerDependencies": {
24
- "@faasjs/deep_merge": "0.0.4-beta.4",
25
- "@faasjs/func": "0.0.4-beta.4",
26
- "@faasjs/logger": "0.0.4-beta.4",
27
29
  "knex": "*"
28
30
  },
29
31
  "devDependencies": {
30
- "@faasjs/deep_merge": "0.0.4-beta.4",
31
- "@faasjs/func": "0.0.4-beta.4",
32
- "@faasjs/logger": "0.0.4-beta.4",
33
32
  "knex": "*",
34
33
  "@types/mysql": "*",
35
34
  "@types/node": "*",