ismx-nexo-node-app 0.3.36 → 0.3.38

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/js/index.js CHANGED
@@ -54,19 +54,33 @@ exports.BusinessState = BusinessState_1.default;
54
54
  const BusinessProxy_1 = __importDefault(require("./business/BusinessProxy"));
55
55
  exports.BusinessProxy = BusinessProxy_1.default;
56
56
  const BusinessServer_1 = __importDefault(require("./business/BusinessServer"));
57
- exports.BusinessServer = BusinessServer_1.default;
57
+ class BusinessServer extends BusinessServer_1.default {
58
+ }
59
+ exports.BusinessServer = BusinessServer;
58
60
  const BusinessThread_1 = __importDefault(require("./business/BusinessThread"));
59
- exports.BusinessThread = BusinessThread_1.default;
61
+ class BusinessThread extends BusinessThread_1.default {
62
+ }
63
+ exports.BusinessThread = BusinessThread;
60
64
  const BusinessErrors_1 = __importDefault(require("./business/BusinessErrors"));
61
- exports.BusinessErrors = BusinessErrors_1.default;
65
+ class BusinessErrors extends BusinessErrors_1.default {
66
+ }
67
+ exports.BusinessErrors = BusinessErrors;
62
68
  const BusinessLogger_1 = __importDefault(require("./business/BusinessLogger"));
63
- exports.BusinessLogger = BusinessLogger_1.default;
69
+ class BusinessLogger extends BusinessLogger_1.default {
70
+ }
71
+ exports.BusinessLogger = BusinessLogger;
64
72
  const CryptoUtils_1 = __importDefault(require("./business/utils/CryptoUtils"));
65
- exports.CryptoUtils = CryptoUtils_1.default;
73
+ class CryptoUtils extends CryptoUtils_1.default {
74
+ }
75
+ exports.CryptoUtils = CryptoUtils;
66
76
  const NumberUtils_1 = __importDefault(require("./business/utils/NumberUtils"));
67
- exports.NumberUtils = NumberUtils_1.default;
77
+ class NumberUtils extends NumberUtils_1.default {
78
+ }
79
+ exports.NumberUtils = NumberUtils;
68
80
  const StringUtils_1 = __importDefault(require("./business/utils/StringUtils"));
69
- exports.StringUtils = StringUtils_1.default;
81
+ class StringUtils extends StringUtils_1.default {
82
+ }
83
+ exports.StringUtils = StringUtils;
70
84
  /**************************************************************/
71
85
  const Repository_1 = __importDefault(require("./repository/Repository"));
72
86
  exports.Repository = Repository_1.default;
@@ -79,4 +93,6 @@ class RepositoryDatabasePostgres extends RepositoryDatabasePostgres_1.default {
79
93
  }
80
94
  exports.RepositoryDatabasePostgres = RepositoryDatabasePostgres;
81
95
  const QueryUtils_1 = __importDefault(require("./repository/utils/QueryUtils"));
82
- exports.QueryUtils = QueryUtils_1.default;
96
+ class QueryUtils extends QueryUtils_1.default {
97
+ }
98
+ exports.QueryUtils = QueryUtils;
@@ -20,14 +20,12 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
20
20
  super();
21
21
  this.introspectIntervalTime = 60 * 60 * 1000;
22
22
  this.tables = {};
23
- this.schema = "public";
24
23
  this.onIntrospectedListeners = [];
25
24
  this.native = this.native.bind(this);
26
25
  this.introspect = this.introspect.bind(this);
27
26
  }
28
27
  init(chain) {
29
28
  super.init(chain);
30
- this.schema = chain.schema || "public";
31
29
  this.connect(chain);
32
30
  }
33
31
  addOnIntrospectedListener(listener) {
@@ -64,33 +62,21 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
64
62
  return this.any(tableName, { id });
65
63
  });
66
64
  }
