@things-factory/shell 5.0.0-alpha.5 → 5.0.0-alpha.50

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.
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildWhereClause = void 0;
4
+ function getClause(selectQueryBuilder, columnMeta, operator, field, pname) {
5
+ const relation = columnMeta.relationMetadata;
6
+ if (!relation) {
7
+ switch (operator) {
8
+ case 'like':
9
+ return `${field} LIKE :${pname}`;
10
+ case 'search':
11
+ case 'i_like':
12
+ return `LOWER(${field}) LIKE :${pname}`;
13
+ case 'nlike':
14
+ return `${field} NOT LIKE :${pname}`;
15
+ case 'i_nlike':
16
+ return `LOWER(${field}) NOT LIKE :${pname}`;
17
+ }
18
+ }
19
+ const inverseEntityMetadata = relation.inverseEntityMetadata;
20
+ const { target, tableName, ownColumns } = inverseEntityMetadata;
21
+ var subquery = selectQueryBuilder.subQuery().select('id').from(target, tableName);
22
+ switch (operator) {
23
+ case 'like':
24
+ subquery = subquery.where(`${tableName}.name LIKE :${pname}`);
25
+ break;
26
+ case 'search':
27
+ case 'i_like':
28
+ subquery = subquery.where(`LOWER(${tableName}.name) LIKE :${pname}`);
29
+ break;
30
+ case 'nlike':
31
+ subquery = subquery.where(`${tableName}.name NOT LIKE :${pname}`);
32
+ break;
33
+ case 'i_nlike':
34
+ subquery = subquery.where(`LOWER(${tableName}.name) NOT LIKE :${pname}`);
35
+ break;
36
+ }
37
+ if (ownColumns.find(column => column.propertyName === 'domain')) {
38
+ subquery.andWhere(`${tableName}.domain_id = :domain`);
39
+ }
40
+ return `${field} IN ${subquery.getQuery()}`;
41
+ }
42
+ const buildWhereClause = function (options) {
43
+ const { alias, columnMeta, operator, value, seq, selectQueryBuilder, domain } = options;
44
+ const values = value instanceof Array ? value : [value];
45
+ const { propertyName: name, propertyAliasName, propertyPath: path, databaseName } = columnMeta;
46
+ const field = `${alias}.${databaseName}`;
47
+ const pname = `args${seq}`;
48
+ switch (operator) {
49
+ case 'eq':
50
+ return {
51
+ clause: `${field} = :${pname}`,
52
+ parameters: { [pname]: value }
53
+ };
54
+ case 'like':
55
+ return {
56
+ clause: getClause(selectQueryBuilder, columnMeta, operator, field, pname),
57
+ parameters: { [pname]: `%${value}%` }
58
+ };
59
+ case 'search':
60
+ case 'i_like':
61
+ return {
62
+ clause: getClause(selectQueryBuilder, columnMeta, operator, field, pname),
63
+ parameters: { [pname]: `%${String(value).toLowerCase()}%` }
64
+ };
65
+ case 'nlike':
66
+ return {
67
+ clause: getClause(selectQueryBuilder, columnMeta, operator, field, pname),
68
+ value: { [pname]: `%${value}%` }
69
+ };
70
+ case 'i_nlike':
71
+ return {
72
+ clause: getClause(selectQueryBuilder, columnMeta, operator, field, pname),
73
+ value: { [pname]: `%${String(value).toLowerCase()}%` }
74
+ };
75
+ case 'lt':
76
+ return {
77
+ clause: `${field} < :${pname}`,
78
+ parameters: { [pname]: value }
79
+ };
80
+ case 'gt':
81
+ return {
82
+ clause: `${field} > :${pname}`,
83
+ parameters: { [pname]: value }
84
+ };
85
+ case 'lte':
86
+ return {
87
+ clause: `${field} <= :${pname}`,
88
+ parameters: { [pname]: value }
89
+ };
90
+ case 'gte':
91
+ return {
92
+ clause: `${field} >= :${pname}`,
93
+ parameters: { [pname]: value }
94
+ };
95
+ case 'noteq':
96
+ return {
97
+ clause: `${field} != :${pname}`,
98
+ parameters: { [pname]: value }
99
+ };
100
+ case 'in':
101
+ return {
102
+ clause: `${field} IN (:...${pname})`,
103
+ parameters: { [pname]: values }
104
+ };
105
+ case 'notin':
106
+ return {
107
+ clause: `${field} NOT IN (:...${pname})`,
108
+ parameters: { [pname]: values }
109
+ };
110
+ case 'notin_with_null':
111
+ return {
112
+ clause: `${field} IS NULL OR ${field} NOT IN (:...${pname}))`,
113
+ parameters: { [pname]: values }
114
+ };
115
+ case 'is_null':
116
+ return {
117
+ clause: `${field} IS NULL`
118
+ };
119
+ case 'is_not_null':
120
+ return {
121
+ clause: `${field} IS NOT NULL`
122
+ };
123
+ case 'is_false':
124
+ return {
125
+ clause: `${field} IS FALSE`
126
+ };
127
+ case 'is_true':
128
+ return {
129
+ clause: `${field} IS TRUE`
130
+ };
131
+ case 'is_not_false':
132
+ return {
133
+ clause: `${field} IS NOT FALSE`
134
+ };
135
+ case 'is_not_true':
136
+ return {
137
+ clause: `${field} IS NOT TRUE`
138
+ };
139
+ case 'is_present':
140
+ return {
141
+ clause: `${field} IS PRESENT`
142
+ };
143
+ case 'is_blank':
144
+ return {
145
+ clause: `${field} IS BLANK`
146
+ };
147
+ case 'is_empty_num_id':
148
+ return {
149
+ clause: `${field} IS EMPTY NUMERIC ID`
150
+ };
151
+ case 'between':
152
+ return {
153
+ clause: `${field} BETWEEN :${pname}_1 AND :${pname}_2`,
154
+ parameters: { [`args${seq}_1`]: values[0], [`args${seq}_2`]: values[1] }
155
+ };
156
+ }
157
+ };
158
+ exports.buildWhereClause = buildWhereClause;
159
+ //# sourceMappingURL=where-clause-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"where-clause-builder.js","sourceRoot":"","sources":["../../server/utils/where-clause-builder.ts"],"names":[],"mappings":";;;AAKA,SAAS,SAAS,CAChB,kBAA2C,EAC3C,UAA0B,EAC1B,QAAgB,EAChB,KAAa,EACb,KAAa;IAEb,MAAM,QAAQ,GAAG,UAAU,CAAC,gBAAgB,CAAA;IAE5C,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,QAAQ,EAAE;YAChB,KAAK,MAAM;gBACT,OAAO,GAAG,KAAK,UAAU,KAAK,EAAE,CAAA;YAElC,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ;gBACX,OAAO,SAAS,KAAK,WAAW,KAAK,EAAE,CAAA;YAEzC,KAAK,OAAO;gBACV,OAAO,GAAG,KAAK,cAAc,KAAK,EAAE,CAAA;YAEtC,KAAK,SAAS;gBACZ,OAAO,SAAS,KAAK,eAAe,KA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A0I5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/shell",
3
- "version": "5.0.0-alpha.5",
3
+ "version": "5.0.0-alpha.50",
4
4
  "description": "Core module for framework",
