@rnaga/wp-node 1.3.3 → 1.3.5
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/common/config/define-wp.config..d.ts +1 -1
- package/common/config/define-wp.config..d.ts.map +1 -1
- package/config.d.ts +1 -0
- package/config.d.ts.map +1 -1
- package/database.d.ts +1 -3
- package/database.d.ts.map +1 -1
- package/database.js +37 -39
- package/package.json +1 -1
- package/types/config.d.ts +3 -1
- package/validators/config.d.ts +2 -0
- package/validators/config.d.ts.map +1 -1
- package/validators/config.js +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as types from "../../types";
|
|
2
2
|
export declare const defineWPConfig: (config: Required<{
|
|
3
3
|
staticAssetsPath: types.Config["staticAssetsPath"];
|
|
4
|
-
database: types.
|
|
4
|
+
database: types.DatabaseConfig;
|
|
5
5
|
}> & Partial<{
|
|
6
6
|
postTypeObject: types.PostTypeObject;
|
|
7
7
|
postStatusObject: types.PostStatusObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-wp.config..d.ts","sourceRoot":"","sources":["../../../src/common/config/define-wp.config..ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAM1C,eAAO,MAAM,cAAc,GACzB,QAAQ,QAAQ,CAAC;IACf,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACnD,QAAQ,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"define-wp.config..d.ts","sourceRoot":"","sources":["../../../src/common/config/define-wp.config..ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAM1C,eAAO,MAAM,cAAc,GACzB,QAAQ,QAAQ,CAAC;IACf,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACnD,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC;CAChC,CAAC,GACA,OAAO,CAAC;IACN,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC;IACrC,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,CAAC;IACzC,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC;CAClC,CAAC,GACF,OAAO,CAAC;IACN,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;CAC1B,CAAC,GACF,KAAK,CAAC,YAAY,KAEnB,KAAK,CAAC,MAsER,CAAC"}
|
package/config.d.ts
CHANGED
package/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AAGtC,qBACa,MAAM;;gBAGL,MAAM,EAAE,KAAK,CAAC,MAAM;IAIhC,WAAW;IAIX,KAAK;IAKL,kBAAkB;IAOlB,IAAI,MAAM
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;AAGtC,qBACa,MAAM;;gBAGL,MAAM,EAAE,KAAK,CAAC,MAAM;IAIhC,WAAW;IAIX,KAAK;IAKL,kBAAkB;IAOlB,IAAI,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAET;IAED,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC;CAG5C"}
|
package/database.d.ts
CHANGED
|
@@ -2,17 +2,15 @@ import { Knex } from "knex";
|
|
|
2
2
|
import { Config } from "./config";
|
|
3
3
|
export type DbConnection = Knex | undefined;
|
|
4
4
|
export default class Database {
|
|
5
|
-
#private;
|
|
6
5
|
private config;
|
|
7
|
-
static connections: Knex[];
|
|
8
6
|
static perSiteTables: (keyof import("./types").Tables)[];
|
|
7
|
+
private connectionKey;
|
|
9
8
|
constructor(config: Config);
|
|
10
9
|
get prefix(): string;
|
|
11
10
|
hasTable(tableName: string): Promise<boolean>;
|
|
12
11
|
get connection(): Knex<any, any[]>;
|
|
13
12
|
get transaction(): Promise<Knex.Transaction<any, any[]>>;
|
|
14
13
|
get schema(): Knex.SchemaBuilder;
|
|
15
|
-
closeConnection(): void;
|
|
16
14
|
static closeAll(): void;
|
|
17
15
|
}
|
|
18
16
|
//# sourceMappingURL=database.d.ts.map
|
package/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC;AAY5C,MAAM,CAAC,OAAO,OAAO,QAAQ;IAIf,OAAO,CAAC,MAAM;IAH1B,MAAM,CAAC,aAAa,qCAAgC;IACpD,OAAO,CAAC,aAAa,CAAS;gBAEV,MAAM,EAAE,MAAM;IAsBlC,IAAI,MAAM,WAET;IAEK,QAAQ,CAAC,SAAS,EAAE,MAAM;IAIhC,IAAI,UAAU,qBAEb;IAED,IAAI,WAAW,0CAEd;IAED,IAAI,MAAM,uBAET;IAED,MAAM,CAAC,QAAQ;CAMhB"}
|
package/database.js
CHANGED
|
@@ -11,36 +11,43 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
|
-
var Database_1;
|
|
15
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const
|
|
15
|
+
const crypto_1 = require("crypto");
|
|
16
|
+
const moment_1 = __importDefault(require("moment"));
|
|
17
17
|
const config_1 = require("./config");
|
|
18
|
+
const constants_1 = require("./constants");
|
|
18
19
|
const component_1 = require("./decorators/component");
|
|
19
|
-
|
|
20
|
-
const
|
|
20
|
+
// Multiple Knex instances keyed by connection configuration
|
|
21
|
+
const knexInstances = new Map();
|
|
22
|
+
const generateConnectionKey = (config) => {
|
|
23
|
+
const connection = config.connection;
|
|
24
|
+
const connectionString = `${connection.host}:${connection.port}:${connection.database}:${connection.user}`;
|
|
25
|
+
return (0, crypto_1.createHash)("sha256").update(connectionString).digest("hex");
|
|
26
|
+
};
|
|
21
27
|
let Database = class Database {
|
|
22
|
-
static { Database_1 = this; }
|
|
23
28
|
config;
|
|
24
|
-
static
|
|
25
|
-
|
|
26
|
-
#knex;
|
|
29
|
+
static perSiteTables = constants_1.DEFAULT_DATABASE_TABLES.blog;
|
|
30
|
+
connectionKey;
|
|
27
31
|
constructor(config) {
|
|
28
32
|
this.config = config;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...this.config.config.database
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
this.connectionKey = generateConnectionKey(this.config.config.database);
|
|
34
|
+
if (!knexInstances.has(this.connectionKey)) {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
36
|
+
const knex = require("knex")({
|
|
37
|
+
...this.config.config.database,
|
|
38
|
+
connection: {
|
|
39
|
+
...this.config.config.database.connection,
|
|
40
|
+
timezone: "+00:00", // UTC
|
|
41
|
+
typeCast: (field, next) => {
|
|
42
|
+
if (field.type == "DATETIME") {
|
|
43
|
+
return (0, moment_1.default)(field.string()).format("YYYY-MM-DD HH:mm:ss");
|
|
44
|
+
}
|
|
45
|
+
return next();
|
|
46
|
+
},
|
|
40
47
|
},
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
});
|
|
49
|
+
knexInstances.set(this.connectionKey, knex);
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
get prefix() {
|
|
46
53
|
return this.config.config.tablePrefix;
|
|
@@ -49,32 +56,23 @@ let Database = class Database {
|
|
|
49
56
|
return await this.connection.schema.hasTable(tableName);
|
|
50
57
|
}
|
|
51
58
|
get connection() {
|
|
52
|
-
return this
|
|
59
|
+
return knexInstances.get(this.connectionKey);
|
|
53
60
|
}
|
|
54
61
|
get transaction() {
|
|
55
|
-
return this
|
|
62
|
+
return knexInstances.get(this.connectionKey).transaction();
|
|
56
63
|
}
|
|
57
64
|
get schema() {
|
|
58
|
-
return this
|
|
59
|
-
}
|
|
60
|
-
closeConnection() {
|
|
61
|
-
for (let i = 0; i < Database_1.connections.length; i++) {
|
|
62
|
-
if (Database_1.connections[i] === this.#knex) {
|
|
63
|
-
Database_1.connections.splice(i, 1);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
this.#knex.destroy();
|
|
65
|
+
return knexInstances.get(this.connectionKey).schema;
|
|
68
66
|
}
|
|
69
67
|
static closeAll() {
|
|
70
|
-
for (const
|
|
71
|
-
|
|
68
|
+
for (const knex of knexInstances.values()) {
|
|
69
|
+
knex.destroy();
|
|
72
70
|
}
|
|
73
|
-
|
|
71
|
+
knexInstances.clear();
|
|
74
72
|
}
|
|
75
73
|
};
|
|
76
|
-
Database =
|
|
77
|
-
(0, component_1.component)(
|
|
74
|
+
Database = __decorate([
|
|
75
|
+
(0, component_1.component)(),
|
|
78
76
|
__metadata("design:paramtypes", [config_1.Config])
|
|
79
77
|
], Database);
|
|
80
78
|
exports.default = Database;
|
package/package.json
CHANGED
package/types/config.d.ts
CHANGED
|
@@ -23,7 +23,9 @@ export type ConfigPostStatusObject = Omit<
|
|
|
23
23
|
"label" | "_builtin"
|
|
24
24
|
>;
|
|
25
25
|
|
|
26
|
-
export type
|
|
26
|
+
export type DatabaseConfig = Config["database"];
|
|
27
|
+
|
|
28
|
+
export type JSONWPConfig = DeepPartial<Omit<Config, "database">> &
|
|
27
29
|
Required<{
|
|
28
30
|
staticAssetsPath: Config["staticAssetsPath"];
|
|
29
31
|
}>;
|
package/validators/config.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export declare const config: z.ZodObject<{
|
|
|
57
57
|
charset: z.ZodString;
|
|
58
58
|
password: z.ZodOptional<z.ZodString>;
|
|
59
59
|
database: z.ZodOptional<z.ZodString>;
|
|
60
|
+
ssl: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
60
61
|
}, z.core.$strip>;
|
|
61
62
|
}, z.core.$strip>;
|
|
62
63
|
posts: z.ZodObject<{
|
|
@@ -206,6 +207,7 @@ export declare const configs: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
|
206
207
|
charset: z.ZodString;
|
|
207
208
|
password: z.ZodOptional<z.ZodString>;
|
|
208
209
|
database: z.ZodOptional<z.ZodString>;
|
|
210
|
+
ssl: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
209
211
|
}, z.core.$strip>;
|
|
210
212
|
}, z.core.$strip>;
|
|
211
213
|
posts: z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/validators/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/validators/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyHjB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAA+B,CAAC"}
|