@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.
@@ -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.Config["database"];
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,MAAM,CAAC,UAAU,CAAC,CAAC;CACpC,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"}
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
@@ -55,6 +55,7 @@ export declare class Config {
55
55
  user?: string | undefined;
56
56
  password?: string | undefined;
57
57
  database?: string | undefined;
58
+ ssl?: Record<string, any> | undefined;
58
59
  };
59
60
  };
60
61
  posts: {
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAET;IAED,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC;CAG5C"}
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":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC;AAG5C,MAAM,CAAC,OAAO,OAAO,QAAQ;;IAKf,OAAO,CAAC,MAAM;IAJ1B,MAAM,CAAC,WAAW,EAAE,IAAI,EAAE,CAAM;IAChC,MAAM,CAAC,aAAa,qCAAgC;gBAGhC,MAAM,EAAE,MAAM;IAmBlC,IAAI,MAAM,WAET;IAEK,QAAQ,CAAC,SAAS,EAAE,MAAM;IAIhC,IAAI,UAAU,qBAEb;IAED,IAAI,WAAW,0CAEd;IAED,IAAI,MAAM,uBAET;IAED,eAAe;IAUf,MAAM,CAAC,QAAQ;CAOhB"}
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 constants_1 = require("./constants");
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
- const constants_2 = require("./constants");
20
- const moment_1 = __importDefault(require("moment"));
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 connections = [];
25
- static perSiteTables = constants_2.DEFAULT_DATABASE_TABLES.blog;
26
- #knex;
29
+ static perSiteTables = constants_1.DEFAULT_DATABASE_TABLES.blog;
30
+ connectionKey;
27
31
  constructor(config) {
28
32
  this.config = config;
29
- // eslint-disable-next-line @typescript-eslint/no-var-requires
30
- this.#knex = require("knex")({
31
- ...this.config.config.database,
32
- connection: {
33
- ...this.config.config.database.connection,
34
- timezone: "+00:00", // UTC
35
- typeCast: (field, next) => {
36
- if (field.type == "DATETIME") {
37
- return (0, moment_1.default)(field.string()).format("YYYY-MM-DD HH:mm:ss");
38
- }
39
- return next();
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
- Database_1.connections.push(this.#knex);
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.#knex;
59
+ return knexInstances.get(this.connectionKey);
53
60
  }
54
61
  get transaction() {
55
- return this.#knex.transaction();
62
+ return knexInstances.get(this.connectionKey).transaction();
56
63
  }
57
64
  get schema() {
58
- return this.#knex.schema;
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 conn of Database_1.connections) {
71
- conn.destroy();
68
+ for (const knex of knexInstances.values()) {
69
+ knex.destroy();
72
70
  }
73
- Database_1.connections = [];
71
+ knexInstances.clear();
74
72
  }
75
73
  };
76
- Database = Database_1 = __decorate([
77
- (0, component_1.component)({ scope: constants_1.Scope.Singleton }),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnaga/wp-node",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && tsc --project tsconfig.build.json && npm run copyfiles && cp package.json ./dist/",
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 JSONWPConfig = DeepPartial<Exclude<Config, "database">> &
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
  }>;
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwHjB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAA+B,CAAC"}
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"}
@@ -97,6 +97,7 @@ exports.config = zod_1.z.object({
97
97
  .string()
98
98
  .optional()
99
99
  .refine((v) => v && v.length > 0),
100
+ ssl: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
100
101
  }),
101
102
  }),
102
103
  posts: zod_1.z.object({