5
5
  "bin": {
6
6
  "things-factory": "bin/things-factory",
@@ -31,12 +31,12 @@
31
31
  "test": "NODE_ENV=test jest"
32
32
  },
33
33
  "dependencies": {
34
- "@apollo/client": "^3.5.6",
35
- "@graphql-tools/merge": "^7.0.0",
36
- "@graphql-tools/schema": "^8.2.0",
37
- "@graphql-tools/utils": "^8.3.0",
34
+ "@apollo/client": "^3.5.10",
35
+ "@graphql-tools/merge": "^8.2.3",
36
+ "@graphql-tools/schema": "^8.3.2",
37
+ "@graphql-tools/utils": "^8.6.2",
38
38
  "@hatiolab/koa-webpack": "^6.0.0",
39
- "@hatiolab/things-scene": "^2.7.34",
39
+ "@hatiolab/things-scene": "^3.0.12",
40
40
  "@koa/cors": "^3.1.0",
41
41
  "@material/mwc-button": "^0.25.3",
42
42
  "@material/mwc-fab": "^0.25.3",
@@ -44,26 +44,26 @@
44
44
  "@material/mwc-icon-button": "^0.25.3",
45
45
  "@material/mwc-slider": "^0.25.3",
46
46
  "@material/mwc-textfield": "^0.25.3",
47
- "@operato/board": "1.0.0-alpha.4",
48
- "@operato/graphql": "1.0.0-alpha.4",
49
- "@operato/help": "1.0.0-alpha.4",
50
- "@operato/layout": "1.0.0-alpha.4",
51
- "@operato/shell": "1.0.0-alpha.4",
52
- "@operato/utils": "1.0.0-alpha.4",
53
- "@things-factory/ejs-remote": "^5.0.0-alpha.5",
54
- "@things-factory/env": "^5.0.0-alpha.5",
55
- "@things-factory/styles": "^5.0.0-alpha.5",
56
- "@things-factory/utils": "^5.0.0-alpha.5",
47
+ "@operato/board": "1.0.0-beta.20",
48
+ "@operato/graphql": "1.0.0-beta.20",
49
+ "@operato/help": "1.0.0-beta.20",
50
+ "@operato/layout": "1.0.0-beta.20",
51
+ "@operato/shell": "1.0.0-beta.20",
52
+ "@operato/utils": "1.0.0-beta.20",
53
+ "@things-factory/ejs-remote": "^5.0.0-alpha.50",
54
+ "@things-factory/env": "^5.0.0-alpha.50",
55
+ "@things-factory/styles": "^5.0.0-alpha.50",
56
+ "@things-factory/utils": "^5.0.0-alpha.50",
57
57
  "@webcomponents/webcomponentsjs": "^2.6.0",
58
58
  "@webpack-contrib/schema-utils": "^1.0.0-beta.0",
59
- "apollo-server-core": "^3.5.0",
60
- "apollo-server-koa": "^3.5.0",
61
- "apollo-server-types": "^3.4.0",
59
+ "apollo-server-core": "^3.6.4",
60
+ "apollo-server-koa": "^3.6.4",
61
+ "apollo-server-types": "^3.5.1",
62
62
  "apollo-upload-client": "^17.0.0",
63
63
  "args": "^5.0.0",
64
64
  "broadcastchannel-polyfill": "^1.0.1",
65
65
  "chalk": "^4.1.0",
66
- "class-validator": "^0.12.2",
66
+ "class-validator": "^0.13.2",
67
67
  "core-js": "^3.16.0",
68
68
  "csvtojson": "^2.0.10",
69
69
  "debug": "^4.1.1",
@@ -75,9 +75,9 @@
75
75
  "graphql-redis-subscriptions": "^2.4.2",
76
76
  "graphql-subscriptions": "^2.0.0",
77
77
  "graphql-tag": "^2.12.6",
78
- "graphql-upload": "^12.0.0",
78
+ "graphql-upload": "^13.0.0",
79
79
  "haunted": "^4.8.2",
80
- "html-webpack-plugin": "^4.3.0",
80
+ "html-webpack-plugin": "^5.5.0",
81
81
  "husky": "7.0.1",
82
82
  "imports-loader": "^3.0.0",
83
83
  "inquirer": "^8.2.0",
@@ -92,14 +92,13 @@
92
92
  "koa-static": "^5.0.0",
93
93
  "koa-unless": "^1.0.7",
94
94
  "koa2-connect-history-api-fallback": "^0.1.2",
95
- "lit": "^2.2.0",
95
+ "lit": "^2.2.1",
96
96
  "loader-utils": "^2.0.0",
97
97
  "lodash": "^4.17.15",
98
98
  "lodash-es": "^4.17.15",
99
99
  "mkdirp": "^1.0.3",
100
100
  "mqtt": "^4.3.4",
101
101
  "node-fetch": "^2.6.0",
102
- "node-sass": "^6.0.1",
103
102
  "nodemon": "^2.0.2",
104
103
  "npm-license-crawler": "^0.2.1",
105
104
  "pluralize": "^8.0.0",
@@ -109,6 +108,7 @@
109
108
  "redux-thunk": "^2.3.0",
110
109
  "regenerator-runtime": "^0.13.2",
111
110
  "reselect": "^4.0.0",
111
+ "sass": "^1.50.1",
112
112
  "scrollbooster": "^3.0.2",
113
113
  "subscriptions-transport-ws": "^0.11.0",
114
114
  "sweetalert2": "^10.9.0",
@@ -129,5 +129,5 @@
129
129
  "resolutions": {
130
130
  "core-js": "^3.16.0"
131
131
  },
132
- "gitHead": "379449b7be7b3d8220f1cac9ab684b812117edfd"
132
+ "gitHead": "ba819c6d9ddf60319283f620b80c9737e7486a91"
133
133
  }
