@faasjs/knex 8.0.0-beta.7 → 8.0.0-beta.8
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 -0
- package/dist/index.cjs +45 -17
- package/dist/index.d.ts +32 -3
- package/dist/index.mjs +45 -18
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -25,10 +25,12 @@ npm install @faasjs/knex
|
|
|
25
25
|
## Classes
|
|
26
26
|
|
|
27
27
|
- [Knex](classes/Knex.md)
|
|
28
|
+
- [KnexSchema](classes/KnexSchema.md)
|
|
28
29
|
|
|
29
30
|
## Type Aliases
|
|
30
31
|
|
|
31
32
|
- [KnexConfig](type-aliases/KnexConfig.md)
|
|
33
|
+
- [MountedKnexAdapter](type-aliases/MountedKnexAdapter.md)
|
|
32
34
|
- [MountFaasKnexOptions](type-aliases/MountFaasKnexOptions.md)
|
|
33
35
|
|
|
34
36
|
## Variables
|
package/dist/index.cjs
CHANGED
|
@@ -27,12 +27,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
29
|
let node_crypto = require("node:crypto");
|
|
30
|
-
let
|
|
30
|
+
let node_fs = require("node:fs");
|
|
31
|
+
let node_path = require("node:path");
|
|
31
32
|
let _faasjs_node_utils = require("@faasjs/node-utils");
|
|
32
33
|
let knex = require("knex");
|
|
33
34
|
knex = __toESM(knex);
|
|
34
|
-
let
|
|
35
|
-
let node_path = require("node:path");
|
|
35
|
+
let _faasjs_func = require("@faasjs/func");
|
|
36
36
|
|
|
37
37
|
//#region src/pglite.ts
|
|
38
38
|
function parsePgliteConnection(connection) {
|
|
@@ -105,20 +105,7 @@ function unmountFaasKnex(name = "knex") {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
//#endregion
|
|
108
|
-
//#region src/
|
|
109
|
-
/**
|
|
110
|
-
* FaasJS's sql plugin, base on [Knex](https://knexjs.org/).
|
|
111
|
-
*
|
|
112
|
-
* [](https://github.com/faasjs/faasjs/blob/main/packages/knex/LICENSE)
|
|
113
|
-
* [](https://www.npmjs.com/package/@faasjs/knex)
|
|
114
|
-
*
|
|
115
|
-
* ## Install
|
|
116
|
-
*
|
|
117
|
-
* ```sh
|
|
118
|
-
* npm install @faasjs/knex
|
|
119
|
-
* ```
|
|
120
|
-
* @packageDocumentation
|
|
121
|
-
*/
|
|
108
|
+
//#region src/plugin.ts
|
|
122
109
|
/**
|
|
123
110
|
* Origin [knex](https://knexjs.org/) instance.
|
|
124
111
|
*/
|
|
@@ -299,8 +286,49 @@ async function raw(sql, bindings = []) {
|
|
|
299
286
|
return useKnex().raw(sql, bindings);
|
|
300
287
|
}
|
|
301
288
|
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/schema.ts
|
|
291
|
+
const DefaultMigratorConfig = {
|
|
292
|
+
directory: "./src/db/migrations",
|
|
293
|
+
extension: "ts"
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Migration helper for FaasJS's knex plugin.
|
|
297
|
+
*/
|
|
298
|
+
var KnexSchema = class {
|
|
299
|
+
knex;
|
|
300
|
+
constructor(knex) {
|
|
301
|
+
this.knex = knex;
|
|
302
|
+
}
|
|
303
|
+
getAdapter() {
|
|
304
|
+
if (!this.knex.adapter) throw Error(`[${this.knex.name}] Client not initialized.`);
|
|
305
|
+
return this.knex.adapter;
|
|
306
|
+
}
|
|
307
|
+
getMigratorConfig() {
|
|
308
|
+
return Object.assign({}, DefaultMigratorConfig, this.knex.config?.migrations || Object.create(null));
|
|
309
|
+
}
|
|
310
|
+
async migrateLatest() {
|
|
311
|
+
return this.getAdapter().migrate.latest(this.getMigratorConfig());
|
|
312
|
+
}
|
|
313
|
+
async migrateRollback() {
|
|
314
|
+
return this.getAdapter().migrate.rollback(this.getMigratorConfig());
|
|
315
|
+
}
|
|
316
|
+
async migrateStatus() {
|
|
317
|
+
return this.getAdapter().migrate.status(this.getMigratorConfig());
|
|
318
|
+
}
|
|
319
|
+
async migrateCurrentVersion() {
|
|
320
|
+
return this.getAdapter().migrate.currentVersion(this.getMigratorConfig());
|
|
321
|
+
}
|
|
322
|
+
async migrateMake(name) {
|
|
323
|
+
const migrationName = name?.trim();
|
|
324
|
+
if (!migrationName) throw Error("[KnexSchema] Missing migration name. Usage: npm run migrate:make -- create_users");
|
|
325
|
+
return this.getAdapter().migrate.make(migrationName, this.getMigratorConfig());
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
302
329
|
//#endregion
|
|
303
330
|
exports.Knex = Knex;
|
|
331
|
+
exports.KnexSchema = KnexSchema;
|
|
304
332
|
exports.createPgliteKnex = createPgliteKnex;
|
|
305
333
|
exports.initPostgresTypeParsers = initPostgresTypeParsers;
|
|
306
334
|
exports.mountFaasKnex = mountFaasKnex;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { InvokeData, MountData, Next, Plugin, UseifyPlugin } from "@faasjs/func";
|
|
2
1
|
import knex, { Knex as Knex$1, Knex as OriginKnex } from "knex";
|
|
2
|
+
import { InvokeData, MountData, Next, Plugin, UseifyPlugin } from "@faasjs/func";
|
|
3
3
|
import { Logger } from "@faasjs/logger";
|
|
4
4
|
|
|
5
5
|
//#region src/pglite.d.ts
|
|
6
|
+
type MountedKnexAdapter = {
|
|
7
|
+
adapter: Knex$1;
|
|
8
|
+
query: Knex$1;
|
|
9
|
+
config: Record<string, unknown>;
|
|
10
|
+
};
|
|
6
11
|
type MountFaasKnexOptions = {
|
|
7
12
|
/** key of `globalThis.FaasJS_Knex`, default is `knex` */name?: string; /** optional config metadata passed through to `@faasjs/knex` */
|
|
8
13
|
config?: Record<string, unknown>;
|
|
@@ -21,7 +26,7 @@ declare function mountFaasKnex(db: Knex$1, options?: MountFaasKnexOptions): void
|
|
|
21
26
|
*/
|
|
22
27
|
declare function unmountFaasKnex(name?: string): void;
|
|
23
28
|
//#endregion
|
|
24
|
-
//#region src/
|
|
29
|
+
//#region src/plugin.d.ts
|
|
25
30
|
/**
|
|
26
31
|
* Origin [knex](https://knexjs.org/) instance.
|
|
27
32
|
*/
|
|
@@ -69,4 +74,28 @@ declare function transaction<TResult = any>(scope: (trx: OriginKnex.Transaction<
|
|
|
69
74
|
}): Promise<TResult>;
|
|
70
75
|
declare function raw<TResult = any>(sql: string, bindings?: OriginKnex.RawBinding[] | OriginKnex.ValueDict): Promise<OriginKnex.Raw<TResult>>;
|
|
71
76
|
//#endregion
|
|
72
|
-
|
|
77
|
+
//#region src/schema.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* Migration helper for FaasJS's knex plugin.
|
|
80
|
+
*/
|
|
81
|
+
declare class KnexSchema {
|
|
82
|
+
readonly knex: {
|
|
83
|
+
name: string;
|
|
84
|
+
adapter?: Knex$1;
|
|
85
|
+
config: Knex$1.Config;
|
|
86
|
+
};
|
|
87
|
+
constructor(knex: {
|
|
88
|
+
name: string;
|
|
89
|
+
adapter?: Knex$1;
|
|
90
|
+
config: Knex$1.Config;
|
|
91
|
+
});
|
|
92
|
+
private getAdapter;
|
|
93
|
+
private getMigratorConfig;
|
|
94
|
+
migrateLatest(): Promise<any>;
|
|
95
|
+
migrateRollback(): Promise<any>;
|
|
96
|
+
migrateStatus(): Promise<number>;
|
|
97
|
+
migrateCurrentVersion(): Promise<string>;
|
|
98
|
+
migrateMake(name: string): Promise<string>;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { Knex, KnexConfig, KnexSchema, MountFaasKnexOptions, MountedKnexAdapter, type OriginKnex, createPgliteKnex, initPostgresTypeParsers, mountFaasKnex, originKnex, query, raw, transaction, unmountFaasKnex, useKnex };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { usePlugin } from "@faasjs/func";
|
|
3
|
-
import { deepMerge, loadPackage } from "@faasjs/node-utils";
|
|
4
|
-
import knex from "knex";
|
|
5
2
|
import { mkdirSync } from "node:fs";
|
|
6
3
|
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { deepMerge, loadPackage } from "@faasjs/node-utils";
|
|
5
|
+
import knex from "knex";
|
|
6
|
+
import { usePlugin } from "@faasjs/func";
|
|
7
7
|
|
|
8
8
|
//#region src/pglite.ts
|
|
9
9
|
function parsePgliteConnection(connection) {
|
|
@@ -76,20 +76,7 @@ function unmountFaasKnex(name = "knex") {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
//#endregion
|
|
79
|
-
//#region src/
|
|
80
|
-
/**
|
|
81
|
-
* FaasJS's sql plugin, base on [Knex](https://knexjs.org/).
|
|
82
|
-
*
|
|
83
|
-
* [](https://github.com/faasjs/faasjs/blob/main/packages/knex/LICENSE)
|
|
84
|
-
* [](https://www.npmjs.com/package/@faasjs/knex)
|
|
85
|
-
*
|
|
86
|
-
* ## Install
|
|
87
|
-
*
|
|
88
|
-
* ```sh
|
|
89
|
-
* npm install @faasjs/knex
|
|
90
|
-
* ```
|
|
91
|
-
* @packageDocumentation
|
|
92
|
-
*/
|
|
79
|
+
//#region src/plugin.ts
|
|
93
80
|
/**
|
|
94
81
|
* Origin [knex](https://knexjs.org/) instance.
|
|
95
82
|
*/
|
|
@@ -271,4 +258,44 @@ async function raw(sql, bindings = []) {
|
|
|
271
258
|
}
|
|
272
259
|
|
|
273
260
|
//#endregion
|
|
274
|
-
|
|
261
|
+
//#region src/schema.ts
|
|
262
|
+
const DefaultMigratorConfig = {
|
|
263
|
+
directory: "./src/db/migrations",
|
|
264
|
+
extension: "ts"
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Migration helper for FaasJS's knex plugin.
|
|
268
|
+
*/
|
|
269
|
+
var KnexSchema = class {
|
|
270
|
+
knex;
|
|
271
|
+
constructor(knex) {
|
|
272
|
+
this.knex = knex;
|
|
273
|
+
}
|
|
274
|
+
getAdapter() {
|
|
275
|
+
if (!this.knex.adapter) throw Error(`[${this.knex.name}] Client not initialized.`);
|
|
276
|
+
return this.knex.adapter;
|
|
277
|
+
}
|
|
278
|
+
getMigratorConfig() {
|
|
279
|
+
return Object.assign({}, DefaultMigratorConfig, this.knex.config?.migrations || Object.create(null));
|
|
280
|
+
}
|
|
281
|
+
async migrateLatest() {
|
|
282
|
+
return this.getAdapter().migrate.latest(this.getMigratorConfig());
|
|
283
|
+
}
|
|
284
|
+
async migrateRollback() {
|
|
285
|
+
return this.getAdapter().migrate.rollback(this.getMigratorConfig());
|
|
286
|
+
}
|
|
287
|
+
async migrateStatus() {
|
|
288
|
+
return this.getAdapter().migrate.status(this.getMigratorConfig());
|
|
289
|
+
}
|
|
290
|
+
async migrateCurrentVersion() {
|
|
291
|
+
return this.getAdapter().migrate.currentVersion(this.getMigratorConfig());
|
|
292
|
+
}
|
|
293
|
+
async migrateMake(name) {
|
|
294
|
+
const migrationName = name?.trim();
|
|
295
|
+
if (!migrationName) throw Error("[KnexSchema] Missing migration name. Usage: npm run migrate:make -- create_users");
|
|
296
|
+
return this.getAdapter().migrate.make(migrationName, this.getMigratorConfig());
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
//#endregion
|
|
301
|
+
export { Knex, KnexSchema, createPgliteKnex, initPostgresTypeParsers, mountFaasKnex, originKnex, query, raw, transaction, unmountFaasKnex, useKnex };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/knex",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"knex": "*",
|
|
34
|
-
"@faasjs/func": ">=8.0.0-beta.
|
|
35
|
-
"@faasjs/logger": ">=8.0.0-beta.
|
|
36
|
-
"@faasjs/node-utils": ">=8.0.0-beta.
|
|
34
|
+
"@faasjs/func": ">=8.0.0-beta.8",
|
|
35
|
+
"@faasjs/logger": ">=8.0.0-beta.8",
|
|
36
|
+
"@faasjs/node-utils": ">=8.0.0-beta.8"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"knex": "*",
|
|
40
|
-
"@faasjs/func": ">=8.0.0-beta.
|
|
41
|
-
"@faasjs/logger": ">=8.0.0-beta.
|
|
42
|
-
"@faasjs/node-utils": ">=8.0.0-beta.
|
|
40
|
+
"@faasjs/func": ">=8.0.0-beta.8",
|
|
41
|
+
"@faasjs/logger": ">=8.0.0-beta.8",
|
|
42
|
+
"@faasjs/node-utils": ">=8.0.0-beta.8",
|
|
43
43
|
"better-sqlite3": "*",
|
|
44
44
|
"knex-pglite": "*",
|
|
45
45
|
"@types/pg": "*",
|