67
- any(tableName, filters) {
68
- return __awaiter(this, void 0, void 0, function* () {
65
+ any(tableName_1) {
66
+ return __awaiter(this, arguments, void 0, function* (tableName, filters = {}) {
69
67
  return yield this.find(tableName, filters).then((rows) => rows[0]);
70
68
  });
71
69
  }
72
- find(tableName, filters) {
73
- return __awaiter(this, void 0, void 0, function* () {
70
+ find(tableName_1) {
71
+ return __awaiter(this, arguments, void 0, function* (tableName, filters = {}) {
74
72
  if (!this.tables[tableName])
75
73
  throw new Error(`table ${tableName} does not exist`);
74
+ let schema = this.tables[tableName][0].schema;
76
75
  let { where, values } = this.toWhere(tableName, filters);
77
- let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${where}`;
76
+ let query = `SELECT * FROM ${schema}.${tableName} WHERE ${where}`;
78
77
  return this.query(query, values);
79
78
  });
80
79
  }
81
- all_depr(tableName_1) {
82
- return __awaiter(this, arguments, void 0, function* (tableName, options = {}) {
83
- var _a, _b;
84
- if (!this.tables[tableName])
85
- throw new Error(`table ${tableName} does not exist`);
86
- let table = this.tables[tableName];
87
- let schema = (_a = options.schema) !== null && _a !== void 0 ? _a : this.schema;
88
- return this.query(`
89
- SELECT * FROM ${schema}.${tableName}
90
- WHERE ${(_b = options.filters) !== null && _b !== void 0 ? _b : "TRUE"}
91
- `);
92
- });
93
- }
94
80
  add(tableName, object, id) {
95
81
  return __awaiter(this, void 0, void 0, function* () {
96
82
  return this.addAll(tableName, [Object.assign({ id: id }, object)]).then((rows) => rows[0]);
@@ -101,8 +87,9 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
101
87
  if (!this.tables[tableName])
102
88
  throw new Error(`table ${tableName} does not exist`);
103
89
  let table = this.tables[tableName];
90
+ let schema = table[0].schema;
104
91
  let columns = PostgresUtils_1.default.columns(table);
105
- let query = `INSERT INTO ${this.schema}.${tableName} (${columns.join(",")}) VALUES `;
92
+ let query = `INSERT INTO ${schema}.${tableName} (${columns.join(",")}) VALUES `;
106
93
  let values = [];
107
94
  let index = 1;
108
95
  for (let object of objects) {
@@ -123,43 +110,47 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
123
110
  if (!this.tables[tableName])
124
111
  throw new Error(`table ${tableName} does not exist`);
125
112
  let table = this.tables[tableName];
113
+ let schema = table[0].schema;
126
114
  let columns = PostgresUtils_1.default.columns(table);
127
115
  let params = columns.map((column, index) => `\$${index + 2}`).join(",");
128
116
  let values = [id, ...columns.map((column) => object[PostgresUtils_1.default.stringToCamel(column)])];
129
- let query = `UPDATE ${this.schema}.${tableName} SET (${columns.join(",")}) = (${params}) WHERE id = $1 `;
117
+ let query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = (${params}) WHERE id = $1 `;
130
118
  query += `RETURNING *`;
131
119
  return this.query(query, values).then((result) => result[0]);
132
120
  });
133
121
  }
134
122
  page(tableName_1, sortKey_1) {
135
- return __awaiter(this, arguments, void 0, function* (tableName, sortKey, maxResults = 50, pageNumber = 0, filters) {
123
+ return __awaiter(this, arguments, void 0, function* (tableName, sortKey, maxResults = 50, pageNumber = 0, filters = {}) {
136
124
  if (!this.tables[tableName])
137
125
  throw new Error(`table ${tableName} does not exist`);
138
126
  let table = this.tables[tableName];
127
+ let schema = table[0].schema;
139
128
  let columns = PostgresUtils_1.default.columns(table);
140
129
  let offset = maxResults * pageNumber;
141
130
  let { where, values } = this.toWhere(tableName, filters, "", 4);
142
- let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${where} ORDER BY $1 LIMIT $2 OFFSET $3`;
131
+ let query = `SELECT * FROM ${schema}.${tableName} WHERE ${where} ORDER BY $1 LIMIT $2 OFFSET $3`;
143
132
  let elements = this.query(query, [sortKey, maxResults, offset, ...values]);
144
133
  let total = this.count(tableName, filters);
145
134
  return Promise.all([total, elements]).then(([total, elements]) => ({ total, elements }));
146
135
  });
147
136
  }
148
- count(tableName, filters) {
149
- return __awaiter(this, void 0, void 0, function* () {
137
+ count(tableName_1) {
138
+ return __awaiter(this, arguments, void 0, function* (tableName, filters = {}) {
150
139
  if (!this.tables[tableName])
151
140
  throw new Error(`table ${tableName} does not exist`);
141
+ let schema = this.tables[tableName][0].schema;
152
142
  let { where, values } = this.toWhere(tableName, filters);
153
- let query = `SELECT count(*) as count FROM ${this.schema}.${tableName} WHERE ${where}`;
143
+ let query = `SELECT count(*) as count FROM ${schema}.${tableName} WHERE ${where}`;
154
144
  return this.query(query, values).then((result) => result[0].count);
155
145
  });
156
146
  }
157
- select(tableName, select, filters) {
158
- return __awaiter(this, void 0, void 0, function* () {
147
+ select(tableName_1, select_1) {
148
+ return __awaiter(this, arguments, void 0, function* (tableName, select, filters = {}) {
159
149
  if (!this.tables[tableName])
160
150
  throw new Error(`table ${tableName} does not exist`);
151
+ let schema = this.tables[tableName][0].schema;
161
152
  let { where, values } = this.toWhere(tableName, filters);
162
- let query = `SELECT json_agg(u.${select}) as list FROM ${this.schema}.${tableName} u WHERE ${where}`;
153
+ let query = `SELECT json_agg(u.${select}) as list FROM ${schema}.${tableName} u WHERE ${where}`;
163
154
  return this.query(query, values).then((result) => result[0].list);
164
155
  });
165
156
  }
@@ -168,7 +159,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
168
159
  throw new Error(`not implemented yet`);
169
160
  });
170
161
  }
171
- toWhere(tableName, filters, alias = "", index = 1) {
162
+ toWhere(tableName, filters = {}, alias = "", index = 1) {
172
163
  let table = this.tables[tableName];
173
164
  let columns = PostgresUtils_1.default.columns(table);
174
165
  let elements = Object.entries(filters !== null && filters !== void 0 ? filters : []);
@@ -193,11 +184,10 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
193
184
  return __awaiter(this, void 0, void 0, function* () {
194
185
  let result = yield this.native(`
195
186
  SELECT table_name as name,
196
- json_agg(json_build_object('name', column_name, 'default', column_default)) as columns
187
+ json_agg(json_build_object('name', column_name, 'schema', table_schema, 'default', column_default)) as columns
197
188
  FROM information_schema.columns
198
- WHERE (table_schema = $1 or table_schema = 'public')
199
189
  GROUP BY table_name
200
- `, [this.schema]);
190
+ `);
201
191
  for (let table of result.rows)
202
192
  this.tables[table["name"]] = table["columns"];
203
193
  this.onIntrospectedListeners.forEach((l) => l(this.tables));
@@ -29,15 +29,15 @@ class RepositoryRestFormal extends RepositoryRest_1.default {
29
29
  if (json.code === "0")
30
30
  return json.data;
31
31
  else { // @ts-ignore
32
- throw new BusinessErrors_1.FormalError(json.code, json.description, call);
32
+ throw new FormalError(json.code, json.description, call);
33
33
  }
34
34
  }))
35
35
  .catch((error) => {
36
36
  // @ts-ignore
37
- if (error instanceof BusinessErrors_1.FormalError)
37
+ if (error instanceof FormalError)
38
38
  throw error;
39
39
  else { // @ts-ignore
40
- throw new BusinessErrors_1.FormalError("-1", "ConnectionError", undefined, error);
40
+ throw new FormalError("-1", "ConnectionError", undefined, error);
41
41
  }
42
42
  });
43
43
  });
@@ -26,21 +26,28 @@ export declare const BusinessProxy: typeof BaseBusinessProxy;
26
26
  export interface Module extends BaseModule {
27
27
  }
28
28
  import BaseBusinessServer from "./business/BusinessServer";
29
- export declare const BusinessServer: typeof BaseBusinessServer;
29
+ export declare class BusinessServer extends BaseBusinessServer {
30
+ }
30
31
  import BaseBusinessThread from "./business/BusinessThread";
31
- export declare const BusinessThread: typeof BaseBusinessThread;
32
+ export declare abstract class BusinessThread extends BaseBusinessThread {
33
+ }
32
34
  import BaseBusinessErrors, { FormalError as BaseFormalError } from "./business/BusinessErrors";
33
- export declare const BusinessErrors: typeof BaseBusinessErrors;
35
+ export declare class BusinessErrors extends BaseBusinessErrors {
36
+ }
34
37
  export interface FormalError extends BaseFormalError {
35
38
  }
36
39
  import BaseBusinessLogger from "./business/BusinessLogger";
37
- export declare const BusinessLogger: typeof BaseBusinessLogger;
40
+ export declare class BusinessLogger extends BaseBusinessLogger {
41
+ }
38
42
  import _CryptoUtils from "./business/utils/CryptoUtils";
39
- export declare const CryptoUtils: typeof _CryptoUtils;
43
+ export declare abstract class CryptoUtils extends _CryptoUtils {
44
+ }
40
45
  import _NumberUtils from "./business/utils/NumberUtils";
41
- export declare const NumberUtils: typeof _NumberUtils;
46
+ export declare abstract class NumberUtils extends _NumberUtils {
47
+ }
42
48
  import _StringUtils from "./business/utils/StringUtils";
43
- export declare const StringUtils: typeof _StringUtils;
49
+ export declare abstract class StringUtils extends _StringUtils {
50
+ }
44
51
  /**************************************************************/
45
52
  import BaseRepository from "./repository/Repository";
46
53
  export declare const Repository: typeof BaseRepository;
@@ -51,4 +58,5 @@ import _RepositoryDatabasePostgres from "./repository/RepositoryDatabasePostgres
51
58
  export declare class RepositoryDatabasePostgres extends _RepositoryDatabasePostgres {
52
59
  }
53
60
  import _QueryUtils from "./repository/utils/QueryUtils";
54
- export declare const QueryUtils: typeof _QueryUtils;
61
+ export declare abstract class QueryUtils extends _QueryUtils {
62
+ }
@@ -10,7 +10,6 @@ export interface Chain {
10
10
  user: string;
11
11
  password: string;
12
12
  database: string;
13
- schema: string;
14
13
  }
15
14
  export interface Pagination<T> {
16
15
  total: number;
@@ -38,7 +37,6 @@ export default abstract class RepositoryDatabase extends Repository {
38
37
  abstract find<E>(tableName: string, filters: {
39
38
  [key: string]: Primitive | Array<any>;
40
39
  }): Promise<E[]>;
41
- abstract all_depr<E>(tableName: string, options: QueryOptions): Promise<E[]>;
42
40
  abstract add<E>(tableName: string, object: {
43
41
  [key: string]: Primitive;
44
42
  } | any, id?: string): Promise<E>;
@@ -2,13 +2,13 @@ import pg, { QueryResult } from "pg";
2
2
  import RepositoryDatabase, { Chain, Pagination, Primitive, QueryOptions } from "./RepositoryDatabase";
3
3
  export interface Column {
4
4
  name: string;
5
+ schema: string;
5
6
  default?: string;
6
7
  }
7
8
  export default class RepositoryDatabasePostgres extends RepositoryDatabase {
8
9
  private readonly introspectIntervalTime;
9
10
  protected client: pg.Client;
10
11
  private tables;
11
- private schema;
12
12
  constructor();
13
13
  init(chain: Chain): void;
14
14
  private onIntrospectedListeners;
@@ -19,13 +19,12 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
19
19
  native(query: string, values?: any[], options?: QueryOptions): Promise<QueryResult>;
20
20
  query<E>(query: string, values?: any[], options?: QueryOptions): Promise<E[]>;
21
21
  one<E>(tableName: string, id: string): Promise<E>;
22
- any<E>(tableName: string, filters: {
22
+ any<E>(tableName: string, filters?: {
23
23
  [key: string]: Primitive | Array<any>;
24
24
  }): Promise<E>;
25
- find<T>(tableName: string, filters: {
25
+ find<T>(tableName: string, filters?: {
26
26
  [key: string]: Primitive | Array<any>;
27
27
  }): Promise<T[]>;
28
- all_depr<E>(tableName: string, options?: QueryOptions): Promise<E[]>;
29
28
  add<E>(tableName: string, object: {
30
29
  [key: string]: Primitive;
31
30
  } | any, id?: string): Promise<E>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.3.36",
3
+ "version": "0.3.38",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -26,26 +26,26 @@ export const BusinessProxy = BaseBusinessProxy;
26
26
  export interface Module extends BaseModule {}
27
27
 
28
28
  import BaseBusinessServer from "./business/BusinessServer";
29
- export const BusinessServer = BaseBusinessServer;
29
+ export class BusinessServer extends BaseBusinessServer {}
30
30
 
31
31
  import BaseBusinessThread from "./business/BusinessThread";
32
- export const BusinessThread = BaseBusinessThread;
32
+ export abstract class BusinessThread extends BaseBusinessThread {}
33
33
 
34
34
  import BaseBusinessErrors, { FormalError as BaseFormalError } from "./business/BusinessErrors";
35
- export const BusinessErrors = BaseBusinessErrors;
35
+ export class BusinessErrors extends BaseBusinessErrors {}
36
36
  export interface FormalError extends BaseFormalError {}
37
37
 
38
38
  import BaseBusinessLogger from "./business/BusinessLogger";
39
- export const BusinessLogger = BaseBusinessLogger;
39
+ export class BusinessLogger extends BaseBusinessLogger {}
40
40
 
41
41
  import _CryptoUtils from "./business/utils/CryptoUtils";
42
- export const CryptoUtils = _CryptoUtils;
42
+ export abstract class CryptoUtils extends _CryptoUtils {}
43
43
 
44
44
  import _NumberUtils from "./business/utils/NumberUtils";
45
- export const NumberUtils = _NumberUtils;
45
+ export abstract class NumberUtils extends _NumberUtils {}
46
46
 
47
47
  import _StringUtils from "./business/utils/StringUtils";
48
- export const StringUtils = _StringUtils;
48
+ export abstract class StringUtils extends _StringUtils {}
49
49
 
50
50
  /**************************************************************/
51
51
 
@@ -59,4 +59,4 @@ import _RepositoryDatabasePostgres from "./repository/RepositoryDatabasePostgres
59
59
  export class RepositoryDatabasePostgres extends _RepositoryDatabasePostgres {}
60
60
 
61
61
  import _QueryUtils from "./repository/utils/QueryUtils";
62
- export const QueryUtils = _QueryUtils;
62
+ export abstract class QueryUtils extends _QueryUtils {}
@@ -12,7 +12,6 @@ export interface Chain {
12
12
  user: string;
13
13
  password: string;
14
14
  database: string;
15
- schema: string;
16
15
  }
17
16
 
18
17
  export interface Pagination<T> {
@@ -63,8 +62,6 @@ export default abstract class RepositoryDatabase extends Repository
63
62
 
64
63
  abstract find<E>(tableName: string, filters: { [key: string]: Primitive | Array<any> }): Promise<E[]>;
65
64
 
66
- abstract all_depr<E>(tableName: string, options: QueryOptions): Promise<E[]>;
67
-
68
65
  abstract add<E>(tableName: string, object: {[key:string]:Primitive}|any, id?: string): Promise<E>;
69
66
 
70
67
  abstract addAll<T>(tableName: string, objects: ({[key:string]:Primitive }|any)[]): Promise<T[]>;
@@ -4,6 +4,7 @@ import RepositoryDatabase, {Chain, Pagination, Primitive, QueryOptions} from "./
4
4
 
5
5
  export interface Column {
6
6
  name: string
7
+ schema: string
7
8
  default?: string
8
9
  }
9
10
 
@@ -15,8 +16,6 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
15
16
 
16
17
  private tables: { [key: string]: Column[] } = {};
17
18
 
18
- private schema: string = "public";
19
-
20
19
  constructor() {
21
20
  super();
22
21
  this.native = this.native.bind(this);
@@ -26,7 +25,6 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
26
25
  init(chain: Chain)
27
26
  {
28
27
  super.init(chain);
29
- this.schema = chain.schema || "public";
30
28
  this.connect(chain);
31
29
  }
32
30
 
@@ -65,31 +63,20 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
65
63
  return this.any<E>(tableName, { id });
66
64
  }
67
65
 
68
- async any<E>(tableName: string, filters: { [key: string]: Primitive | Array<any> }): Promise<E>
66
+ async any<E>(tableName: string, filters: { [key: string]: Primitive | Array<any> }={}): Promise<E>
69
67
  {
70
68
  return await this.find<E>(tableName, filters).then((rows) => rows[0]);
71
69
  }
72
70
 
73
- async find<T>(tableName: string, filters: { [key: string]: Primitive | Array<any> }): Promise<T[]>
71
+ async find<T>(tableName: string, filters: { [key: string]: Primitive | Array<any> }={}): Promise<T[]>
74
72
  {
75
73
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
74
+ let schema = this.tables[tableName][0].schema;
76
75
  let { where, values } = this.toWhere(tableName, filters);
77
- let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${where}`
76
+ let query = `SELECT * FROM ${schema}.${tableName} WHERE ${where}`
78
77
  return this.query<T>(query, values);
79
78
  }
80
79
 
81
- async all_depr<E>(tableName: string, options: QueryOptions = {}): Promise<E[]>
82
- {
83
- if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
84
- let table = this.tables[tableName];
85
- let schema = options.schema ?? this.schema;
86
-
87
- return this.query(`
88
- SELECT * FROM ${schema}.${tableName}
89
- WHERE ${ options.filters ?? "TRUE" }
90
- `);
91
- }
92
-
93
80
  async add<E>(tableName: string, object: {[key:string]:Primitive}|any, id?: string): Promise<E>
94
81
  {
95
82
  return this.addAll<E>(tableName, [ { id: id, ...object } ]).then((rows) => rows[0]);
@@ -99,8 +86,9 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
99
86
  {
100
87
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
101
88
  let table = this.tables[tableName];
89
+ let schema = table[0].schema;
102
90
  let columns = PostgresUtils.columns(table);
103
- let query = `INSERT INTO ${this.schema}.${tableName} (${columns.join(",")}) VALUES `;
91
+ let query = `INSERT INTO ${schema}.${tableName} (${columns.join(",")}) VALUES `;
104
92
 
105
93
  let values = []; let index = 1;
106
94
  for (let object of objects) {
@@ -120,25 +108,27 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
120
108
  if (!id) throw new Error(`field 'id' is mandatory when updating ${tableName}`);
121
109
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
122
110
  let table = this.tables[tableName];
111
+ let schema = table[0].schema;
123
112
  let columns = PostgresUtils.columns(table);
124
113
 
125
114
  let params = columns.map((column, index) => `\$${index+2}`).join(",");
126
115
  let values = [ id, ...columns.map((column) => object[PostgresUtils.stringToCamel(column)]) ];
127
- let query = `UPDATE ${this.schema}.${tableName} SET (${columns.join(",")}) = (${params}) WHERE id = $1 `
116
+ let query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = (${params}) WHERE id = $1 `
128
117
  query += `RETURNING *`;
129
118
 
130
119
  return this.query<T>(query, values).then((result) => result[0]);
131
120
  }
132
121
 
133
- async page<T>(tableName: string, sortKey: string, maxResults: number = 50, pageNumber: number = 0, filters?: {[key:string]:Primitive|Array<Primitive>}): Promise<Pagination<T>>
122
+ async page<T>(tableName: string, sortKey: string, maxResults: number = 50, pageNumber: number = 0, filters: {[key:string]:Primitive|Array<Primitive>}={}): Promise<Pagination<T>>
134
123
  {
135
124
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
136
125
  let table = this.tables[tableName];
126
+ let schema = table[0].schema;
137
127
  let columns = PostgresUtils.columns(table);
138
128
  let offset = maxResults * pageNumber;
139
129
 
140
130
  let { where, values } = this.toWhere(tableName, filters, "", 4);
141
- let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${ where } ORDER BY $1 LIMIT $2 OFFSET $3`;
131
+ let query = `SELECT * FROM ${schema}.${tableName} WHERE ${ where } ORDER BY $1 LIMIT $2 OFFSET $3`;
142
132
  let elements = this.query<T>(query, [sortKey, maxResults, offset, ...values])
143
133
 
144
134
  let total = this.count(tableName, filters)
@@ -147,19 +137,21 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
147
137
  );
148
138
  }
149
139
 
150
- async count(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<number>
140
+ async count(tableName: string, filters: { [key: string]: Primitive | Array<Primitive> }={}): Promise<number>
151
141
  {
152
142
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
143
+ let schema = this.tables[tableName][0].schema;
153
144
  let { where, values } = this.toWhere(tableName, filters);
154
- let query = `SELECT count(*) as count FROM ${this.schema}.${tableName} WHERE ${where}`
145
+ let query = `SELECT count(*) as count FROM ${schema}.${tableName} WHERE ${where}`
155
146
  return this.query<{count:number}>(query, values).then((result) => result[0].count);
156
147
  }
157
148
 
158
- async select(tableName: string, select: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<string[]>
149
+ async select(tableName: string, select: string, filters: { [key: string]: Primitive | Array<Primitive> }={}): Promise<string[]>
159
150
  {
160
151
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
152
+ let schema = this.tables[tableName][0].schema;
161
153
  let { where, values } = this.toWhere(tableName, filters);
162
- let query = `SELECT json_agg(u.${select}) as list FROM ${this.schema}.${tableName} u WHERE ${where}`
154
+ let query = `SELECT json_agg(u.${select}) as list FROM ${schema}.${tableName} u WHERE ${where}`
163
155
  return this.query<{list:string[]}>(query, values).then((result) => result[0].list);
164
156
  }
165
157
 
@@ -168,7 +160,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
168
160
  throw new Error(`not implemented yet`);
169
161
  }
170
162
 
171
- toWhere(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }, alias:string = "", index=1)
163
+ toWhere(tableName: string, filters: { [key: string]: Primitive | Array<Primitive> }={}, alias:string = "", index=1)
172
164
  {
173
165
  let table = this.tables[tableName];
174
166
  let columns = PostgresUtils.columns(table);
@@ -190,11 +182,10 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
190
182
  private async introspect() {
191
183
  let result = await this.native(`
192
184
  SELECT table_name as name,
193
- json_agg(json_build_object('name', column_name, 'default', column_default)) as columns
185
+ json_agg(json_build_object('name', column_name, 'schema', table_schema, 'default', column_default)) as columns
194
186
  FROM information_schema.columns
195
- WHERE (table_schema = $1 or table_schema = 'public')
196
187
  GROUP BY table_name
197
- `, [this.schema]);
188
+ `);
198
189
 
199
190
  for (let table of result.rows)
200
191
  this.tables[table["name"]] = table["columns"];
@@ -1,7 +1,6 @@
1
1
  import RepositoryRest from "./RepositoryRest";
2
2
  import {Wrapper} from "../api/ServiceRestFormal";
3
3
  import {HttpRequest} from "../api/Service";
4
- import { FormalError } from "../business/BusinessErrors";
5
4
 
6
5
  export default class RepositoryRestFormal<S=any> extends RepositoryRest<Wrapper<S>> {
7
6