@@ -1,4 +1,5 @@
1
1
  import { config, logger } from '@things-factory/env'
2
+
2
3
  import { domainMiddleware } from './domain-middleware'
3
4
 
4
5
  const debug = require('debug')('things-factory:shell:middleware')
@@ -18,8 +19,8 @@ export function initMiddlewares(app) {
18
19
  try {
19
20
  await next()
20
21
  } catch (err) {
21
- context.status = err.status || 500
22
- context.body = err.message
22
+ context.status = err?.status || 500
23
+ context.body = err?.message
23
24
 
24
25
  // emitting error to app.on('error', ...)
25
26
  context.app.emit('error', err, context)
package/server/pubsub.ts CHANGED
@@ -4,7 +4,7 @@ import { PubSub } from 'graphql-subscriptions'
4
4
  import Redis from 'ioredis'
5
5
  import { connect } from 'mqtt'
6
6
 
7
- import { config } from '@things-factory/env'
7
+ import { config, logger } from '@things-factory/env'
8
8
 
9
9
  const { middleware, host, port, nodes, topic, options } = config.get('pubsub', {})
10
10
 
@@ -56,7 +56,7 @@ switch (middleware) {
56
56
  ...options
57
57
  })
58
58
  } catch (e) {
59
- console.error('graphql-kafka-subscriptions module is not installed, so application can not go further.')
59
+ logger.error('graphql-kafka-subscriptions module is not installed, so application can not go further.')
60
60
  throw e
61
61
  }
