@creator.co/wapi 1.2.11 → 1.2.12

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "json-stringify-safe": "^5.0.1",
35
35
  "jsonwebtoken": "^9.0.2",
36
36
  "knex": "^3.0.1",
37
+ "knex-stringcase": "^1.4.6",
37
38
  "node-cache": "^5.1.2",
38
39
  "object-hash": "^3.0.0",
39
40
  "parse-duration": "^1.1.0",
@@ -14,6 +14,7 @@ export declare class KnexDatabase extends Database<KnexTransaction> {
14
14
  * @returns None
15
15
  */
16
16
  constructor(config: DbConfig<'knex'>);
17
+ private constructConfig;
17
18
  /**
18
19
  * Initiates a transaction using the underlying database client.
19
20
  * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object representing the transaction.
@@ -53,6 +53,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.KnexDatabase = void 0;
55
55
  var knex_1 = require("knex");
56
+ var knexStringcase = require("knex-stringcase");
56
57
  var KnexTransaction_1 = require("./KnexTransaction");
57
58
  var Database_1 = require("../../Database");
58
59
  /**
@@ -68,7 +69,11 @@ var KnexDatabase = /** @class */ (function (_super) {
68
69
  */
69
70
  function KnexDatabase(config) {
70
71
  var _this = _super.call(this, config) || this;
71
- _this.client = KnexDatabase.knexProvider({
72
+ _this.client = KnexDatabase.knexProvider(_this.constructConfig(config));
73
+ return _this;
74
+ }
75
+ KnexDatabase.prototype.constructConfig = function (config) {
76
+ var knexConfig = {
72
77
  client: config.driver,
73
78
  connection: {
74
79
  host: config.host,
@@ -81,9 +86,9 @@ var KnexDatabase = /** @class */ (function (_super) {
81
86
  min: 1,
82
87
  max: config.maxConnections,
83
88
  },
84
- });
85
- return _this;
86
- }
89
+ };
90
+ return config.convertCamelToSnake ? knexStringcase(knexConfig) : knexConfig;
91
+ };
87
92
  /**
88
93
  * Initiates a transaction using the underlying database client.
89
94
  * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object representing the transaction.
@@ -1 +1 @@
1
- {"version":3,"file":"KnexDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/knex/KnexDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAiC;AAEjC,qDAAwE;AACxE,2CAAyC;AAGzC;;;GAGG;AACH;IAAkC,gCAAyB;IAKzD;;;;OAIG;IACH,sBAAmB,MAAwB;QAA3C,YACE,kBAAM,MAAM,CAAC,SAed;QAdC,KAAI,CAAC,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC;YACtC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,UAAU,EAAE;gBACV,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B;YACD,IAAI,EAAE;gBACJ,GAAG,EAAE,CAAC;gBACN,GAAG,EAAE,MAAM,CAAC,cAAc;aAC3B;SACF,CAAC,CAAA;;IACJ,CAAC;IAED;;;OAGG;IACmB,kCAAW,GAAjC;;;;;4BACmB,qBAAM,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAA;;wBAA1C,QAAQ,GAAG,SAA+B;wBAChD,sBAAO,qCAAmB,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAA;;;;KACxD;IAlCc,yBAAY,GAAiE,cAAI,CAAA;IAmClG,mBAAC;CAA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AY,GAAiE,cAAI,CAAA;IA0ClG,mBAAC;CAAA,AA3CD,CAAkC,mBAAQ,GA2CzC;AA3CY,oCAAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "json-stringify-safe": "^5.0.1",
35
35
  "jsonwebtoken": "^9.0.2",
36
36
  "knex": "^3.0.1",
37
+ "knex-stringcase": "^1.4.6",
37
38
  "node-cache": "^5.1.2",
38
39
  "object-hash": "^3.0.0",
39
40
  "parse-duration": "^1.1.0",
@@ -1,4 +1,5 @@
1
1
  import knex, { Knex } from 'knex'
2
+ import * as knexStringcase from 'knex-stringcase'
2
3
 
3
4
  import { KnexTransaction, KnexTransactionImpl } from './KnexTransaction'
4
5
  import { Database } from '../../Database'
@@ -20,7 +21,12 @@ export class KnexDatabase extends Database<KnexTransaction> {
20
21
  */
21
22
  public constructor(config: DbConfig<'knex'>) {
22
23
  super(config)
23
- this.client = KnexDatabase.knexProvider({
24
+
25
+ this.client = KnexDatabase.knexProvider(this.constructConfig(config))
26
+ }
27
+
28
+ private constructConfig(config: DbConfig<'knex'>) {
29
+ const knexConfig = {
24
30
  client: config.driver,
25
31
  connection: {
26
32
  host: config.host,
@@ -33,7 +39,9 @@ export class KnexDatabase extends Database<KnexTransaction> {
33
39
  min: 1,
34
40
  max: config.maxConnections,
35
41
  },
36
- })
42
+ }
43
+
44
+ return config.convertCamelToSnake ? knexStringcase(knexConfig) : knexConfig
37
45
  }
38
46
 
39
47
  /**
@@ -34,9 +34,10 @@ export type DatabaseTransactionType<Type extends DatabaseType> =
34
34
  * @property {string} database - The name of the database to connect to.
35
35
  * @property {boolean} autoCommit - Whether or not to automatically commit transactions.
36
36
  * @property {number} maxConnections - The maximum number of connections to the database.
37
+ * @property {boolean} [convertCamelToSnake] - Whether or not to convert camel case to snake case for column names.
37
38
  * @returns The transaction type associated with the specified database type.
38
39
  */
39
- export interface DbConfig<S extends DatabaseType> {
40
+ export type DbConfig<S extends DatabaseType> = {
40
41
  type: S
41
42
  driver: string
42
43
  host: string
@@ -46,4 +47,8 @@ export interface DbConfig<S extends DatabaseType> {
46
47
  database: string
47
48
  autoCommit: boolean
48
49
  maxConnections: number
49
- }
50
+ } & (S extends 'knex'
51
+ ? {
52
+ convertCamelToSnake?: boolean
53
+ }
54
+ : any)
@@ -50,4 +50,27 @@ describe('KnexDatabase', () => {
50
50
  expect(trans).toBeInstanceOf(KnexTransactionImpl)
51
51
  expect(trans['delegate']).toBe(mockTrans)
52
52
  })
53
+
54
+ test('KnexDatabase - convert camel to snake', async () => {
55
+ const mockTrans = { a: 'b' } as any
56
+ const mockClient = jest.fn(
57
+ () =>
58
+ ({
59
+ transaction: async () => mockTrans,
60
+ }) as Knex
61
+ )
62
+ KnexDatabase['knexProvider'] = mockClient
63
+
64
+ const underTest = new KnexDatabase({ ...config, convertCamelToSnake: true })
65
+ expect(mockClient).toBeCalledWith({
66
+ ...expectedImplConfig,
67
+ postProcessResponse: expect.any(Function),
68
+ wrapIdentifier: expect.any(Function),
69
+ })
70
+
71
+ const trans = await underTest.transaction()
72
+
73
+ expect(trans).toBeInstanceOf(KnexTransactionImpl)
74
+ expect(trans['delegate']).toBe(mockTrans)
75
+ })
53
76
  })