@webda/postgres 1.6.0-beta.1 → 2.0.0-beta.0

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/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6CAA2B"}
@@ -1,4 +1,4 @@
1
- import { CoreModel, ModdaDefinition } from "@webda/core";
1
+ import { CoreModel } from "@webda/core";
2
2
  import { SQLResult, SQLStore, SQLStoreParameters } from "./sqlstore";
3
3
  import { Pool, Client, ClientConfig, PoolConfig } from "pg";
4
4
  declare class PostgresParameters extends SQLStoreParameters {
@@ -25,6 +25,7 @@ declare class PostgresParameters extends SQLStoreParameters {
25
25
  * );
26
26
  * ```
27
27
  *
28
+ * @WebdaModda
28
29
  */
29
30
  export default class PostgresStore<T extends CoreModel = CoreModel, K extends PostgresParameters = PostgresParameters> extends SQLStore<T, K> {
30
31
  client: Client | Pool;
@@ -48,6 +49,10 @@ export default class PostgresStore<T extends CoreModel = CoreModel, K extends Po
48
49
  * @returns
49
50
  */
50
51
  executeQuery(query: string): Promise<SQLResult<T>>;
52
+ /**
53
+ * @override
54
+ */
55
+ mapExpressionAttribute(attribute: string[]): string;
51
56
  /**
52
57
  * @override
53
58
  */
@@ -72,9 +77,5 @@ export default class PostgresStore<T extends CoreModel = CoreModel, K extends Po
72
77
  * @override
73
78
  */
74
79
  _deleteItemFromCollection(uuid: string, attribute: string, index: number, itemWriteCondition: any, itemWriteConditionField: string, updateDate: Date): Promise<any>;
75
- /**
76
- * @override
77
- */
78
- static getModda(): ModdaDefinition;
79
80
  }
80
81
  export {};
@@ -28,6 +28,7 @@ class PostgresParameters extends sqlstore_1.SQLStoreParameters {
28
28
  * );
29
29
  * ```
30
30
  *
31
+ * @WebdaModda
31
32
  */
32
33
  class PostgresStore extends sqlstore_1.SQLStore {
33
34
  /**
@@ -77,6 +78,12 @@ class PostgresStore extends sqlstore_1.SQLStore {
77
78
  };
78
79
  });
79
80
  }
81
+ /**
82
+ * @override
83
+ */
84
+ mapExpressionAttribute(attribute) {
85
+ return `data#>>'{${attribute.join(",")}}'`;
86
+ }
80
87
  /**
81
88
  * @override
82
89
  */
@@ -86,7 +93,7 @@ class PostgresStore extends sqlstore_1.SQLStore {
86
93
  if (itemWriteCondition) {
87
94
  query += this.getQueryCondition(itemWriteCondition, itemWriteConditionField);
88
95
  }
89
- let res = yield this.query(query);
96
+ let res = yield this.sqlQuery(query);
90
97
  if (res.rowCount === 0) {
91
98
  throw new core_1.UpdateConditionFailError(uid, itemWriteConditionField, itemWriteCondition);
92
99
  }
@@ -101,7 +108,7 @@ class PostgresStore extends sqlstore_1.SQLStore {
101
108
  if (itemWriteCondition) {
102
109
  query += this.getQueryCondition(itemWriteCondition, itemWriteConditionField);
103
110
  }
104
- let res = yield this.query(query);
111
+ let res = yield this.sqlQuery(query);
105
112
  if (res.rowCount === 0) {
106
113
  if (itemWriteCondition) {
107
114
  throw new core_1.UpdateConditionFailError(uuid, itemWriteConditionField, itemWriteCondition);
@@ -124,7 +131,7 @@ class PostgresStore extends sqlstore_1.SQLStore {
124
131
  _incrementAttribute(uid, attribute, value, updateDate) {
125
132
  return __awaiter(this, void 0, void 0, function* () {
126
133
  let query = `UPDATE ${this.parameters.table} SET data = jsonb_set(jsonb_set(data, '{${attribute}}', (COALESCE(data->>'${attribute}','0')::int + ${value})::text::jsonb)::jsonb, '{_lastUpdate}', '"${updateDate.toISOString()}"'::jsonb) WHERE uuid = '${this.getUuid(uid)}'`;
127
- let res = yield this.query(query);
134
+ let res = yield this.sqlQuery(query);
128
135
  if (res.rowCount === 0) {
129
136
  throw new core_1.StoreNotFoundError(uid, this.getName());
130
137
  }
@@ -146,7 +153,7 @@ class PostgresStore extends sqlstore_1.SQLStore {
146
153
  if (itemWriteCondition) {
147
154
  query += ` AND (data#>>'{${attribute}, ${index}}')::jsonb->>'${itemWriteConditionField}'='${itemWriteCondition}'`;
148
155
  }
149
- let res = yield this.query(query);
156
+ let res = yield this.sqlQuery(query);
150
157
  if (res.rowCount === 0) {
151
158
  if (itemWriteCondition) {
152
159
  throw new core_1.UpdateConditionFailError(uuid, itemWriteConditionField, itemWriteCondition);
@@ -168,7 +175,7 @@ class PostgresStore extends sqlstore_1.SQLStore {
168
175
  if (itemWriteCondition) {
169
176
  query += ` AND (data#>>'{${attribute}, ${index}}')::jsonb->>'${itemWriteConditionField}'='${itemWriteCondition}'`;
170
177
  }
171
- let res = yield this.query(query);
178
+ let res = yield this.sqlQuery(query);
172
179
  if (res.rowCount === 0) {
173
180
  if (itemWriteCondition) {
174
181
  throw new core_1.UpdateConditionFailError(uuid, itemWriteConditionField, itemWriteCondition);
@@ -179,16 +186,6 @@ class PostgresStore extends sqlstore_1.SQLStore {
179
186
  }
180
187
  });
181
188
  }
182
- /**
183
- * @override
184
- */
185
- static getModda() {
186
- return {
187
- uuid: "Webda/PostgresStore",
188
- label: "PostgresStore",
189
- description: "Implements PostgreSQL storage"
190
- };
191
- }
192
189
  }
193
190
  exports.default = PostgresStore;
194
191
  //# sourceMappingURL=postgresstore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgresstore.js","sourceRoot":"","sources":["../src/postgresstore.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAuG;AACvG,yCAAqE;AACrE,2BAA4D;AAE5D,MAAM,kBAAmB,SAAQ,6BAAkB;CASlD;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAqB,aAGnB,SAAQ,mBAAc;IAGtB;;OAEG;IACH,cAAc,CAAC,MAAW;QACxB,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACG,IAAI;;;;;YACR,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;gBAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,SAAI,CAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;aAC1D;iBAAM;gBACL,IAAI,CAAC,MAAM,GAAG,IAAI,WAAM,CAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;aAC5D;YACD,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,OAAM,IAAI,WAAE,CAAC;QACrB,CAAC;KAAA;IAED;;;OAGG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACG,YAAY,CAAC,KAAa;;YAC9B,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAClC,IAAI,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACzC,OAAO;gBACL,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC/C,QAAQ,EAAE,GAAG,CAAC,QAAQ;aAC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iBAAiB,uBAAuB,MAAM,kBAAkB,GAAG,CAAC;aACnH;YACD,IAAI,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,EAAE;gBACtB,IAAI,kBAAkB,EAAE;oBACtB,MAAM,IAAI,+BAAwB,CAAC,IAAI,EAAE,uBAAuB,EAAE,kBAAkB,CAAC,CAAC;iBACvF;qBAAM;oBACL,MAAM,IAAI,yBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;iBACpD;aACF;QACH,CAAC;KAAA;CACF;AAnLD,gCAmLC"}
package/lib/sqlstore.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CoreModel, Store, StoreParameters } from "@webda/core";
1
+ import { CoreModel, Store, StoreParameters, WebdaQL } from "@webda/core";
2
2
  export interface SQLDatabase {
3
3
  name: string;
4
4
  }
@@ -13,18 +13,28 @@ export interface SQLResult<T> {
13
13
  rows: T[];
14
14
  rowCount: number;
15
15
  }
16
+ export declare class SQLComparisonExpression extends WebdaQL.ComparisonExpression {
17
+ toStringValue(value: (string | number | boolean) | (string | number | boolean)[]): string;
18
+ toStringAttribute(): string;
19
+ }
16
20
  export declare abstract class SQLStore<T extends CoreModel, K extends SQLStoreParameters = SQLStoreParameters> extends Store<T, K> {
17
- query(q: string): Promise<SQLResult<T>>;
21
+ sqlQuery(q: string): Promise<SQLResult<T>>;
18
22
  abstract executeQuery(q: string): Promise<SQLResult<T>>;
19
23
  completeQuery(q: string): string;
20
24
  /**
21
25
  * @override
22
26
  */
23
27
  _delete(uid: string, writeCondition: any, writeConditionField: string): Promise<void>;
28
+ abstract mapExpressionAttribute(attribute: string[]): string;
29
+ duplicateExpression(expression: WebdaQL.Expression): WebdaQL.Expression;
24
30
  /**
25
31
  * @override
26
32
  */
27
- _find(request: any, offset?: any, limit?: any): Promise<T[]>;
33
+ find(query: WebdaQL.Query): Promise<{
34
+ results: T[];
35
+ continuationToken: string;
36
+ filter: WebdaQL.Expression;
37
+ }>;
28
38
  /**
29
39
  * @override
30
40
  */
package/lib/sqlstore.js CHANGED
@@ -9,13 +9,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SQLStore = exports.SQLStoreParameters = void 0;
12
+ exports.SQLStore = exports.SQLComparisonExpression = exports.SQLStoreParameters = void 0;
13
13
  const core_1 = require("@webda/core");
14
14
  class SQLStoreParameters extends core_1.StoreParameters {
15
15
  }
16
16
  exports.SQLStoreParameters = SQLStoreParameters;
17
+ class SQLComparisonExpression extends core_1.WebdaQL.ComparisonExpression {
18
+ toStringValue(value) {
19
+ if (typeof value === "string") {
20
+ return `'${value}'`;
21
+ }
22
+ return super.toStringValue(value);
23
+ }
24
+ toStringAttribute() {
25
+ if ([">", "<", "<=", ">="].includes(this.operator)) {
26
+ // coalesce(data#>>'{${this.attribute[0]}}', '0') ?
27
+ return `CAST(${this.attribute[0]} AS integer)`;
28
+ }
29
+ return this.attribute[0];
30
+ }
31
+ }
32
+ exports.SQLComparisonExpression = SQLComparisonExpression;
17
33
  class SQLStore extends core_1.Store {
18
- query(q) {
34
+ sqlQuery(q) {
19
35
  q = this.completeQuery(q);
20
36
  return this.executeQuery(q);
21
37
  }
@@ -38,24 +54,51 @@ class SQLStore extends core_1.Store {
38
54
  if (writeCondition) {
39
55
  query += this.getQueryCondition(writeCondition, writeConditionField);
40
56
  }
41
- let res = yield this.query(query);
57
+ let res = yield this.sqlQuery(query);
42
58
  if (res.rowCount === 0 && writeCondition) {
43
59
  throw new core_1.UpdateConditionFailError(uid, writeConditionField, writeCondition);
44
60
  }
45
61
  });
46
62
  }
63
+ duplicateExpression(expression) {
64
+ if (expression instanceof core_1.WebdaQL.AndExpression) {
65
+ return new core_1.WebdaQL.AndExpression(expression.children.map(exp => this.duplicateExpression(exp)));
66
+ }
67
+ else if (expression instanceof core_1.WebdaQL.OrExpression) {
68
+ return new core_1.WebdaQL.OrExpression(expression.children.map(exp => this.duplicateExpression(exp)));
69
+ }
70
+ else if (expression instanceof core_1.WebdaQL.ComparisonExpression) {
71
+ if (expression.operator === "IN") {
72
+ const attr = this.mapExpressionAttribute(expression.attribute);
73
+ return new core_1.WebdaQL.OrExpression(expression.value.map(v => new SQLComparisonExpression("=", attr, v)));
74
+ }
75
+ return new SQLComparisonExpression(expression.operator, this.mapExpressionAttribute(expression.attribute), expression.value);
76
+ }
77
+ }
47
78
  /**
48
79
  * @override
49
80
  */
50
- _find(request, offset, limit) {
81
+ find(query) {
51
82
  return __awaiter(this, void 0, void 0, function* () {
52
- request !== null && request !== void 0 ? request : (request = "TRUE");
53
- limit !== null && limit !== void 0 ? limit : (limit = 1000);
54
- if (typeof request !== "string") {
55
- throw new Error("Query should be a string");
83
+ // Update condition
84
+ let sql = this.duplicateExpression(query.filter).toString() || "TRUE";
85
+ let offset = 0;
86
+ offset = parseInt(query.continuationToken || "0", 10);
87
+ if (query.orderBy && query.orderBy.length) {
88
+ sql +=
89
+ " ORDER BY " +
90
+ query.orderBy.map(c => `${this.mapExpressionAttribute(c.field.split("."))} ${c.direction}`).join(", ");
91
+ }
92
+ sql += ` LIMIT ${query.limit || "1000"}`;
93
+ if (offset) {
94
+ sql += ` OFFSET ${offset}`;
56
95
  }
57
- request += ` LIMIT ${limit}`;
58
- return (yield this.query(request)).rows;
96
+ const results = (yield this.sqlQuery(sql)).rows.map(c => this.initModel(c));
97
+ return {
98
+ results,
99
+ continuationToken: query.limit <= results.length ? (offset + query.limit).toString() : undefined,
100
+ filter: new core_1.WebdaQL.AndExpression([])
101
+ };
59
102
  });
60
103
  }
61
104
  /**
@@ -63,7 +106,7 @@ class SQLStore extends core_1.Store {
63
106
  */
64
107
  exists(uid) {
65
108
  return __awaiter(this, void 0, void 0, function* () {
66
- let res = yield this.query(`SELECT uuid FROM ${this.parameters.table} WHERE ${this.getModel().getUuidField()} = '${this.getUuid(uid)}'`);
109
+ let res = yield this.sqlQuery(`SELECT uuid FROM ${this.parameters.table} WHERE ${this.getModel().getUuidField()} = '${this.getUuid(uid)}'`);
67
110
  return res.rowCount === 1;
68
111
  });
69
112
  }
@@ -72,7 +115,7 @@ class SQLStore extends core_1.Store {
72
115
  */
73
116
  _get(uid, raiseIfNotFound) {
74
117
  return __awaiter(this, void 0, void 0, function* () {
75
- let res = yield this.query(`${this.getModel().getUuidField()} = '${this.getUuid(uid)}'`);
118
+ let res = yield this.sqlQuery(`${this.getModel().getUuidField()} = '${this.getUuid(uid)}'`);
76
119
  if (res.rowCount === 0 && raiseIfNotFound) {
77
120
  throw new core_1.StoreNotFoundError(uid, this.getName());
78
121
  }
@@ -85,9 +128,9 @@ class SQLStore extends core_1.Store {
85
128
  getAll(list) {
86
129
  return __awaiter(this, void 0, void 0, function* () {
87
130
  if (list) {
88
- return (yield this.query(list.map(uuid => `uuid='${this.getUuid(uuid)}'`).join(" OR "))).rows;
131
+ return (yield this.sqlQuery(list.map(uuid => `uuid='${this.getUuid(uuid)}'`).join(" OR "))).rows;
89
132
  }
90
- return (yield this.query("TRUE")).rows;
133
+ return (yield this.sqlQuery("TRUE")).rows;
91
134
  });
92
135
  }
93
136
  /**
@@ -99,7 +142,7 @@ class SQLStore extends core_1.Store {
99
142
  if (itemWriteCondition) {
100
143
  q += this.getQueryCondition(itemWriteCondition, itemWriteConditionField);
101
144
  }
102
- let res = yield this.query(q);
145
+ let res = yield this.sqlQuery(q);
103
146
  if (res.rowCount === 0) {
104
147
  throw new core_1.UpdateConditionFailError(uid, itemWriteConditionField, itemWriteCondition);
105
148
  }
@@ -121,13 +164,13 @@ class SQLStore extends core_1.Store {
121
164
  */
122
165
  _save(object) {
123
166
  return __awaiter(this, void 0, void 0, function* () {
124
- yield this.query(`INSERT INTO ${this.parameters.table}(uuid,data) VALUES('${this.getUuid(object)}', '${object.toStoredJSON(true)}')`);
167
+ yield this.sqlQuery(`INSERT INTO ${this.parameters.table}(uuid,data) VALUES('${this.getUuid(object)}', '${object.toStoredJSON(true)}')`);
125
168
  return object;
126
169
  });
127
170
  }
128
171
  __clean() {
129
172
  return __awaiter(this, void 0, void 0, function* () {
130
- yield this.query(`DELETE FROM ${this.parameters.table}`);
173
+ yield this.sqlQuery(`DELETE FROM ${this.parameters.table}`);
131
174
  });
132
175
  }
133
176
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sqlstore.js","sourceRoot":"","sources":["../src/sqlstore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAA8G;AAM9G,MAAa,kBAAmB,SAAQ,sBAAe;CAGtD;AAHD,gDAGC;AAWD,MAAsB,QAAiF,SAAQ,YAG9G;IACC,KAAK,CAAC,CAAS;QACb,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAID,aAAa,CAAC,CAAS;QACrB,qCAAqC;QACrC,sBAAsB;QACtB,0EAA0E;QAC1E,iDAAiD;QACjD,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC5G,OAAO,iBAAiB,IAAI,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC,EAAE,CAAC;SAC5D;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAED;;OAEG;IACG,OAAO,CAAC,GAAW,EAAE,cAAmB,EAAE,mBAA2B;;YACzE,IAAI,KAAK,GAAG,eAAe,IAAI,CAAC,UAAU,CAAC,KAAK,gBAAgB,GAAG,GAAG,CAAC;YACvE,IAAI,cAAc,EAAE;gBAClB,KAAK,IAAI,IAAI,CAAC,iBAAiB,CAAC,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;gBACtB,MAAM,IAAI,+BAAwB,CAAC,GAAG,EAAE,uBAAuB,EAAE,kBAAkB,CAAC,CAAC;aACtF;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAED,OAAO,CAAC,MAAkB;QACxB,IAAI,EAAU,CAAC;QACf,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,EAAE,GAAG,MAAM,CAAC;SACb;aAAM;YACL,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;SACvB;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD;;OAEG;IACG,KAAK,CAAC,MAAS;;YACnB,MAAM,IAAI,CAAC,QAAQ,CACjB,eAAe,IAAI,CAAC,UAAU,CAAC,KAAK,uBAAuB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,MAAM,CAAC,YAAY,CACvG,IAAI,CACL,IAAI,CACN,CAAC;YACF,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAEK,OAAO;;YACX,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;QAC9D,CAAC;KAAA;CACF;AAhKD,4BAgKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webda/postgres",
3
- "version": "1.6.0-beta.1",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "Implements Postgres on webda",
5
5
  "keywords": [
6
6
  "postgres",
@@ -11,14 +11,14 @@
11
11
  "main": "lib/index.js",
12
12
  "typings": "lib/index.d.ts",
13
13
  "scripts": {
14
- "build": "tsc",
14
+ "build": "webda build",
15
15
  "pretest": "npm run build",
16
16
  "lint": "prettier --check src/**/*",
17
17
  "lint:fix": "prettier --write src/**/*",
18
18
  "test": "nyc mocha --recursive --exit --timeout=100000 -r ../../node_modules/ts-node/register src/**/*.spec.ts src/*.spec.ts"
19
19
  },
20
20
  "dependencies": {
21
- "@webda/core": "^1.6.0-beta.1",
21
+ "@webda/core": "^2.0.0-beta.0",
22
22
  "pg": "^8.7.1"
23
23
  },
24
24
  "files": [
@@ -47,7 +47,8 @@
47
47
  "namespace": "Webda"
48
48
  },
49
49
  "devDependencies": {
50
- "@types/node": "14.0.0"
50
+ "@types/node": "14.0.0",
51
+ "@webda/shell": "^2.0.0-beta.0"
51
52
  },
52
- "gitHead": "348aa239847c88956fa756c798d700bd48fff1fe"
53
+ "gitHead": "5a559bca55832e9a6526794117e2f78188eba3d0"
53
54
  }
package/test/config.json CHANGED
@@ -6,8 +6,10 @@
6
6
  "host": "localhost",
7
7
  "user": "webda.io",
8
8
  "database": "webda.io",
9
- "password": "webda.io"
9
+ "password": "webda.io",
10
+ "statement_timeout": 60000
10
11
  },
12
+ "usePool": true,
11
13
  "sessionSecret": "Lp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5EN"
12
14
  },
13
15
  "services": {
package/webda.module.json CHANGED
@@ -1,8 +1,863 @@
1
1
  {
2
- "services": {
3
- "Webda/PostgresStore": "lib/postgresstore.js"
2
+ "moddas": {
3
+ "webda/postgresstore": "lib/postgresstore:default"
4
4
  },
5
+ "beans": {},
5
6
  "models": {},
6
7
  "deployers": {},
7
- "schemas": {}
8
+ "schemas": {
9
+ "webda/postgresstore": {
10
+ "type": "object",
11
+ "properties": {
12
+ "type": {
13
+ "type": "string",
14
+ "description": "Type of the service"
15
+ },
16
+ "model": {
17
+ "type": "string",
18
+ "description": "Webda model to use within the Store",
19
+ "default": "Webda/CoreModel"
20
+ },
21
+ "asyncDelete": {
22
+ "type": "boolean",
23
+ "description": "async delete"
24
+ },
25
+ "expose": {
26
+ "$ref": "#/definitions/ExposeParameters",
27
+ "description": "Expose the service to an urls"
28
+ },
29
+ "strict": {
30
+ "type": "boolean",
31
+ "description": "Allow to load object that does not have the type data",
32
+ "default": true
33
+ },
34
+ "slowQueryThreshold": {
35
+ "type": "number",
36
+ "description": "Slow query threshold",
37
+ "default": 30000
38
+ },
39
+ "table": {
40
+ "type": "string"
41
+ },
42
+ "database": {
43
+ "$ref": "#/definitions/SQLDatabase"
44
+ },
45
+ "usePool": {
46
+ "type": "boolean",
47
+ "default": false
48
+ },
49
+ "postgresqlServer": {
50
+ "anyOf": [
51
+ {
52
+ "$ref": "#/definitions/ClientConfig"
53
+ },
54
+ {
55
+ "$ref": "#/definitions/PoolConfig"
56
+ }
57
+ ],
58
+ "description": "By default use environment variables"
59
+ }
60
+ },
61
+ "required": [
62
+ "asyncDelete",
63
+ "database",
64
+ "slowQueryThreshold",
65
+ "table",
66
+ "type"
67
+ ],
68
+ "$schema": "http://json-schema.org/draft-07/schema#",
69
+ "definitions": {
70
+ "ExposeParameters": {
71
+ "type": "object",
72
+ "properties": {
73
+ "url": {
74
+ "type": "string",
75
+ "description": "URL endpoint to use to expose REST Resources API",
76
+ "default": "service.getName().toLowerCase()"
77
+ },
78
+ "restrict": {
79
+ "type": "object",
80
+ "properties": {
81
+ "create": {
82
+ "type": "boolean",
83
+ "description": "Do not expose the POST"
84
+ },
85
+ "update": {
86
+ "type": "boolean",
87
+ "description": "Do not expose the PUT and PATCH"
88
+ },
89
+ "get": {
90
+ "type": "boolean",
91
+ "description": "Do not expose the GET"
92
+ },
93
+ "delete": {
94
+ "type": "boolean",
95
+ "description": "Do not expose the DELETE"
96
+ },
97
+ "query": {
98
+ "type": "boolean",
99
+ "description": "Do not expose the query endpoint"
100
+ }
101
+ },
102
+ "description": "You can restrict any part of the CRUD",
103
+ "default": {}
104
+ },
105
+ "queryMethod": {
106
+ "type": "string",
107
+ "enum": [
108
+ "PUT",
109
+ "GET"
110
+ ],
111
+ "description": "For confidentiality sometimes you might prefer to expose query through PUT To avoid GET logging"
112
+ }
113
+ },
114
+ "required": [
115
+ "queryMethod"
116
+ ]
117
+ },
118
+ "SQLDatabase": {
119
+ "type": "object",
120
+ "properties": {
121
+ "name": {
122
+ "type": "string"
123
+ }
124
+ },
125
+ "required": [
126
+ "name"
127
+ ]
128
+ },
129
+ "ClientConfig": {
130
+ "type": "object",
131
+ "properties": {
132
+ "user": {
133
+ "type": "string"
134
+ },
135
+ "database": {
136
+ "type": "string"
137
+ },
138
+ "password": {
139
+ "anyOf": [
140
+ {
141
+ "type": "string"
142
+ },
143
+ {}
144
+ ]
145
+ },
146
+ "port": {
147
+ "type": "number"
148
+ },
149
+ "host": {
150
+ "type": "string"
151
+ },
152
+ "connectionString": {
153
+ "type": "string"
154
+ },
155
+ "keepAlive": {
156
+ "type": "boolean"
157
+ },
158
+ "stream": {
159
+ "$ref": "#/definitions/internal.Duplex"
160
+ },
161
+ "statement_timeout": {
162
+ "anyOf": [
163
+ {
164
+ "type": "boolean",
165
+ "const": false
166
+ },
167
+ {
168
+ "type": "number"
169
+ }
170
+ ]
171
+ },
172
+ "parseInputDatesAsUTC": {
173
+ "type": "boolean"
174
+ },
175
+ "ssl": {
176
+ "anyOf": [
177
+ {
178
+ "type": "boolean"
179
+ },
180
+ {
181
+ "$ref": "#/definitions/ConnectionOptions"
182
+ }
183
+ ]
184
+ },
185
+ "query_timeout": {
186
+ "type": "number"
187
+ },
188
+ "keepAliveInitialDelayMillis": {
189
+ "type": "number"
190
+ },
191
+ "idle_in_transaction_session_timeout": {
192
+ "type": "number"
193
+ },
194
+ "application_name": {
195
+ "type": "string"
196
+ },
197
+ "connectionTimeoutMillis": {
198
+ "type": "number"
199
+ },
200
+ "types": {
201
+ "$ref": "#/definitions/CustomTypesConfig"
202
+ },
203
+ "options": {
204
+ "type": "string"
205
+ }
206
+ }
207
+ },
208
+ "internal.Duplex": {
209
+ "type": "object",
210
+ "properties": {
211
+ "writable": {
212
+ "type": "boolean"
213
+ },
214
+ "writableEnded": {
215
+ "type": "boolean"
216
+ },
217
+ "writableFinished": {
218
+ "type": "boolean"
219
+ },
220
+ "writableHighWaterMark": {
221
+ "type": "number"
222
+ },
223
+ "writableLength": {
224
+ "type": "number"
225
+ },
226
+ "writableObjectMode": {
227
+ "type": "boolean"
228
+ },
229
+ "writableCorked": {
230
+ "type": "number"
231
+ },
232
+ "destroyed": {
233
+ "type": "boolean"
234
+ },
235
+ "readable": {
236
+ "type": "boolean"
237
+ },
238
+ "readableHighWaterMark": {
239
+ "type": "number"
240
+ },
241
+ "readableLength": {
242
+ "type": "number"
243
+ },
244
+ "readableObjectMode": {
245
+ "type": "boolean"
246
+ }
247
+ },
248
+ "required": [
249
+ "destroyed",
250
+ "readable",
251
+ "readableHighWaterMark",
252
+ "readableLength",
253
+ "readableObjectMode",
254
+ "writable",
255
+ "writableCorked",
256
+ "writableEnded",
257
+ "writableFinished",
258
+ "writableHighWaterMark",
259
+ "writableLength",
260
+ "writableObjectMode"
261
+ ]
262
+ },
263
+ "ConnectionOptions": {
264
+ "type": "object",
265
+ "properties": {
266
+ "secureContext": {
267
+ "$ref": "#/definitions/SecureContext",
268
+ "description": "An optional TLS context object from tls.createSecureContext()"
269
+ },
270
+ "enableTrace": {
271
+ "type": "boolean",
272
+ "description": "When enabled, TLS packet trace information is written to `stderr`. This can be used to debug TLS connection problems.",
273
+ "default": false
274
+ },
275
+ "requestCert": {
276
+ "type": "boolean",
277
+ "description": "If true the server will request a certificate from clients that connect and attempt to verify that certificate. Defaults to false."
278
+ },
279
+ "ALPNProtocols": {
280
+ "anyOf": [
281
+ {
282
+ "type": "array",
283
+ "items": {
284
+ "type": "string"
285
+ }
286
+ },
287
+ {
288
+ "type": "array",
289
+ "items": {
290
+ "$ref": "#/definitions/Uint8Array"
291
+ }
292
+ },
293
+ {
294
+ "$ref": "#/definitions/Uint8Array"
295
+ }
296
+ ],
297
+ "description": "An array of strings or a Buffer naming possible ALPN protocols. (Protocols should be ordered by their priority.)"
298
+ },
299
+ "SNICallback": {
300
+ "description": "SNICallback(servername, cb) <Function> A function that will be called if the client supports SNI TLS extension. Two arguments will be passed when called: servername and cb. SNICallback should invoke cb(null, ctx), where ctx is a SecureContext instance. (tls.createSecureContext(...) can be used to get a proper SecureContext.) If SNICallback wasn't provided the default callback with high-level API will be used (see below)."
301
+ },
302
+ "rejectUnauthorized": {
303
+ "type": "boolean",
304
+ "description": "If true the server will reject any connection which is not authorized with the list of supplied CAs. This option only has an effect if requestCert is true.",
305
+ "default": true
306
+ },
307
+ "ca": {
308
+ "anyOf": [
309
+ {
310
+ "type": "string"
311
+ },
312
+ {
313
+ "$ref": "#/definitions/Buffer"
314
+ },
315
+ {
316
+ "type": "array",
317
+ "items": {
318
+ "anyOf": [
319
+ {
320
+ "type": "string"
321
+ },
322
+ {
323
+ "$ref": "#/definitions/Buffer"
324
+ }
325
+ ]
326
+ }
327
+ }
328
+ ],
329
+ "description": "Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified using this option."
330
+ },
331
+ "cert": {
332
+ "anyOf": [
333
+ {
334
+ "type": "string"
335
+ },
336
+ {
337
+ "$ref": "#/definitions/Buffer"
338
+ },
339
+ {
340
+ "type": "array",
341
+ "items": {
342
+ "anyOf": [
343
+ {
344
+ "type": "string"
345
+ },
346
+ {
347
+ "$ref": "#/definitions/Buffer"
348
+ }
349
+ ]
350
+ }
351
+ }
352
+ ],
353
+ "description": "Cert chains in PEM format. One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private key, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see ca). When providing multiple cert chains, they do not have to be in the same order as their private keys in key. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail."
354
+ },
355
+ "sigalgs": {
356
+ "type": "string",
357
+ "description": "Colon-separated list of supported signature algorithms. The list can contain digest algorithms (SHA256, MD5 etc.), public key algorithms (RSA-PSS, ECDSA etc.), combination of both (e.g 'RSA+SHA384') or TLS v1.3 scheme names (e.g. rsa_pss_pss_sha512)."
358
+ },
359
+ "ciphers": {
360
+ "type": "string",
361
+ "description": "Cipher suite specification, replacing the default. For more information, see modifying the default cipher suite. Permitted ciphers can be obtained via tls.getCiphers(). Cipher names must be uppercased in order for OpenSSL to accept them."
362
+ },
363
+ "clientCertEngine": {
364
+ "type": "string",
365
+ "description": "Name of an OpenSSL engine which can provide the client certificate."
366
+ },
367
+ "crl": {
368
+ "anyOf": [
369
+ {
370
+ "type": "string"
371
+ },
372
+ {
373
+ "$ref": "#/definitions/Buffer"
374
+ },
375
+ {
376
+ "type": "array",
377
+ "items": {
378
+ "anyOf": [
379
+ {
380
+ "type": "string"
381
+ },
382
+ {
383
+ "$ref": "#/definitions/Buffer"
384
+ }
385
+ ]
386
+ }
387
+ }
388
+ ],
389
+ "description": "PEM formatted CRLs (Certificate Revocation Lists)."
390
+ },
391
+ "dhparam": {
392
+ "anyOf": [
393
+ {
394
+ "type": "string"
395
+ },
396
+ {
397
+ "$ref": "#/definitions/Buffer"
398
+ }
399
+ ],
400
+ "description": "Diffie Hellman parameters, required for Perfect Forward Secrecy. Use openssl dhparam to create the parameters. The key length must be greater than or equal to 1024 bits or else an error will be thrown. Although 1024 bits is permissible, use 2048 bits or larger for stronger security. If omitted or invalid, the parameters are silently discarded and DHE ciphers will not be available."
401
+ },
402
+ "ecdhCurve": {
403
+ "type": "string",
404
+ "description": "A string describing a named curve or a colon separated list of curve NIDs or names, for example P-521:P-384:P-256, to use for ECDH key agreement. Set to auto to select the curve automatically. Use crypto.getCurves() to obtain a list of available curve names. On recent releases, openssl ecparam -list_curves will also display the name and description of each available elliptic curve. Default: tls.DEFAULT_ECDH_CURVE."
405
+ },
406
+ "honorCipherOrder": {
407
+ "type": "boolean",
408
+ "description": "Attempt to use the server's cipher suite preferences instead of the client's. When true, causes SSL_OP_CIPHER_SERVER_PREFERENCE to be set in secureOptions"
409
+ },
410
+ "key": {
411
+ "anyOf": [
412
+ {
413
+ "type": "string"
414
+ },
415
+ {
416
+ "$ref": "#/definitions/Buffer"
417
+ },
418
+ {
419
+ "type": "array",
420
+ "items": {
421
+ "anyOf": [
422
+ {
423
+ "$ref": "#/definitions/Buffer"
424
+ },
425
+ {
426
+ "$ref": "#/definitions/KeyObject"
427
+ }
428
+ ]
429
+ }
430
+ }
431
+ ],
432
+ "description": "Private keys in PEM format. PEM allows the option of private keys being encrypted. Encrypted keys will be decrypted with options.passphrase. Multiple keys using different algorithms can be provided either as an array of unencrypted key strings or buffers, or an array of objects in the form {pem: <string|buffer>[, passphrase: <string>]}. The object form can only occur in an array. object.passphrase is optional. Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not."
433
+ },
434
+ "privateKeyEngine": {
435
+ "type": "string",
436
+ "description": "Name of an OpenSSL engine to get private key from. Should be used together with privateKeyIdentifier."
437
+ },
438
+ "privateKeyIdentifier": {
439
+ "type": "string",
440
+ "description": "Identifier of a private key managed by an OpenSSL engine. Should be used together with privateKeyEngine. Should not be set together with key, because both options define a private key in different ways."
441
+ },
442
+ "maxVersion": {
443
+ "$ref": "#/definitions/SecureVersion",
444
+ "description": "Optionally set the maximum TLS version to allow. One of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the `secureProtocol` option, use one or the other.\n**Default:** `'TLSv1.3'`, unless changed using CLI options. Using `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used."
445
+ },
446
+ "minVersion": {
447
+ "$ref": "#/definitions/SecureVersion",
448
+ "description": "Optionally set the minimum TLS version to allow. One of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the `secureProtocol` option, use one or the other. It is not recommended to use less than TLSv1.2, but it may be required for interoperability.\n**Default:** `'TLSv1.2'`, unless changed using CLI options. Using `--tls-v1.0` sets the default to `'TLSv1'`. Using `--tls-v1.1` sets the default to `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to 'TLSv1.3'. If multiple of the options are provided, the lowest minimum is used."
449
+ },
450
+ "passphrase": {
451
+ "type": "string",
452
+ "description": "Shared passphrase used for a single private key and/or a PFX."
453
+ },
454
+ "pfx": {
455
+ "anyOf": [
456
+ {
457
+ "type": "string"
458
+ },
459
+ {
460
+ "$ref": "#/definitions/Buffer"
461
+ },
462
+ {
463
+ "type": "array",
464
+ "items": {
465
+ "anyOf": [
466
+ {
467
+ "type": "string"
468
+ },
469
+ {
470
+ "$ref": "#/definitions/Buffer"
471
+ },
472
+ {
473
+ "$ref": "#/definitions/PxfObject"
474
+ }
475
+ ]
476
+ }
477
+ }
478
+ ],
479
+ "description": "PFX or PKCS12 encoded private key and certificate chain. pfx is an alternative to providing key and cert individually. PFX is usually encrypted, if it is, passphrase will be used to decrypt it. Multiple PFX can be provided either as an array of unencrypted PFX buffers, or an array of objects in the form {buf: <string|buffer>[, passphrase: <string>]}. The object form can only occur in an array. object.passphrase is optional. Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not."
480
+ },
481
+ "secureOptions": {
482
+ "type": "number",
483
+ "description": "Optionally affect the OpenSSL protocol behavior, which is not usually necessary. This should be used carefully if at all! Value is a numeric bitmask of the SSL_OP_* options from OpenSSL Options"
484
+ },
485
+ "secureProtocol": {
486
+ "type": "string",
487
+ "description": "Legacy mechanism to select the TLS protocol version to use, it does not support independent control of the minimum and maximum version, and does not support limiting the protocol to TLSv1.3. Use minVersion and maxVersion instead. The possible values are listed as SSL_METHODS, use the function names as strings. For example, use 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow any TLS protocol version up to TLSv1.3. It is not recommended to use TLS versions less than 1.2, but it may be required for interoperability. Default: none, see minVersion."
488
+ },
489
+ "sessionIdContext": {
490
+ "type": "string",
491
+ "description": "Opaque identifier used by servers to ensure session state is not shared between applications. Unused by clients."
492
+ },
493
+ "host": {
494
+ "type": "string"
495
+ },
496
+ "port": {
497
+ "type": "number"
498
+ },
499
+ "path": {
500
+ "type": "string"
501
+ },
502
+ "socket": {
503
+ "$ref": "#/definitions/Socket"
504
+ },
505
+ "servername": {
506
+ "type": "string"
507
+ },
508
+ "session": {
509
+ "$ref": "#/definitions/Buffer"
510
+ },
511
+ "minDHSize": {
512
+ "type": "number"
513
+ },
514
+ "lookup": {
515
+ "$ref": "#/definitions/LookupFunction"
516
+ },
517
+ "timeout": {
518
+ "type": "number"
519
+ }
520
+ }
521
+ },
522
+ "SecureContext": {
523
+ "type": "object",
524
+ "properties": {
525
+ "context": {}
526
+ },
527
+ "required": [
528
+ "context"
529
+ ]
530
+ },
531
+ "Uint8Array": {
532
+ "type": "object",
533
+ "properties": {
534
+ "BYTES_PER_ELEMENT": {
535
+ "type": "number"
536
+ },
537
+ "buffer": {
538
+ "$ref": "#/definitions/ArrayBufferLike"
539
+ },
540
+ "byteLength": {
541
+ "type": "number"
542
+ },
543
+ "byteOffset": {
544
+ "type": "number"
545
+ },
546
+ "length": {
547
+ "type": "number"
548
+ }
549
+ },
550
+ "required": [
551
+ "BYTES_PER_ELEMENT",
552
+ "buffer",
553
+ "byteLength",
554
+ "byteOffset",
555
+ "length"
556
+ ],
557
+ "additionalProperties": {
558
+ "type": "number"
559
+ }
560
+ },
561
+ "ArrayBufferLike": {
562
+ "anyOf": [
563
+ {
564
+ "$ref": "#/definitions/ArrayBuffer"
565
+ },
566
+ {}
567
+ ]
568
+ },
569
+ "ArrayBuffer": {
570
+ "type": "object",
571
+ "properties": {
572
+ "byteLength": {
573
+ "type": "number"
574
+ }
575
+ },
576
+ "required": [
577
+ "byteLength"
578
+ ]
579
+ },
580
+ "Buffer": {
581
+ "type": "object",
582
+ "properties": {
583
+ "BYTES_PER_ELEMENT": {
584
+ "type": "number"
585
+ },
586
+ "buffer": {
587
+ "$ref": "#/definitions/ArrayBufferLike"
588
+ },
589
+ "byteLength": {
590
+ "type": "number"
591
+ },
592
+ "byteOffset": {
593
+ "type": "number"
594
+ },
595
+ "length": {
596
+ "type": "number"
597
+ }
598
+ },
599
+ "required": [
600
+ "BYTES_PER_ELEMENT",
601
+ "buffer",
602
+ "byteLength",
603
+ "byteOffset",
604
+ "length"
605
+ ],
606
+ "description": "Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'"
607
+ },
608
+ "KeyObject": {
609
+ "type": "object",
610
+ "properties": {
611
+ "pem": {
612
+ "anyOf": [
613
+ {
614
+ "type": "string"
615
+ },
616
+ {
617
+ "$ref": "#/definitions/Buffer"
618
+ }
619
+ ],
620
+ "description": "Private keys in PEM format."
621
+ },
622
+ "passphrase": {
623
+ "type": "string",
624
+ "description": "Optional passphrase."
625
+ }
626
+ },
627
+ "required": [
628
+ "pem"
629
+ ]
630
+ },
631
+ "SecureVersion": {
632
+ "type": "string",
633
+ "enum": [
634
+ "TLSv1.3",
635
+ "TLSv1.2",
636
+ "TLSv1.1",
637
+ "TLSv1"
638
+ ]
639
+ },
640
+ "PxfObject": {
641
+ "type": "object",
642
+ "properties": {
643
+ "buf": {
644
+ "anyOf": [
645
+ {
646
+ "type": "string"
647
+ },
648
+ {
649
+ "$ref": "#/definitions/Buffer"
650
+ }
651
+ ],
652
+ "description": "PFX or PKCS12 encoded private key and certificate chain."
653
+ },
654
+ "passphrase": {
655
+ "type": "string",
656
+ "description": "Optional passphrase."
657
+ }
658
+ },
659
+ "required": [
660
+ "buf"
661
+ ]
662
+ },
663
+ "Socket": {
664
+ "type": "object",
665
+ "properties": {
666
+ "writable": {
667
+ "type": "boolean"
668
+ },
669
+ "writableEnded": {
670
+ "type": "boolean"
671
+ },
672
+ "writableFinished": {
673
+ "type": "boolean"
674
+ },
675
+ "writableHighWaterMark": {
676
+ "type": "number"
677
+ },
678
+ "writableLength": {
679
+ "type": "number"
680
+ },
681
+ "writableObjectMode": {
682
+ "type": "boolean"
683
+ },
684
+ "writableCorked": {
685
+ "type": "number"
686
+ },
687
+ "destroyed": {
688
+ "type": "boolean"
689
+ },
690
+ "readable": {
691
+ "type": "boolean"
692
+ },
693
+ "readableHighWaterMark": {
694
+ "type": "number"
695
+ },
696
+ "readableLength": {
697
+ "type": "number"
698
+ },
699
+ "readableObjectMode": {
700
+ "type": "boolean"
701
+ },
702
+ "bufferSize": {
703
+ "type": "number"
704
+ },
705
+ "bytesRead": {
706
+ "type": "number"
707
+ },
708
+ "bytesWritten": {
709
+ "type": "number"
710
+ },
711
+ "connecting": {
712
+ "type": "boolean"
713
+ },
714
+ "localAddress": {
715
+ "type": "string"
716
+ },
717
+ "localPort": {
718
+ "type": "number"
719
+ },
720
+ "remoteAddress": {
721
+ "type": "string"
722
+ },
723
+ "remoteFamily": {
724
+ "type": "string"
725
+ },
726
+ "remotePort": {
727
+ "type": "number"
728
+ }
729
+ },
730
+ "required": [
731
+ "bufferSize",
732
+ "bytesRead",
733
+ "bytesWritten",
734
+ "connecting",
735
+ "destroyed",
736
+ "localAddress",
737
+ "localPort",
738
+ "readable",
739
+ "readableHighWaterMark",
740
+ "readableLength",
741
+ "readableObjectMode",
742
+ "writable",
743
+ "writableCorked",
744
+ "writableEnded",
745
+ "writableFinished",
746
+ "writableHighWaterMark",
747
+ "writableLength",
748
+ "writableObjectMode"
749
+ ]
750
+ },
751
+ "LookupFunction": {},
752
+ "CustomTypesConfig": {
753
+ "type": "object",
754
+ "properties": {
755
+ "getTypeParser": {}
756
+ },
757
+ "required": [
758
+ "getTypeParser"
759
+ ]
760
+ },
761
+ "PoolConfig": {
762
+ "type": "object",
763
+ "properties": {
764
+ "user": {
765
+ "type": "string"
766
+ },
767
+ "database": {
768
+ "type": "string"
769
+ },
770
+ "password": {
771
+ "anyOf": [
772
+ {
773
+ "type": "string"
774
+ },
775
+ {}
776
+ ]
777
+ },
778
+ "port": {
779
+ "type": "number"
780
+ },
781
+ "host": {
782
+ "type": "string"
783
+ },
784
+ "connectionString": {
785
+ "type": "string"
786
+ },
787
+ "keepAlive": {
788
+ "type": "boolean"
789
+ },
790
+ "stream": {
791
+ "$ref": "#/definitions/internal.Duplex"
792
+ },
793
+ "statement_timeout": {
794
+ "anyOf": [
795
+ {
796
+ "type": "boolean",
797
+ "const": false
798
+ },
799
+ {
800
+ "type": "number"
801
+ }
802
+ ]
803
+ },
804
+ "parseInputDatesAsUTC": {
805
+ "type": "boolean"
806
+ },
807
+ "ssl": {
808
+ "anyOf": [
809
+ {
810
+ "type": "boolean"
811
+ },
812
+ {
813
+ "$ref": "#/definitions/ConnectionOptions"
814
+ }
815
+ ]
816
+ },
817
+ "query_timeout": {
818
+ "type": "number"
819
+ },
820
+ "keepAliveInitialDelayMillis": {
821
+ "type": "number"
822
+ },
823
+ "idle_in_transaction_session_timeout": {
824
+ "type": "number"
825
+ },
826
+ "application_name": {
827
+ "type": "string"
828
+ },
829
+ "connectionTimeoutMillis": {
830
+ "type": "number"
831
+ },
832
+ "types": {
833
+ "$ref": "#/definitions/CustomTypesConfig"
834
+ },
835
+ "options": {
836
+ "type": "string"
837
+ },
838
+ "max": {
839
+ "type": "number"
840
+ },
841
+ "min": {
842
+ "type": "number"
843
+ },
844
+ "idleTimeoutMillis": {
845
+ "type": "number"
846
+ },
847
+ "log": {},
848
+ "Promise": {
849
+ "not": {}
850
+ },
851
+ "allowExitOnIdle": {
852
+ "type": "boolean"
853
+ },
854
+ "maxUses": {
855
+ "type": "number"
856
+ }
857
+ }
858
+ }
859
+ },
860
+ "title": "PostgresStore"
861
+ }
862
+ }
8
863
  }