62
62
  break
@@ -73,7 +73,7 @@ const exitHandler = async evt => {
73
73
  try {
74
74
  await pubsub.close()
75
75
  } catch (err) {
76
- console.error(err)
76
+ logger.error(err)
77
77
  }
78
78
  }
79
79
  }
@@ -1,33 +1,36 @@
1
+ /* following lines should be located in top of the file */
1
2
  // @prettier-ignore
2
3
  process.env.NODE_ENV = 'development'
3
4
  process.setMaxListeners(0)
4
- /** Never move following lines */
5
5
 
6
- import { ConnectionContext, SubscriptionServer } from 'subscriptions-transport-ws'
7
- import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
8
- import { domainPrivateRouter, domainPublicRouter, globalPrivateRouter, globalPublicRouter } from './routers'
9
- import { execute, subscribe } from 'graphql'
10
-
11
- import { ApolloServer } from 'apollo-server-koa'
6
+ /* following lines should be located in top of the file */
12
7
  import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core'
13
- import { GraphqlLocalClient } from './graphql-local-client'
14
- import Koa from 'koa'
8
+ import { ApolloServer } from 'apollo-server-koa'
9
+ import bytesFormat from 'bytes'
15
10
  import co from 'co'
16
- import compose from 'koa-compose'
17
- import cors from '@koa/cors'
18
- import { createServer } from 'http'
19
- import { databaseInitializer } from './initializers/database'
11
+ import { execute, subscribe } from 'graphql'
20
12
  import { graphqlUploadKoa } from 'graphql-upload'
21
- import { historyApiFallback } from 'koa2-connect-history-api-fallback'
22
- import ip from 'koa-ip'
13
+ import { createServer } from 'http'
14
+ import Koa from 'koa'
23
15
  import koaBodyParser from 'koa-bodyparser'
16
+ import compose from 'koa-compose'
17
+ import ip from 'koa-ip'
24
18
  import koaStatic from 'koa-static'
19
+ import { historyApiFallback } from 'koa2-connect-history-api-fallback'
20
+ /** Never move following lines */
21
+ import { ConnectionContext, SubscriptionServer } from 'subscriptions-transport-ws'
22
+
25
23
  import koaWebpack from '@hatiolab/koa-webpack'
