@things-factory/shell 5.0.0-alpha.5 → 5.0.0-alpha.52
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/client/themes/tooltip-theme.css +4 -3
- package/config/config.production.js +13 -0
- package/dist-server/middlewares/index.js +2 -2
- package/dist-server/middlewares/index.js.map +1 -1
- package/dist-server/pubsub.js +2 -2
- package/dist-server/pubsub.js.map +1 -1
- package/dist-server/server-dev.js +18 -16
- package/dist-server/server-dev.js.map +1 -1
- package/dist-server/server.js +15 -14
- package/dist-server/server.js.map +1 -1
- package/dist-server/service/domain/domain-resolver.js +4 -1
- package/dist-server/service/domain/domain-resolver.js.map +1 -1
- package/dist-server/service/domain/domain.js +34 -1
- package/dist-server/service/domain/domain.js.map +1 -1
- package/dist-server/utils/condition-builder.js +10 -11
- package/dist-server/utils/condition-builder.js.map +1 -1
- package/dist-server/utils/list-params-converter.js +29 -17
- package/dist-server/utils/list-params-converter.js.map +1 -1
- package/dist-server/utils/list-query-builder.js +92 -3
- package/dist-server/utils/list-query-builder.js.map +1 -1
- package/dist-server/utils/where-clause-builder.js +159 -0
- package/dist-server/utils/where-clause-builder.js.map +1 -0
- package/package.json +26 -25
- package/server/middlewares/index.ts +3 -2
- package/server/pubsub.ts +3 -3
- package/server/server-dev.ts +20 -17
- package/server/server.ts +17 -15
- package/server/service/domain/domain-resolver.ts +5 -1
- package/server/service/domain/domain.ts +37 -2
- package/server/utils/condition-builder.ts +12 -12
- package/server/utils/list-params-converter.ts +61 -25
- package/server/utils/list-query-builder.ts +123 -3
- package/server/utils/where-clause-builder.ts +200 -0
@@ -1,12 +1,24 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.buildQuery = void 0;
|
3
|
+
exports.getQueryBuilderFromListParams = exports.buildQuery = void 0;
|
4
4
|
const typeorm_1 = require("typeorm");
|
5
5
|
const condition_builder_1 = require("./condition-builder");
|
6
|
-
const
|
6
|
+
const where_clause_builder_1 = require("./where-clause-builder");
|
7
|
+
/**
|
8
|
+
* @deprecated The name of this function does not imply an exact purpose and it is not possible to correspond to a foreign key using the meta information of the table column, so it is recommended to replace it with the A function.
|
9
|
+
*/
|
10
|
+
const buildQuery = function (queryBuilder, params, context, options) {
|
7
11
|
var _a, _b;
|
12
|
+
/* default value of domainRef is 'true' */
|
13
|
+
var domainRef = typeof options === 'boolean' ? options : true;
|
14
|
+
/* for backwards compatibility of function spec */
|
15
|
+
if (typeof options === 'object') {
|
16
|
+
var { domainRef = true, searchables } = options;
|
17
|
+
}
|
8
18
|
const columnFilters = ((_a = params.filters) === null || _a === void 0 ? void 0 : _a.filter(filter => filter.operator !== 'search')) || [];
|
9
|
-
const searchFilters =
|
19
|
+
const searchFilters = searchables instanceof Array
|
20
|
+
? ((_b = params.filters) === null || _b === void 0 ? void 0 : _b.filter(filter => filter.operator === 'search' && searchables.includes(filter.name))) || []
|
21
|
+
: [];
|
10
22
|
const pagination = params.pagination;
|
11
23
|
const sortings = params.sortings;
|
12
24
|
const domainId = context && context.state.domain && context.state.domain.id;
|
@@ -48,4 +60,81 @@ const buildQuery = function (queryBuilder, params, context, domainRef = true) {
|
|
48
60
|
}
|
49
61
|
};
|
50
62
|
exports.buildQuery = buildQuery;
|
63
|
+
function getQueryBuilderFromListParams(options) {
|
64
|
+
var _a, _b;
|
65
|
+
var { repository, params, domain, alias, searchables } = options;
|
66
|
+
const selectQueryBuilder = repository.createQueryBuilder(alias);
|
67
|
+
alias = selectQueryBuilder.alias;
|
68
|
+
const columnFilters = ((_a = params.filters) === null || _a === void 0 ? void 0 : _a.filter(filter => filter.operator !== 'search')) || [];
|
69
|
+
const searchFilters = searchables instanceof Array
|
70
|
+
? ((_b = params.filters) === null || _b === void 0 ? void 0 : _b.filter(filter => filter.operator === 'search' && searchables.includes(filter.name))) || []
|
71
|
+
: [];
|
72
|
+
const pagination = params.pagination;
|
73
|
+
const sortings = params.sortings;
|
74
|
+
const metadata = repository.metadata;
|
75
|
+
const columnMetas = params.filters
|
76
|
+
.map(filter => filter.name)
|
77
|
+
.reduce((sum, name) => {
|
78
|
+
sum[name] = metadata.columns.find(column => column.propertyName === name);
|
79
|
+
return sum;
|
80
|
+
}, {});
|
81
|
+
if (columnFilters && columnFilters.length > 0) {
|
82
|
+
columnFilters.forEach(filter => {
|
83
|
+
const { name, operator, value } = filter;
|
84
|
+
const condition = (0, where_clause_builder_1.buildWhereClause)({
|
85
|
+
alias,
|
86
|
+
columnMeta: columnMetas[name],
|
87
|
+
operator,
|
88
|
+
value,
|
89
|
+
seq: Object.keys(selectQueryBuilder.getParameters()).length + 1,
|
90
|
+
domain,
|
91
|
+
selectQueryBuilder
|
92
|
+
});
|
93
|
+
if (condition === null || condition === void 0 ? void 0 : condition.clause)
|
94
|
+
selectQueryBuilder.andWhere(condition.clause);
|
95
|
+
if (condition === null || condition === void 0 ? void 0 : condition.parameters)
|
96
|
+
selectQueryBuilder.setParameters(condition.parameters);
|
97
|
+
});
|
98
|
+
}
|
99
|
+
if (searchFilters.length > 0) {
|
100
|
+
selectQueryBuilder.andWhere(new typeorm_1.Brackets(qb => {
|
101
|
+
searchFilters.forEach(filter => {
|
102
|
+
const { name, operator, value } = filter;
|
103
|
+
const condition = (0, where_clause_builder_1.buildWhereClause)({
|
104
|
+
alias,
|
105
|
+
columnMeta: columnMetas[name],
|
106
|
+
operator /* has to be 'search' */,
|
107
|
+
value,
|
108
|
+
seq: Object.keys(selectQueryBuilder.getParameters()).length + 1,
|
109
|
+
domain,
|
110
|
+
selectQueryBuilder
|
111
|
+
});
|
112
|
+
if (condition === null || condition === void 0 ? void 0 : condition.clause)
|
113
|
+
qb.orWhere(condition.clause);
|
114
|
+
if (condition === null || condition === void 0 ? void 0 : condition.parameters)
|
115
|
+
selectQueryBuilder.setParameters(condition.parameters);
|
116
|
+
});
|
117
|
+
}));
|
118
|
+
}
|
119
|
+
if (domain) {
|
120
|
+
selectQueryBuilder.andWhere(`${selectQueryBuilder.alias}.domain = :domain`, { domain: domain.id });
|
121
|
+
}
|
122
|
+
if (pagination && pagination.page > 0 && pagination.limit > 0) {
|
123
|
+
selectQueryBuilder.skip(pagination.limit * (pagination.page - 1));
|
124
|
+
selectQueryBuilder.take(pagination.limit);
|
125
|
+
}
|
126
|
+
if (sortings && sortings.length > 0) {
|
127
|
+
sortings.forEach((sorting, index) => {
|
128
|
+
const sortField = sorting.name.split('.').length > 1 ? sorting.name : `${selectQueryBuilder.alias}.${sorting.name}`;
|
129
|
+
if (index === 0) {
|
130
|
+
selectQueryBuilder.orderBy(sortField, sorting.desc ? 'DESC' : 'ASC');
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
selectQueryBuilder.addOrderBy(sortField, sorting.desc ? 'DESC' : 'ASC');
|
134
|
+
}
|
135
|
+
});
|
136
|
+
}
|
137
|
+
return selectQueryBuilder;
|
138
|
+
}
|
139
|
+
exports.getQueryBuilderFromListParams = getQueryBuilderFromListParams;
|
51
140
|
//# sourceMappingURL=list-query-builder.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"list-query-builder.js","sourceRoot":"","sources":["../../server/utils/list-query-builder.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"list-query-builder.js","sourceRoot":"","sources":["../../server/utils/list-query-builder.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAIlE,2DAAoD;AACpD,iEAAyD;AAEzD;;GAEG;AACI,MAAM,UAAU,GAAG,UACxB,YAAiB,EACjB,MAAW,EACX,OAAY,EACZ,OAKK;;IAEL,0CAA0C;IAC1C,IAAI,SAAS,GAAG,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;IAE7D,kDAAkD;IAClD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,IAAI,EAAE,SAAS,GAAG,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;KAChD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AA;KAC1C;IAED,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;YAClC,MAAM,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAA;YACnG,IAAI,KAAK,KAAK,CAAC,EAAE;gBACf,kBAAkB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;aACrE;iBAAM;gBACL,kBAAkB,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;aACxE;QACH,CAAC,CAAC,CAAA;KACH;IAED,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AA3FD,sEA2FC"}
|
@@ -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,OAA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AE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE;aACzE,CAAA;KACJ;AACH,CAAC,CAAA;AA1IY,QAAA,gBAAgB,oBA0I5B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/shell",
|
3
|
-
"version": "5.0.0-alpha.
|
3
|
+
"version": "5.0.0-alpha.52",
|
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.
|
35
|
-
"@graphql-tools/merge": "^
|
36
|
-
"@graphql-tools/schema": "^8.2
|
37
|
-
"@graphql-tools/utils": "^8.
|
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": "^
|
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-
|
48
|
-
"@operato/graphql": "1.0.0-
|
49
|
-
"@operato/help": "1.0.0-
|
50
|
-
"@operato/layout": "1.0.0-
|
51
|
-
"@operato/shell": "1.0.0-
|
52
|
-
"@operato/utils": "1.0.0-
|
53
|
-
"@things-factory/ejs-remote": "^5.0.0-alpha.
|
54
|
-
"@things-factory/env": "^5.0.0-alpha.
|
55
|
-
"@things-factory/styles": "^5.0.0-alpha.
|
56
|
-
"@things-factory/utils": "^5.0.0-alpha.
|
47
|
+
"@operato/board": "1.0.0-beta.26",
|
48
|
+
"@operato/graphql": "1.0.0-beta.26",
|
49
|
+
"@operato/help": "1.0.0-beta.26",
|
50
|
+
"@operato/layout": "1.0.0-beta.26",
|
51
|
+
"@operato/shell": "1.0.0-beta.26",
|
52
|
+
"@operato/utils": "1.0.0-beta.26",
|
53
|
+
"@things-factory/ejs-remote": "^5.0.0-alpha.52",
|
54
|
+
"@things-factory/env": "^5.0.0-alpha.52",
|
55
|
+
"@things-factory/styles": "^5.0.0-alpha.52",
|
56
|
+
"@things-factory/utils": "^5.0.0-alpha.52",
|
57
57
|
"@webcomponents/webcomponentsjs": "^2.6.0",
|
58
58
|
"@webpack-contrib/schema-utils": "^1.0.0-beta.0",
|
59
|
-
"apollo-server-core": "^3.
|
60
|
-
"apollo-server-koa": "^3.
|
61
|
-
"apollo-server-types": "^3.
|
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.
|
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": "^
|
78
|
+
"graphql-upload": "^13.0.0",
|
79
79
|
"haunted": "^4.8.2",
|
80
|
-
"html-webpack-plugin": "^
|
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.
|
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,11 +108,13 @@
|
|
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",
|
115
115
|
"type-graphql": "^1.2.0-rc.1",
|
116
116
|
"typeorm": "^0.2.41",
|
117
|
+
"uuid": "^3.4.0",
|
117
118
|
"web-animations-js": "^2.3.2",
|
118
119
|
"web-push": "^3.4.5",
|
119
120
|
"webfontloader": "^1.6.28"
|
@@ -129,5 +130,5 @@
|
|
129
130
|
"resolutions": {
|
130
131
|
"core-js": "^3.16.0"
|
131
132
|
},
|
132
|
-
"gitHead": "
|
133
|
+
"gitHead": "dd9c8f2e256e256e42bd9bd26db5eaa955f85620"
|
133
134
|
}
|
@@ -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
|
22
|
-
context.body = err
|
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
|
-
|
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
|
-
|
76
|
+
logger.error(err)
|
77
77
|
}
|
78
78
|
}
|
79
79
|
}
|
package/server/server-dev.ts
CHANGED
@@ -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
|
-
|
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 {
|
14
|
-
import
|
8
|
+
import { ApolloServer } from 'apollo-server-koa'
|
9
|
+
import bytesFormat from 'bytes'
|
15
10
|
import co from 'co'
|
16
|
-
import
|
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 {
|
22
|
-
import
|
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
|
-
|
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
|
11
|
-
import Koa from 'koa'
|
6
|
+
import bytesFormat from 'bytes'
|
12
7
|
import co from 'co'
|
13
|
-
import
|
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 {
|
19
|
-
import
|
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
|
-
|
28
|
+
logger.error(error)
|
27
29
|
|
28
30
|
process.exit(1)
|
29
31
|
})
|
@@ -22,7 +22,11 @@ export class DomainResolver {
|
|
22
22
|
@Query(returns => DomainList, { description: 'To fetch multiple domain' })
|
23
23
|
async domains(@Args() params: ListParam, @Ctx() context): Promise<DomainList> {
|
24
24
|
const queryBuilder = getRepository(Domain).createQueryBuilder()
|
25
|
-
|
25
|
+
|
26
|
+
buildQuery(queryBuilder, params || {}, context, {
|
27
|
+
domainRef: false,
|
28
|
+
searchables: ['name', 'description', 'subdomain']
|
29
|
+
})
|
26
30
|
const [items, total] = await queryBuilder.getManyAndCount()
|
27
31
|
|
28
32
|
return { items, total }
|
@@ -1,12 +1,47 @@
|
|
1
|
-
import { Column, CreateDateColumn, Entity, Index,
|
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
|
-
@
|
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()
|