ismx-nexo-node-app 0.4.103 → 0.4.105

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,5 +1,47 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Hash = void 0;
5
+ class Hash {
6
+ constructor(dict) {
7
+ this.size = null;
8
+ this[_a] = "Hash";
9
+ this.dict = dict !== null && dict !== void 0 ? dict : {};
10
+ }
11
+ add(value) {
12
+ this.dict[value] = null;
13
+ return this;
14
+ }
15
+ clear() {
16
+ this.dict = {};
17
+ }
18
+ delete(value) {
19
+ return delete this.dict[value];
20
+ }
21
+ forEach(callbackfn, thisArg) {
22
+ return Object.keys(this.dict).forEach((v) => callbackfn(v, v, this), thisArg);
23
+ }
24
+ has(value) {
25
+ return !!this.dict[value];
26
+ }
27
+ entries() {
28
+ return Object.entries(this.dict);
29
+ }
30
+ keys() {
31
+ return Object.keys(this.dict).values();
32
+ }
33
+ values() {
34
+ return Object.keys(this.dict).values();
35
+ }
36
+ length() {
37
+ return Object.keys(this.dict).length;
38
+ }
39
+ [Symbol.iterator]() {
40
+ return Object.keys(this.dict)[Symbol.iterator]();
41
+ }
42
+ }
43
+ exports.Hash = Hash;
44
+ _a = Symbol.toStringTag;
3
45
  class Repository {
4
46
  }
5
47
  exports.default = Repository;
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const PostgresUtils_1 = __importDefault(require("./utils/PostgresUtils"));
39
39
  const RepositoryDatabase_1 = __importDefault(require("./RepositoryDatabase"));
40
+ const Repository_1 = require("./Repository");
40
41
  class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
41
42
  constructor() {
42
43
  super();
@@ -207,7 +208,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
207
208
  let schema = this.tables[tableName][0].schema;
208
209
  let { where, values } = this.toWhere(tableName, filters);
209
210
  let query = `SELECT count(*) as count FROM ${schema}.${tableName} WHERE ${where}`;
210
- return this.query(query, values).then((result) => { var _a, _b; return (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0; });
211
+ return this.query(query, values).then((result) => { var _a, _b; return Number.parseInt((_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : "0"); });
211
212
  });
212
213
  }
213
214
  select(tableName_1, select_1) {
@@ -220,6 +221,18 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
220
221
  return this.query(query, values).then((result) => { var _a, _b; return (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : []; });
221
222
  });
222
223
  }