24
+ import cors from '@koa/cors'
25
+ import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
26
+
27
+ import { GraphqlLocalClient } from './graphql-local-client'
28
+ import { databaseInitializer } from './initializers/database'
29
+ import { domainPrivateRouter, domainPublicRouter, globalPrivateRouter, globalPublicRouter } from './routers'
26
30
  import { schema } from './schema'
27
- import bytesFormat from 'bytes'
28
31
 
29
32
  process.on('uncaughtException', error => {
30
- console.error(error)
33
+ logger.error(error)
31
34
 
32
35
  process.exit(1)
33
36
  })
package/server/server.ts CHANGED
@@ -1,29 +1,31 @@
1
+ // @prettier-ignore
1
2
  process.env.NODE_ENV = 'production'
2
3
  process.setMaxListeners(0)
3
4
 
4
- import { ConnectionContext, SubscriptionServer } from 'subscriptions-transport-ws'
5
- import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
6
- import { domainPrivateRouter, domainPublicRouter, globalPrivateRouter, globalPublicRouter } from './routers'
7
- import { execute, subscribe } from 'graphql'
8
-
9
5
  import { ApolloServer } from 'apollo-server-koa'
10
- import { GraphqlLocalClient } from './graphql-local-client'
11
- import Koa from 'koa'
6
+ import bytesFormat from 'bytes'
12
7
  import co from 'co'
13
- import compose from 'koa-compose'
14
- import cors from '@koa/cors'
15
- import { createServer } from 'http'
16
- import { databaseInitializer } from './initializers/database'
8
+ import { execute, subscribe } from 'graphql'
17
9
  import { graphqlUploadKoa } from 'graphql-upload'
18
- import { historyApiFallback } from 'koa2-connect-history-api-fallback'
19
- import ip from 'koa-ip'
10
+ import { createServer } from 'http'
11
+ import Koa from 'koa'
20
12
  import koaBodyParser from 'koa-bodyparser'
13
+ import compose from 'koa-compose'
14
+ import ip from 'koa-ip'
21
15
  import koaStatic from 'koa-static'
16
+ import { historyApiFallback } from 'koa2-connect-history-api-fallback'
17
+ import { ConnectionContext, SubscriptionServer } from 'subscriptions-transport-ws'
18
+
19
+ import cors from '@koa/cors'
20
+ import { config, loader, logger, orderedModuleNames } from '@things-factory/env'
21
+
22
+ import { GraphqlLocalClient } from './graphql-local-client'
23
+ import { databaseInitializer } from './initializers/database'
24
+ import { domainPrivateRouter, domainPublicRouter, globalPrivateRouter, globalPublicRouter } from './routers'
22
25
  import { schema } from './schema'
23
- import bytesFormat from 'bytes'
24
26
 
25
27
  process.on('uncaughtException', error => {
26
- console.error(error)
28
+ logger.error(error)
27
29
 
28
30
  process.exit(1)
29
31
  })
@@ -1,12 +1,47 @@
1
- import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
1
+ import { Column, CreateDateColumn, Entity, Index, UpdateDateColumn } from 'typeorm'
2
2
  import { ObjectType, Field, ID } from 'type-graphql'
3
+ import { config } from '@things-factory/env'
4
+
5
+ const numericTypes = ["int","int2","int4","int8","integer","tinyint","smallint","mediumint","bigint"]
6
+ const generatedStrategy = ['uuid','rowid',"increment","identity"]
7
+ const domainPrimaryOption =config.get('domainPrimaryOption')
8
+ const domainPrimaryType = domainPrimaryOption?.type
9
+ const domainPrimaryStrategy = domainPrimaryOption?.strategy
3
10
 
4
11
  @Entity()
5
12
  @Index('ix_domain_0', (domain: Domain) => [domain.subdomain], { unique: true })
6
13
  @ObjectType()
