@faasjs/knex 0.0.3-beta.1 → 0.0.3-beta.100
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 +2 -2
- package/dist/index.d.mts +41 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +42 -52
- package/dist/index.mjs +22 -17
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -130,7 +130,7 @@ ___
|
|
|
130
130
|
|
|
131
131
|
### useKnex
|
|
132
132
|
|
|
133
|
-
▸ **useKnex**(`config?`): [`Knex`](classes/Knex.md)
|
|
133
|
+
▸ **useKnex**(`config?`): `UseifyPlugin`<[`Knex`](classes/Knex.md)\>
|
|
134
134
|
|
|
135
135
|
#### Parameters
|
|
136
136
|
|
|
@@ -140,4 +140,4 @@ ___
|
|
|
140
140
|
|
|
141
141
|
#### Returns
|
|
142
142
|
|
|
143
|
-
[`Knex`](classes/Knex.md)
|
|
143
|
+
`UseifyPlugin`<[`Knex`](classes/Knex.md)\>
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Plugin, DeployData, Next, MountData, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
2
|
+
import { Logger } from '@faasjs/logger';
|
|
3
|
+
import { Knex as Knex$1 } from 'knex';
|
|
4
|
+
export { Knex as K } from 'knex';
|
|
5
|
+
|
|
6
|
+
type KnexConfig = {
|
|
7
|
+
name?: string;
|
|
8
|
+
config?: Knex$1.Config;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
declare class Knex implements Plugin {
|
|
12
|
+
readonly type: string;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
config: Knex$1.Config;
|
|
15
|
+
adapter: Knex$1;
|
|
16
|
+
query: Knex$1;
|
|
17
|
+
logger: Logger;
|
|
18
|
+
constructor(config?: KnexConfig);
|
|
19
|
+
onDeploy(data: DeployData, next: Next): Promise<void>;
|
|
20
|
+
onMount(data: MountData, next: Next): Promise<void>;
|
|
21
|
+
onInvoke(data: InvokeData<any, any, any>, next: Next): Promise<void>;
|
|
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>;
|
|
24
|
+
schema(): Knex$1.SchemaBuilder;
|
|
25
|
+
quit(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
declare function useKnex(config?: KnexConfig): UseifyPlugin<Knex>;
|
|
28
|
+
declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.QueryBuilder<Knex$1.TableType<TName>, {
|
|
29
|
+
_base: Knex$1.ResolveTableType<Knex$1.TableType<TName>, 'base'>;
|
|
30
|
+
_hasSelection: false;
|
|
31
|
+
_keys: never;
|
|
32
|
+
_aliases: {};
|
|
33
|
+
_single: false;
|
|
34
|
+
_intersectProps: {};
|
|
35
|
+
_unionProps: never;
|
|
36
|
+
}[]>;
|
|
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>;
|
|
39
|
+
declare function raw<TResult = any>(sql: string, bindings?: Knex$1.RawBinding[] | Knex$1.ValueDict): Promise<TResult>;
|
|
40
|
+
|
|
41
|
+
export { Knex, KnexConfig, query, raw, transaction, useKnex };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Plugin, DeployData, Next, MountData, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
2
|
+
import { Logger } from '@faasjs/logger';
|
|
2
3
|
import { Knex as Knex$1 } from 'knex';
|
|
3
4
|
export { Knex as K } from 'knex';
|
|
4
5
|
|
|
@@ -13,7 +14,7 @@ declare class Knex implements Plugin {
|
|
|
13
14
|
config: Knex$1.Config;
|
|
14
15
|
adapter: Knex$1;
|
|
15
16
|
query: Knex$1;
|
|
16
|
-
|
|
17
|
+
logger: Logger;
|
|
17
18
|
constructor(config?: KnexConfig);
|
|
18
19
|
onDeploy(data: DeployData, next: Next): Promise<void>;
|
|
19
20
|
onMount(data: MountData, next: Next): Promise<void>;
|
|
@@ -23,7 +24,7 @@ declare class Knex implements Plugin {
|
|
|
23
24
|
schema(): Knex$1.SchemaBuilder;
|
|
24
25
|
quit(): Promise<void>;
|
|
25
26
|
}
|
|
26
|
-
declare function useKnex(config?: KnexConfig): Knex
|
|
27
|
+
declare function useKnex(config?: KnexConfig): UseifyPlugin<Knex>;
|
|
27
28
|
declare function query<TName extends Knex$1.TableNames>(table: TName): Knex$1.QueryBuilder<Knex$1.TableType<TName>, {
|
|
28
29
|
_base: Knex$1.ResolveTableType<Knex$1.TableType<TName>, 'base'>;
|
|
29
30
|
_hasSelection: false;
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var func = require('@faasjs/func');
|
|
4
|
+
var logger = require('@faasjs/logger');
|
|
5
|
+
var deep_merge = require('@faasjs/deep_merge');
|
|
6
|
+
var knex = require('knex');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
9
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
var knex__default = /*#__PURE__*/_interopDefault(knex);
|
|
11
|
+
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
13
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
14
|
+
}) : x)(function(x) {
|
|
15
|
+
if (typeof require !== "undefined")
|
|
16
|
+
return require.apply(this, arguments);
|
|
17
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
34
18
|
});
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var import_func = require("@faasjs/func");
|
|
37
|
-
var import_logger = require("@faasjs/logger");
|
|
38
|
-
var import_deep_merge = require("@faasjs/deep_merge");
|
|
39
|
-
var import_knex = __toESM(require("knex"));
|
|
40
19
|
var Name = "knex";
|
|
41
20
|
if (!global["FaasJS_Knex"]) {
|
|
42
21
|
global.FaasJS_Knex = {};
|
|
@@ -62,11 +41,11 @@ var Knex = class {
|
|
|
62
41
|
data.dependencies["better-sqlite3"] = "*";
|
|
63
42
|
else
|
|
64
43
|
data.dependencies[client] = "*";
|
|
65
|
-
new
|
|
44
|
+
new logger.Logger(this.name).debug("add dependencies: " + client);
|
|
66
45
|
await next();
|
|
67
46
|
}
|
|
68
47
|
async onMount(data, next) {
|
|
69
|
-
var _a;
|
|
48
|
+
var _a, _b;
|
|
70
49
|
this.logger = data.logger;
|
|
71
50
|
if (global.FaasJS_Knex[this.name]) {
|
|
72
51
|
this.config = global.FaasJS_Knex[this.name].config;
|
|
@@ -90,12 +69,25 @@ var Knex = class {
|
|
|
90
69
|
this.config[key] = value;
|
|
91
70
|
}
|
|
92
71
|
if (data.config.plugins && ((_a = data.config.plugins[this.name]) == null ? void 0 : _a.config))
|
|
93
|
-
this.config =
|
|
72
|
+
this.config = deep_merge.deepMerge(data.config.plugins[this.name].config, this.config);
|
|
94
73
|
if (this.config.client === "sqlite3")
|
|
95
74
|
this.config.client = "better-sqlite3";
|
|
96
|
-
this.
|
|
75
|
+
if (this.config.client === "pg" && typeof ((_b = this.config.pool) == null ? void 0 : _b.propagateCreateError) === "undefined") {
|
|
76
|
+
if (!this.config.pool)
|
|
77
|
+
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);
|
|
85
|
+
if (typeof this.config.connection === "string" && !this.config.connection.includes("json=true"))
|
|
86
|
+
this.config.connection = this.config.connection + "?json=true";
|
|
87
|
+
}
|
|
88
|
+
this.adapter = knex__default.default(this.config);
|
|
97
89
|
if (this.config.client === "pg") {
|
|
98
|
-
const pg =
|
|
90
|
+
const pg = __require("pg");
|
|
99
91
|
const intTypes = [
|
|
100
92
|
"INT2",
|
|
101
93
|
"INT4",
|
|
@@ -171,8 +163,8 @@ var Knex = class {
|
|
|
171
163
|
function useKnex(config) {
|
|
172
164
|
const name = (config == null ? void 0 : config.name) || Name;
|
|
173
165
|
if (global.FaasJS_Knex[name])
|
|
174
|
-
return
|
|
175
|
-
return
|
|
166
|
+
return func.usePlugin(global.FaasJS_Knex[name]);
|
|
167
|
+
return func.usePlugin(new Knex(config));
|
|
176
168
|
}
|
|
177
169
|
function query(table) {
|
|
178
170
|
return useKnex().query(table);
|
|
@@ -183,11 +175,9 @@ async function transaction(scope, config) {
|
|
|
183
175
|
async function raw(sql, bindings = []) {
|
|
184
176
|
return useKnex().raw(sql, bindings);
|
|
185
177
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
useKnex
|
|
193
|
-
});
|
|
178
|
+
|
|
179
|
+
exports.Knex = Knex;
|
|
180
|
+
exports.query = query;
|
|
181
|
+
exports.raw = raw;
|
|
182
|
+
exports.transaction = transaction;
|
|
183
|
+
exports.useKnex = useKnex;
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
+
import { usePlugin } from '@faasjs/func';
|
|
2
|
+
import { Logger } from '@faasjs/logger';
|
|
3
|
+
import { deepMerge } from '@faasjs/deep_merge';
|
|
4
|
+
import knex from 'knex';
|
|
5
|
+
|
|
1
6
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
7
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
8
|
}) : x)(function(x) {
|
|
4
9
|
if (typeof require !== "undefined")
|
|
5
10
|
return require.apply(this, arguments);
|
|
6
|
-
throw
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
12
|
});
|
|
8
|
-
|
|
9
|
-
// src/index.ts
|
|
10
|
-
import {
|
|
11
|
-
usePlugin
|
|
12
|
-
} from "@faasjs/func";
|
|
13
|
-
import { Logger } from "@faasjs/logger";
|
|
14
|
-
import { deepMerge } from "@faasjs/deep_merge";
|
|
15
|
-
import knex from "knex";
|
|
16
13
|
var Name = "knex";
|
|
17
14
|
if (!global["FaasJS_Knex"]) {
|
|
18
15
|
global.FaasJS_Knex = {};
|
|
@@ -42,7 +39,7 @@ var Knex = class {
|
|
|
42
39
|
await next();
|
|
43
40
|
}
|
|
44
41
|
async onMount(data, next) {
|
|
45
|
-
var _a;
|
|
42
|
+
var _a, _b;
|
|
46
43
|
this.logger = data.logger;
|
|
47
44
|
if (global.FaasJS_Knex[this.name]) {
|
|
48
45
|
this.config = global.FaasJS_Knex[this.name].config;
|
|
@@ -69,6 +66,19 @@ var Knex = class {
|
|
|
69
66
|
this.config = deepMerge(data.config.plugins[this.name].config, this.config);
|
|
70
67
|
if (this.config.client === "sqlite3")
|
|
71
68
|
this.config.client = "better-sqlite3";
|
|
69
|
+
if (this.config.client === "pg" && typeof ((_b = this.config.pool) == null ? void 0 : _b.propagateCreateError) === "undefined") {
|
|
70
|
+
if (!this.config.pool)
|
|
71
|
+
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);
|
|
79
|
+
if (typeof this.config.connection === "string" && !this.config.connection.includes("json=true"))
|
|
80
|
+
this.config.connection = this.config.connection + "?json=true";
|
|
81
|
+
}
|
|
72
82
|
this.adapter = knex(this.config);
|
|
73
83
|
if (this.config.client === "pg") {
|
|
74
84
|
const pg = __require("pg");
|
|
@@ -159,10 +169,5 @@ async function transaction(scope, config) {
|
|
|
159
169
|
async function raw(sql, bindings = []) {
|
|
160
170
|
return useKnex().raw(sql, bindings);
|
|
161
171
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
query,
|
|
165
|
-
raw,
|
|
166
|
-
transaction,
|
|
167
|
-
useKnex
|
|
168
|
-
};
|
|
172
|
+
|
|
173
|
+
export { Knex, query, raw, transaction, useKnex };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/knex",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.100",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,16 +15,15 @@
|
|
|
15
15
|
},
|
|
16
16
|
"funding": "https://github.com/sponsors/faasjs",
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "tsup-node src/index.ts --
|
|
19
|
-
"build:types": "tsup-node src/index.ts --dts-only"
|
|
18
|
+
"build": "tsup-node src/index.ts --config ../../tsup.config.json"
|
|
20
19
|
},
|
|
21
20
|
"files": [
|
|
22
21
|
"dist"
|
|
23
22
|
],
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@faasjs/deep_merge": "
|
|
26
|
-
"@faasjs/func": "
|
|
27
|
-
"@faasjs/logger": "
|
|
24
|
+
"@faasjs/deep_merge": "0.0.3-beta.100",
|
|
25
|
+
"@faasjs/func": "0.0.3-beta.100",
|
|
26
|
+
"@faasjs/logger": "0.0.3-beta.100",
|
|
28
27
|
"knex": "*"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|