224
+ selectSet(tableName, select, filters) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ if (!this.tables[tableName])
227
+ throw new Error(`table ${tableName} does not exist`);
228
+ let schema = this.tables[tableName][0].schema;
229
+ let { where, values } = this.toWhere(tableName, filters);
230
+ let query = `
231
+ SELECT json_object_agg(u.${select}, NULL) as list
232
+ FROM ( SELECT DISTINCT u.${select} FROM FROM ${schema}.${tableName} WHERE "user" = ${where} ) t`;
233
+ return this.query(query, values).then((result) => { var _a, _b; return new Repository_1.Hash((_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : {}); });
234
+ });
235
+ }
223
236
  toWhere(tableName, filters = {}, alias = "", index = 1) {
224
237
  let table = this.tables[tableName];
225
238
  let columns = PostgresUtils_1.default.columns(table);
@@ -75,10 +75,6 @@ class RepositoryRest extends Repository_1.default {
75
75
  RepositoryRest.defaultReviver = (key, value) => {
76
76
  if (DateUtils_1.default.isIsoDate(value))
77
77
  return new Date(value);
78
- if (Number.isInteger(value))
79
- return parseInt(value);
80
- if (!isNaN(Number(value)) && value.includes("."))
81
- return parseFloat(value);
82
78
  return value;
83
79
  };
84
80
  exports.default = RepositoryRest;
@@ -3,5 +3,21 @@ export interface Pagination<T> {
3
3
  elements: T[];
4
4
  }
5
5
  export type Transient<T> = Omit<T, 'id'>;
6
+ export declare class Hash<T extends string | number | symbol> implements Set<T> {
7
+ dict: Record<T, any>;
8
+ size: number;
9
+ constructor(dict?: Record<T, any>);
10
+ add(value: T): this;
11
+ clear(): void;
12
+ delete(value: T): boolean;
13
+ forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
14
+ has(value: T): boolean;
15
+ entries(): SetIterator<[T, T]>;
16
+ keys(): SetIterator<T>;
17
+ values(): SetIterator<T>;
18
+ length(): number;
19
+ [Symbol.iterator](): SetIterator<T>;
20
+ [Symbol.toStringTag]: string;
21
+ }
6
22
  export default class Repository {
7
23
  }
@@ -10,7 +10,8 @@ export interface Chain {
10
10
  password: string;
11
11
  database: string;
12
12
  }
13
- export type Primitive = string | number | Date | null | undefined;
13
+ export type Primitive = string | number | symbol;
14
+ export type Valuable = Primitive | Date | null | undefined;
14
15
  export default abstract class RepositoryDatabase extends Repository {
15
16
  protected connected: boolean;
16
17
  protected chain: Chain;
@@ -27,36 +28,36 @@ export default abstract class RepositoryDatabase extends Repository {
27
28
  abstract query<E>(query: string, values: any[], options: QueryOptions): Promise<E[]>;
28
29
  abstract one<E>(tableName: string, id: string): Promise<E>;
29
30
  abstract any<E>(tableName: string, filters: {
30
- [key: string]: Primitive | Array<any>;
31
+ [key: string]: Valuable | Array<any>;
31
32
  }): Promise<E>;
32
33
  abstract find<E>(tableName: string, filters: {
33
- [key: string]: Primitive | Array<any>;
34
+ [key: string]: Valuable | Array<any>;
34
35
  }): Promise<E[]>;
35
36
  abstract group(tableName: string, key: string, value: string, filters: {
36
- [p: string]: Primitive | Array<any>;
37
+ [p: string]: Valuable | Array<any>;
37
38
  }): Promise<{
38
39
  [p: string]: string[];
39
40
  }>;
40
41
  abstract add<E>(tableName: string, object: {
41
- [key: string]: Primitive;
42
+ [key: string]: Valuable;
42
43
  } | any, id?: string): Promise<E>;
43
44
  abstract addAll<T>(tableName: string, objects: ({
44
- [key: string]: Primitive;
45
+ [key: string]: Valuable;
45
46
  } | any)[]): Promise<T[]>;
46
47
  abstract update<T>(tableName: string, id: string, object: {
47
- [key: string]: Primitive;
48
+ [key: string]: Valuable;
48
49
  } | any): Promise<T>;
49
50
  abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {
50
- [key: string]: Primitive | Array<Primitive>;
51
+ [key: string]: Valuable | Array<Valuable>;
51
52
  }): Promise<Pagination<T>>;
52
53
  abstract exist(tableName: string, filters?: {
53
- [key: string]: Primitive | Array<Primitive>;
54
+ [key: string]: Valuable | Array<Valuable>;
54
55
  }): Promise<boolean>;
55
56
  abstract count(tableName: string, filters?: {
56
- [key: string]: Primitive | Array<Primitive>;
57
+ [key: string]: Valuable | Array<Valuable>;
57
58
  }): Promise<number>;
58
59
  abstract select(tableName: string, select: string, filters?: {
59
- [key: string]: Primitive | Array<Primitive>;
60
+ [key: string]: Valuable | Array<Valuable>;
60
61
  }): Promise<string[]>;
61
62
  abstract delete<T>(tableName: string, id: string): Promise<T>;
62
63
  abstract deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
@@ -1,5 +1,5 @@
1
- import RepositoryDatabase, { Chain, Primitive, QueryOptions } from "./RepositoryDatabase";
2
- import { Pagination } from "./Repository";
1
+ import RepositoryDatabase, { Chain, Valuable, QueryOptions, Primitive } from "./RepositoryDatabase";
2
+ import { Hash, Pagination } from "./Repository";
3
3
  export interface Column {
4
4
  name: string;
5
5
  schema: string;
@@ -20,42 +20,43 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
20
20
  query<E>(query: string, values?: any[], options?: QueryOptions): Promise<E[]>;
21
21
  one<E>(tableName: string, id: string): Promise<E>;
22
22
  any<E>(tableName: string, filters?: {
23
- [key: string]: Primitive | Array<any>;
23
+ [key: string]: Valuable | Array<any>;
24
24
  }): Promise<E>;
25
25
  find<T>(tableName: string, filters?: {
26
- [key: string]: Primitive | Array<any>;
26
+ [key: string]: Valuable | Array<any>;
27
27
  }): Promise<T[]>;
28
28
  group(tableName: string, key: string, value: string, filters: {
29
- [p: string]: Primitive | Array<any>;
29
+ [p: string]: Valuable | Array<any>;
30
30
  }): Promise<{
31
31
  [p: string]: any[];
32
32
  }>;
33
33
  add<E>(tableName: string, object: {
34
- [key: string]: Primitive;
34
+ [key: string]: Valuable;
35
35
  } | any, id?: string): Promise<E>;
36
36
  addAll<T>(tableName: string, objects: ({
37
- [key: string]: Primitive;
37
+ [key: string]: Valuable;
38
38
  } | any)[]): Promise<T[]>;
39
39
  update<T>(tableName: string, id: string, object: Partial<T>): Promise<T>;
40
40
  delete<T>(tableName: string, id: string): Promise<T>;
41
41
  deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
42
42
  page<T>(tableName: string, sortKey: string, maxResults?: number, pageNumber?: number, filters?: {
43
- [key: string]: Primitive | Array<Primitive>;
43
+ [key: string]: Valuable | Array<Valuable>;
44
44
  }): Promise<Pagination<T>>;
45
45
  exist(tableName: string, filters?: {
46
- [p: string]: Primitive | Array<Primitive>;
46
+ [p: string]: Valuable | Array<Valuable>;
47
47
  }): Promise<boolean>;
48
48
  count(tableName: string, filters?: {
49
- [key: string]: Primitive | Array<Primitive>;
49
+ [key: string]: Valuable | Array<Valuable>;
50
50
  }): Promise<number>;
51
51
  select(tableName: string, select: string, filters?: {
52
- [key: string]: Primitive | Array<Primitive>;
52
+ [key: string]: Valuable | Array<Valuable>;
53
53
  }): Promise<string[]>;
54
+ selectSet<T>(tableName: string, select: string, filters: Partial<T>): Promise<Hash<Primitive>>;
54
55
  toWhere(tableName: string, filters?: {
55
- [key: string]: Primitive | Array<Primitive>;
56
+ [key: string]: Valuable | Array<Valuable>;
56
57
  }, alias?: string, index?: number): {
57
58
  where: string;
58
- values: (string | number | Date | Primitive[])[];
59
+ values: (string | number | symbol | Date | Valuable[])[];
59
60
  };
60
61
  private introspect;
61
62
  }
@@ -13,5 +13,5 @@ export default class RepositoryRest<Body = any, Res = any> extends Repository {
13
13
  constructor(baseUrl: string, options?: RestOptions);
14
14
  call<B = Body, E = Res>(method?: string, endpoint?: string, request?: HttpRequest<B>): Promise<HttpResponse<E>>;
15
15
  private reviver;
16
- static defaultReviver: (key: string, value: string) => string | number | Date;
16
+ static defaultReviver: (key: string, value: any) => any;
17
17
  }
@@ -1,12 +1,12 @@
1
1
  import { Column } from "../RepositoryDatabasePostgres";
2
- import { Primitive } from "../RepositoryDatabase";
2
+ import { Valuable } from "../RepositoryDatabase";
3
3
  export default abstract class PostgresUtils {
4
4
  static camelToSnake(column: string): string;
5
5
  static snakeToCamel(obj: any): any;
6
6
  static columns(table: Column[]): string[];
7
7
  static isReservedWord(word: string): boolean;
8
8
  static bindOrDefault(table: Column[], object: {
9
- [p: string]: Primitive;
9
+ [p: string]: Valuable;
10
10
  }, startIndex: any): {
11
11
  bindings: string[];
12
12
  values: any[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.103",
3
+ "version": "0.4.105",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -5,6 +5,49 @@ export interface Pagination<T> {
5
5
 
6
6
  export type Transient<T> = Omit<T, 'id'>
7
7
 
8
+ export class Hash<T extends string | number | symbol> implements Set<T>
9
+ {
10
+ dict: Record<T, any>
11
+ size: number = null!;
12
+
13
+ constructor(dict?: Record<T, any>) {
14
+ this.dict = dict ?? {} as Record<T, any>;
15
+ }
16
+
17
+ add(value: T): this {
18
+ this.dict[value] = null;
19
+ return this;
20
+ }
21
+ clear(): void {
22
+ this.dict = {} as Record<T, any>;
23
+ }
24
+ delete(value: T): boolean {
25
+ return delete this.dict[value];
26
+ }
27
+ forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void {
28
+ return Object.keys(this.dict).forEach((v) => callbackfn(v as T, v as T, this), thisArg);
29
+ }
30
+ has(value: T): boolean {
31
+ return !!this.dict[value];
32
+ }
33
+ entries(): SetIterator<[T, T]> {
34
+ return Object.entries(this.dict) as unknown as SetIterator<[T, T]>;
35
+ }
36
+ keys(): SetIterator<T> {
37
+ return Object.keys(this.dict).values() as SetIterator<T>;
38
+ }
39
+ values(): SetIterator<T> {
40
+ return Object.keys(this.dict).values() as SetIterator<T>;
41
+ }
42
+ length(): number {
43
+ return Object.keys(this.dict).length;
44
+ }
45
+ [Symbol.iterator](): SetIterator<T> {
46
+ return (Object.keys(this.dict) as T[])[Symbol.iterator]()
47
+ }
48
+ [Symbol.toStringTag]: string = "Hash";
49
+ }
50
+
8
51
  export default class Repository {
9
52
 
10
53
  }
@@ -13,7 +13,8 @@ export interface Chain {
13
13
  database: string;
14
14
  }
15
15
 
16
- export type Primitive = string | number | Date | null | undefined;
16
+ export type Primitive = string | number | symbol
17
+ export type Valuable = Primitive | Date | null | undefined;
17
18
 
18
19
  export default abstract class RepositoryDatabase extends Repository
19
20
  {
@@ -52,25 +53,25 @@ export default abstract class RepositoryDatabase extends Repository
52
53
 
53
54
  abstract one<E>(tableName: string, id: string): Promise<E>;
54
55
 
55
- abstract any<E>(tableName: string, filters: { [key: string]: Primitive | Array<any> }): Promise<E>;
56
+ abstract any<E>(tableName: string, filters: { [key: string]: Valuable | Array<any> }): Promise<E>;
56
57
 
57
- abstract find<E>(tableName: string, filters: { [key: string]: Primitive | Array<any> }): Promise<E[]>;
58
+ abstract find<E>(tableName: string, filters: { [key: string]: Valuable | Array<any> }): Promise<E[]>;
58
59
 
59
- abstract group(tableName: string, key: string, value: string, filters: { [p: string]: Primitive | Array<any> }): Promise<{ [p: string]: string[] }>
60
+ abstract group(tableName: string, key: string, value: string, filters: { [p: string]: Valuable | Array<any> }): Promise<{ [p: string]: string[] }>
60
61
 
61
- abstract add<E>(tableName: string, object: {[key:string]:Primitive}|any, id?: string): Promise<E>;
62
+ abstract add<E>(tableName: string, object: {[key:string]:Valuable}|any, id?: string): Promise<E>;
62
63
 
63
- abstract addAll<T>(tableName: string, objects: ({[key:string]:Primitive }|any)[]): Promise<T[]>;
64
+ abstract addAll<T>(tableName: string, objects: ({[key:string]:Valuable }|any)[]): Promise<T[]>;
64
65
 
65
- abstract update<T>(tableName: string, id: string, object: {[key:string]:Primitive}|any): Promise<T>;
66
+ abstract update<T>(tableName: string, id: string, object: {[key:string]:Valuable}|any): Promise<T>;
66
67
 
67
- abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {[key:string]:Primitive|Array<Primitive>}): Promise<Pagination<T>>;
68
+ abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {[key:string]:Valuable|Array<Valuable>}): Promise<Pagination<T>>;
68
69
 
69
- abstract exist(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<boolean>;
70
+ abstract exist(tableName: string, filters?: { [key: string]: Valuable | Array<Valuable> }): Promise<boolean>;
70
71
 
71
- abstract count(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<number>;
72
+ abstract count(tableName: string, filters?: { [key: string]: Valuable | Array<Valuable> }): Promise<number>;
72
73
 
73
- abstract select(tableName: string, select: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<string[]>;
74
+ abstract select(tableName: string, select: string, filters?: { [key: string]: Valuable | Array<Valuable> }): Promise<string[]>;
74
75
 
75
76
  abstract delete<T>(tableName: string, id: string): Promise<T>;
76
77
 
@@ -1,6 +1,6 @@
1
1
  import PostgresUtils from "./utils/PostgresUtils";
2
- import RepositoryDatabase, {Chain, Primitive, QueryOptions} from "./RepositoryDatabase";
3
- import {Pagination} from "./Repository";
2
+ import RepositoryDatabase, {Chain, Valuable, QueryOptions, Primitive} from "./RepositoryDatabase";
3
+ import {Hash, Pagination} from "./Repository";
4
4
 
5
5
  export interface Column {
6
6
  name: string
@@ -66,12 +66,12 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
66
66
  return this.any<E>(tableName, { id });
67
67
  }
68
68
 
69
- async any<E>(tableName: string, filters: { [key: string]: Primitive | Array<any> }={}): Promise<E>
69
+ async any<E>(tableName: string, filters: { [key: string]: Valuable | Array<any> }={}): Promise<E>
70
70
  {
71
71
  return await this.find<E>(tableName, filters).then((rows) => rows[0]);
72
72
  }
73
73
 
74
- async find<T>(tableName: string, filters: { [key: string]: Primitive | Array<any> }={}): Promise<T[]>
74
+ async find<T>(tableName: string, filters: { [key: string]: Valuable | Array<any> }={}): Promise<T[]>
75
75
  {
76
76
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
77
77
  let schema = this.tables[tableName][0].schema;
@@ -80,7 +80,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
80
80
  return this.query<T>(query, values);
81
81
  }
82
82
 
83
- async group(tableName: string, key: string, value: string, filters: { [p: string]: Primitive | Array<any> }): Promise<{ [p: string]: any[] }> {
83
+ async group(tableName: string, key: string, value: string, filters: { [p: string]: Valuable | Array<any> }): Promise<{ [p: string]: any[] }> {
84
84
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
85
85
  let schema = this.tables[tableName][0].schema;
86
86
  let { where, values } = this.toWhere(tableName, filters);
@@ -94,12 +94,12 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
94
94
  });
95
95
  }
96
96
 
97
- async add<E>(tableName: string, object: {[key:string]:Primitive}|any, id?: string): Promise<E>
97
+ async add<E>(tableName: string, object: {[key:string]:Valuable}|any, id?: string): Promise<E>
98
98
  {
99
99
  return this.addAll<E>(tableName, [ { id: id, ...object } ]).then((rows) => rows[0]);
100
100
  }
101
101
 
102
- async addAll<T>(tableName: string, objects: ({[key:string]:Primitive }|any)[]): Promise<T[]>
102
+ async addAll<T>(tableName: string, objects: ({[key:string]:Valuable }|any)[]): Promise<T[]>
103
103
  {
104
104
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
105
105
  let table = this.tables[tableName];
@@ -153,7 +153,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
153
153
  return this.query<T>(query, values);
154
154
  }
155
155
 
156
- async page<T>(tableName: string, sortKey: string, maxResults: number = 50, pageNumber: number = 0, filters: {[key:string]:Primitive|Array<Primitive>}={}): Promise<Pagination<T>>
156
+ async page<T>(tableName: string, sortKey: string, maxResults: number = 50, pageNumber: number = 0, filters: {[key:string]:Valuable|Array<Valuable>}={}): Promise<Pagination<T>>
157
157
  {
158
158
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
159
159
  let table = this.tables[tableName];
@@ -171,20 +171,20 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
171
171
  );
172
172
  }
173
173
 
174
- async exist(tableName: string, filters: { [p: string]: Primitive | Array<Primitive> }={}): Promise<boolean> {
174
+ async exist(tableName: string, filters: { [p: string]: Valuable | Array<Valuable> }={}): Promise<boolean> {
175
175
  return (await this.count(tableName, filters)) > 0;
176
176
  }
177
177
 
178
- async count(tableName: string, filters: { [key: string]: Primitive | Array<Primitive> }={}): Promise<number>
178
+ async count(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<number>
179
179
  {
180
180
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
181
181
  let schema = this.tables[tableName][0].schema;
182
182
  let { where, values } = this.toWhere(tableName, filters);
183
183
  let query = `SELECT count(*) as count FROM ${schema}.${tableName} WHERE ${where}`
184
- return this.query<{count:number}>(query, values).then((result) => result[0]?.count ?? 0);
184
+ return this.query<{count:string}>(query, values).then((result) => Number.parseInt(result[0]?.count ?? "0"));
185
185
  }
186
186
 
187
- async select(tableName: string, select: string, filters: { [key: string]: Primitive | Array<Primitive> }={}): Promise<string[]>
187
+ async select(tableName: string, select: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<string[]>
188
188
  {
189
189
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
190
190
  let schema = this.tables[tableName][0].schema;
@@ -193,7 +193,18 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
193
193
  return this.query<{list:string[]}>(query, values).then((result) => result[0]?.list ?? []);
194
194
  }
195
195
 
196
- toWhere(tableName: string, filters: { [key: string]: Primitive | Array<Primitive> }={}, alias:string = "", index=1)
196
+ async selectSet<T>(tableName: string, select: string, filters: Partial<T>): Promise<Hash<Primitive>>
197
+ {
198
+ if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
199
+ let schema = this.tables[tableName][0].schema;
200
+ let { where, values } = this.toWhere(tableName, filters as any);
201
+ let query = `
202
+ SELECT json_object_agg(u.${select}, NULL) as list
203
+ FROM ( SELECT DISTINCT u.${select} FROM FROM ${schema}.${tableName} WHERE "user" = ${where} ) t`;
204
+ return this.query<{list:Record<Primitive, null>}>(query, values).then((result) => new Hash(result[0]?.list ?? {}));
205
+ }
206
+
207
+ toWhere(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> }={}, alias:string = "", index=1)
197
208
  {
198
209
  let table = this.tables[tableName];
199
210
  let columns = PostgresUtils.columns(table);
@@ -78,17 +78,15 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
78
78
  });
79
79
  }
80
80
 
81
- private reviver(key: string, value: string) {
81
+ private reviver(key: string, value: any) {
82
82
  let revived = this.options.jsonReviver?.(key, value);
83
83
  if (revived) return revived;
84
-
84
+
85
85
  return RepositoryRest.defaultReviver(key, value);
86
86
  }
87
87
 
88
- static defaultReviver = (key: string, value: string) => {
88
+ static defaultReviver = (key: string, value: any) => {
89
89
  if (DateUtils.isIsoDate(value)) return new Date(value);
90
- if (Number.isInteger(value)) return parseInt(value);
91
- if (!isNaN(Number(value)) && value.includes(".")) return parseFloat(value);
92
90
  return value;
93
91
  }
94
92
 
@@ -1,5 +1,5 @@
1
1
  import {Column} from "../RepositoryDatabasePostgres";
2
- import {Primitive} from "../RepositoryDatabase";
2
+ import {Valuable} from "../RepositoryDatabase";
3
3
 
4
4
  export default abstract class PostgresUtils
5
5
  {
@@ -41,7 +41,7 @@ export default abstract class PostgresUtils
41
41
  return reservedWords.has(word.toLowerCase());
42
42
  }
43
43
 
44
- static bindOrDefault(table: Column[], object: { [p: string]: Primitive }, startIndex: any): { bindings: string[], values: any[] } {
44
+ static bindOrDefault(table: Column[], object: { [p: string]: Valuable }, startIndex: any): { bindings: string[], values: any[] } {
45
45
 
46
46
  let index = startIndex;
47
47
  let bindings: string[] = [];