7
14
  export class Domain {
8
15
  @Field(type => ID)
9
- @PrimaryGeneratedColumn('uuid')
16
+ @Column(
17
+ domainPrimaryOption?
18
+ {
19
+ type: domainPrimaryType,
20
+ primary:true,
21
+ transformer: {
22
+ //from(value: DatabaseType): EntityType
23
+ from: (value) => {
24
+ return value
25
+ },
26
+ //to(value: EntityType): DatabaseType
27
+ to: (value) => {
28
+ if(!value){
29
+ value = 0
30
+ }
31
+ if(numericTypes.indexOf(domainPrimaryType)>=0){
32
+ return parseInt(value)
33
+ }else{
34
+ return value
35
+ }
36
+ }
37
+ },
38
+ generated:generatedStrategy.indexOf(domainPrimaryStrategy)>=0?domainPrimaryStrategy:false
39
+ }:{
40
+ type: 'uuid',
41
+ primary:true,
42
+ generated:'uuid'
43
+ }
44
+ )
10
45
  readonly id: string
11
46
 
12
47
  @Field()
@@ -5,12 +5,13 @@ export const buildCondition = function (
5
5
  fieldName: string,
6
6
  operator: string,
7
7
  value: any,
8
- relation: boolean,
8
+ relation: boolean | string,
9
9
  seq: number
10
10
  ) {
11
11
  seq++
12
12
 
13
13
  fieldName = _.snakeCase(fieldName)
14
+ const values = value instanceof Array ? value : [value]
14
15
 
15
16
  switch (operator) {
16
17
  case 'eq':
@@ -75,24 +76,23 @@ export const buildCondition = function (
75
76
  }
76
77
 
77
78
  case 'in':
78
- const clause = relation ? `${fieldName}.id IN (:...args${seq})` : `${alias}.${fieldName} IN (:...args${seq})`
79
- value = value?.length ? value : [value]
80
79
  return {
81
- clause,
82
- parameters: { [`args${seq}`]: value }
80
+ clause: relation ? `${fieldName}.id IN (:...args${seq})` : `${alias}.${fieldName} IN (:...args${seq})`,
81
+ parameters: { [`args${seq}`]: values }
83
82
  }
83
+
84
84
  case 'notin':
85
- value = value?.length ? value : [value]
86
85
  return {
87
- clause: `${alias}.${fieldName} NOT IN (:...args${seq})`,
88
- parameters: { [`args${seq}`]: value }
86
+ clause: relation ? `${fieldName}.id NOT IN (:...args${seq})` : `${alias}.${fieldName} NOT IN (:...args${seq})`,
87
+ parameters: { [`args${seq}`]: values }
89
88
  }
90
89
 
91
90
  case 'notin_with_null':
92
- value = value?.length ? value : [value]
93
91
  return {
94
- clause: `(${alias}.${fieldName} IS NULL OR ${alias}.${fieldName} NOT IN (:...args${seq}))`,
95
- parameters: { [`args${seq}`]: value }
92
+ clause: relation
93
+ ? `(${fieldName}.id IS NULL OR ${fieldName}.id NOT IN (:...args${seq})`
94
+ : `${alias}.${fieldName} IS NULL OR ${alias}.${fieldName} NOT IN (:...args${seq}))`,
95
+ parameters: { [`args${seq}`]: values }
96
96
  }
97
97
 
98
98
  case 'is_null':
@@ -135,7 +135,7 @@ export const buildCondition = function (
135
135
  case 'between':
136
136
  return {
137
137
  clause: `${alias}.${fieldName} BETWEEN :args${seq}_1 AND :args${seq}_2`,
138
- parameters: { [`args${seq}_1`]: value[0], [`args${seq}_2`]: value[1] }
138
+ parameters: { [`args${seq}_1`]: values[0], [`args${seq}_2`]: values[1] }
139
139
  }
140
140
  }
141
141
  }
@@ -1,8 +1,8 @@
1
- import { Between, Equal, ILike, In, IsNull, Like, Not, Raw } from 'typeorm'
1
+ import { Between, Equal, FindOperator, ILike, In, IsNull, Like, Not, Raw } from 'typeorm'
2
2
 
3
- import { ListParam } from '../service/common-types'
3
+ import { Filter, ListParam, Pagination, Sorting } from '../service/common-types'
4
4
 
5
- const OPERATION_FUNCTION_MAP = {
5
+ const OPERATION_FUNCTION_MAP: { [operator: string]: (value: any) => FindOperator<any> } = {
6
6
  search: value => ILike(value),
7
7
  eq: value => Equal(value),
8
8
  noteq: value => Not(Equal(value)),
@@ -27,12 +27,12 @@ const OPERATION_FUNCTION_MAP = {
27
27
  between: value => Between(value[0], value[1])
28
28
  }
29
29
 
30
- function getOperatorFunction({ operator, name, value, dataType }) {
30
+ function getOperatorFunction({ operator, value }: { operator: string; value: any }): FindOperator<any> {
31
31
  return OPERATION_FUNCTION_MAP[operator](value)
32
32
  }
33
33
 
34
- function makePaginationParams(pagination) {
35
- var jsonParams = {}
34
+ function makePaginationParams(pagination: Pagination): { skip?: number; take?: number } {
35
+ var result = {} as { skip?: number; take?: number }
36
36
  if (pagination) {
37
37
  var { page = 0, limit = 0 } = pagination
38
38
  var skip = 0
@@ -41,39 +41,41 @@ function makePaginationParams(pagination) {
41
41
  if (limit > 0) {
42
42
  skip = Math.max(page - 1, 0) * limit
43
43
  take = limit
44
- Object.assign(jsonParams, {
44
+ Object.assign(result, {
45
45
  skip,
46
46
  take
47
47
  })
48
48
  }
49
49
  }
50
50
 
51
- return jsonParams
51
+ return result
52
52
  }
53
53
 
54
- function makeSortingParams(sortings) {
55
- var jsonParams = {}
54
+ function makeSortingParams(sortings: Sorting[]): { order?: { [name: string]: 'DESC' | 'ASC' } } {
55
+ var result = {} as { order?: { [name: string]: 'DESC' | 'ASC' } }
56
56
  if (sortings) {
57
- var order = {}
57
+ var order = {} as { [name: string]: 'DESC' | 'ASC' }
58
58
  sortings.forEach(s => {
59
59
  order[s.name] = s.desc ? 'DESC' : 'ASC'
60
60
  })
61
61
 
62
- Object.assign(jsonParams, {
62
+ Object.assign(result, {
63
63
  order
64
64
  })
65
65
  }
66
66
 
67
- return jsonParams
67
+ return result
68
68
  }
69
69
 
70
- function makeFilterParams(filters) {
70
+ function makeFilterParams(filters: Filter[]): {
71
+ where: { [name: string]: FindOperator<any> } | { [name: string]: FindOperator<any> }[]
72
+ } {
71
73
  /* for where AND clauses */
72
74
  const columnFilters = filters.filter(filter => filter.operator !== 'search')
73
75
  const columnWhere = columnFilters.reduce((where, f) => {
74
76
  where[f.name] = getOperatorFunction(f)
75
77
  return where
76
- }, {})
78
+ }, {} as { [name: string]: FindOperator<any> })
77
79
 
78
80
  const searchFilters = filters.filter(filter => filter.operator === 'search')
79
81
  if (searchFilters.length === 0) {
@@ -95,9 +97,19 @@ function makeFilterParams(filters) {
95
97
  }
96
98
  }
97
99
 
98
- export function convertListParams(params: typeof ListParam, domain?: String) {
99
- var { pagination, filters = [], sortings } = params as any
100
- var jsonParams = {}
100
+ export function convertListParams(
101
+ params: ListParam,
102
+ domain?: String
103
+ ): {
104
+ where?: { [name: string]: FindOperator<any> }
105
+ order?: {
106
+ [name: string]: 'DESC' | 'ASC'
107
+ }
108
+ skip?: number
109
+ take?: number
110
+ } {
111
+ var { pagination, filters = [], sortings } = params
112
+ var result = {}
101
113
 
102
114
  if (domain) {
103
115
  filters.push({
@@ -107,9 +119,9 @@ export function convertListParams(params: typeof ListParam, domain?: String) {
107
119
  })
108
120
  }
109
121
 
110
- if (pagination) Object.assign(jsonParams, makePaginationParams(pagination))
111
- if (sortings) Object.assign(jsonParams, makeSortingParams(sortings))
112
- if (filters) Object.assign(jsonParams, makeFilterParams(filters))
122
+ if (pagination) Object.assign(result, makePaginationParams(pagination))
123
+ if (sortings) Object.assign(result, makeSortingParams(sortings))
124
+ if (filters) Object.assign(result, makeFilterParams(filters))
113
125
 
114
- return jsonParams
126
+ return result
115
127
  }