@joktec/mysql 0.0.176 → 0.0.177
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/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +18 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/table.decorator.d.ts +20 -0
- package/dist/decorators/table.decorator.d.ts.map +1 -0
- package/dist/decorators/table.decorator.js +31 -0
- package/dist/decorators/table.decorator.js.map +1 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/mysql.finder.d.ts +11 -0
- package/dist/helpers/mysql.finder.d.ts.map +1 -0
- package/dist/helpers/mysql.finder.js +105 -0
- package/dist/helpers/mysql.finder.js.map +1 -0
- package/dist/helpers/mysql.helper.d.ts +7 -8
- package/dist/helpers/mysql.helper.d.ts.map +1 -1
- package/dist/helpers/mysql.helper.js +68 -56
- package/dist/helpers/mysql.helper.js.map +1 -1
- package/dist/helpers/mysql.utils.d.ts +4 -0
- package/dist/helpers/mysql.utils.d.ts.map +1 -0
- package/dist/helpers/mysql.utils.js +25 -0
- package/dist/helpers/mysql.utils.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mysql.benchmark.d.ts +15 -0
- package/dist/mysql.benchmark.d.ts.map +1 -0
- package/dist/mysql.benchmark.js +72 -0
- package/dist/mysql.benchmark.js.map +1 -0
- package/dist/mysql.config.d.ts +16 -1
- package/dist/mysql.config.d.ts.map +1 -1
- package/dist/mysql.config.js +44 -7
- package/dist/mysql.config.js.map +1 -1
- package/dist/mysql.exception.d.ts +1 -1
- package/dist/mysql.exception.d.ts.map +1 -1
- package/dist/mysql.exception.js.map +1 -1
- package/dist/mysql.repo.d.ts +3 -1
- package/dist/mysql.repo.d.ts.map +1 -1
- package/dist/mysql.repo.js +38 -7
- package/dist/mysql.repo.js.map +1 -1
- package/dist/mysql.service.d.ts.map +1 -1
- package/dist/mysql.service.js +4 -2
- package/dist/mysql.service.js.map +1 -1
- package/dist/mysql.strategy.d.ts +15 -0
- package/dist/mysql.strategy.d.ts.map +1 -0
- package/dist/mysql.strategy.js +49 -0
- package/dist/mysql.strategy.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./table.decorator"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { KeyOf } from '@joktec/core';
|
|
2
|
+
import { EntityOptions, IndexOptions } from 'typeorm';
|
|
3
|
+
import { MysqlModel } from '../models';
|
|
4
|
+
type KeyTypeOf<T, TYPE> = {
|
|
5
|
+
[K in keyof T]: T[K] extends TYPE | undefined ? K : never;
|
|
6
|
+
}[keyof T];
|
|
7
|
+
export interface IIndexOptions<T extends MysqlModel = any> extends IndexOptions {
|
|
8
|
+
name?: string;
|
|
9
|
+
fields: KeyOf<T>[];
|
|
10
|
+
}
|
|
11
|
+
export interface ITableOptions<T extends MysqlModel = any> extends EntityOptions {
|
|
12
|
+
keywords?: KeyTypeOf<T, string>[];
|
|
13
|
+
index?: KeyOf<T>[];
|
|
14
|
+
unique?: KeyOf<T>[];
|
|
15
|
+
textSearch?: KeyTypeOf<T, string>[];
|
|
16
|
+
customIndexes?: IIndexOptions<T>[];
|
|
17
|
+
}
|
|
18
|
+
export declare const Tables: <T extends MysqlModel = any>(options?: ITableOptions<T>) => ClassDecorator;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=table.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/table.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,EAAe,MAAM,cAAc,CAAC;AACnE,OAAO,EAAU,aAAa,EAAS,YAAY,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,KAAK,SAAS,CAAC,CAAC,EAAE,IAAI,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAEjG,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,UAAU,GAAG,GAAG,CAAE,SAAQ,YAAY;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,UAAU,GAAG,GAAG,CAAE,SAAQ,aAAa;IAC9E,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;IAElC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;CACpC;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,UAAU,kBAAiB,aAAa,CAAC,CAAC,CAAC,KAAQ,cA2BnF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tables = void 0;
|
|
4
|
+
const core_1 = require("@joktec/core");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const Tables = (options = {}) => {
|
|
7
|
+
return (target) => {
|
|
8
|
+
const className = target.name;
|
|
9
|
+
const decorators = [(0, core_1.SetMetadata)(className, options), (0, typeorm_1.Entity)(options)];
|
|
10
|
+
if (options.index?.length) {
|
|
11
|
+
options.index.map(indexOpts => decorators.push((0, typeorm_1.Index)(indexOpts)));
|
|
12
|
+
}
|
|
13
|
+
if (options.unique?.length) {
|
|
14
|
+
options.unique.map(uniqueOpts => decorators.push((0, typeorm_1.Index)(uniqueOpts, { unique: true })));
|
|
15
|
+
}
|
|
16
|
+
if (options.textSearch?.length) {
|
|
17
|
+
decorators.push((0, typeorm_1.Index)(options.textSearch.map(String), { fulltext: true }));
|
|
18
|
+
}
|
|
19
|
+
if (options.customIndexes?.length) {
|
|
20
|
+
options.customIndexes.map((idxOpts) => {
|
|
21
|
+
if (idxOpts.name)
|
|
22
|
+
decorators.push((0, typeorm_1.Index)(idxOpts.name, idxOpts.fields, idxOpts));
|
|
23
|
+
else
|
|
24
|
+
decorators.push((0, typeorm_1.Index)(idxOpts.fields, idxOpts));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
(0, core_1.applyDecorators)(...decorators)(target);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.Tables = Tables;
|
|
31
|
+
//# sourceMappingURL=table.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.decorator.js","sourceRoot":"","sources":["../../src/decorators/table.decorator.ts"],"names":[],"mappings":";;;AAAA,uCAAmE;AACnE,qCAAqE;AAmB9D,MAAM,MAAM,GAAG,CAA6B,UAA4B,EAAE,EAAkB,EAAE;IACnG,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;QAE9B,MAAM,UAAU,GAAqB,CAAC,IAAA,kBAAW,EAAwB,SAAS,EAAE,OAAO,CAAC,EAAE,IAAA,gBAAM,EAAC,OAAO,CAAC,CAAC,CAAC;QAE/G,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;YAC1B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAA,eAAK,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;YAC3B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAA,eAAK,EAAC,UAAU,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACzF,CAAC;QAED,IAAI,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;YAC/B,UAAU,CAAC,IAAI,CAAC,IAAA,eAAK,EAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7E,CAAC;QAED,IAAI,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;YAClC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,OAAsB,EAAE,EAAE;gBACnD,IAAI,OAAO,CAAC,IAAI;oBAAE,UAAU,CAAC,IAAI,CAAC,IAAA,eAAK,EAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;;oBAC3E,UAAU,CAAC,IAAI,CAAC,IAAA,eAAK,EAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YACvD,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAA,sBAAe,EAAC,GAAG,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC,CAAC;AACJ,CAAC,CAAC;AA3BW,QAAA,MAAM,UA2BjB"}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
package/dist/helpers/index.js
CHANGED
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./mysql.finder"), exports);
|
|
17
18
|
__exportStar(require("./mysql.helper"), exports);
|
|
19
|
+
__exportStar(require("./mysql.utils"), exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,iDAA+B;AAC/B,gDAA8B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IBaseRequest, ICondition, IPopulate } from '@joktec/core';
|
|
2
|
+
import { FindManyOptions } from 'typeorm';
|
|
3
|
+
import { MysqlModel } from '../models';
|
|
4
|
+
export declare class MysqlFinder {
|
|
5
|
+
static parseFilter<T>(query: IBaseRequest<T>): FindManyOptions<T>;
|
|
6
|
+
static parseProjection<T extends MysqlModel>(select: string | string[] | Record<string, number | boolean>): FindManyOptions<T>['select'];
|
|
7
|
+
static parseCondition<T>(condition: ICondition<T>): FindManyOptions<T>['where'];
|
|
8
|
+
static parseOrder<T>(sort: any): FindManyOptions<T>['order'];
|
|
9
|
+
static parseRelations<T>(populate: IPopulate<T>): FindManyOptions<T>['relations'];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=mysql.finder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.finder.d.ts","sourceRoot":"","sources":["../../src/helpers/mysql.finder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAmB,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,eAAe,EAAwE,MAAM,SAAS,CAAC;AAChH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,qBAAa,WAAW;IACtB,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;IASjE,MAAM,CAAC,eAAe,CAAC,CAAC,SAAS,UAAU,EACzC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAC3D,eAAe,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAc/B,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IA2D/E,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAQ5D,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;CAalF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MysqlFinder = void 0;
|
|
4
|
+
const core_1 = require("@joktec/core");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const mysql_exception_1 = require("../mysql.exception");
|
|
7
|
+
class MysqlFinder {
|
|
8
|
+
static parseFilter(query) {
|
|
9
|
+
const { condition = {}, keyword } = query;
|
|
10
|
+
const where = MysqlFinder.parseCondition(condition);
|
|
11
|
+
if (keyword && typeof where === 'object') {
|
|
12
|
+
where['name'] = (0, typeorm_1.ILike)(`%${keyword}%`);
|
|
13
|
+
}
|
|
14
|
+
return { where };
|
|
15
|
+
}
|
|
16
|
+
static parseProjection(select) {
|
|
17
|
+
if (typeof select === 'object') {
|
|
18
|
+
return Object.entries(select).reduce((acc, [field, direction]) => {
|
|
19
|
+
acc[field] = (0, core_1.toBool)(direction);
|
|
20
|
+
return acc;
|
|
21
|
+
}, {});
|
|
22
|
+
}
|
|
23
|
+
return (0, core_1.toArray)(select, { split: ',' }).reduce((acc, field) => {
|
|
24
|
+
acc[field] = true;
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
27
|
+
}
|
|
28
|
+
static parseCondition(condition) {
|
|
29
|
+
const where = {};
|
|
30
|
+
for (const [key, value] of Object.entries(condition)) {
|
|
31
|
+
if (key === '$and' || key === '$or') {
|
|
32
|
+
where[key === '$and' ? 'AND' : 'OR'] = value.map((c) => MysqlFinder.parseCondition(c));
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (value === null || value === undefined) {
|
|
36
|
+
where[key] = (0, typeorm_1.Not)(null);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === 'object') {
|
|
40
|
+
for (const [op, val] of Object.entries(value)) {
|
|
41
|
+
switch (op) {
|
|
42
|
+
case '$eq':
|
|
43
|
+
where[key] = val;
|
|
44
|
+
break;
|
|
45
|
+
case '$gt':
|
|
46
|
+
where[key] = (0, typeorm_1.MoreThan)(val);
|
|
47
|
+
break;
|
|
48
|
+
case '$gte':
|
|
49
|
+
where[key] = (0, typeorm_1.MoreThanOrEqual)(val);
|
|
50
|
+
break;
|
|
51
|
+
case '$lt':
|
|
52
|
+
where[key] = (0, typeorm_1.LessThan)(val);
|
|
53
|
+
break;
|
|
54
|
+
case '$lte':
|
|
55
|
+
where[key] = (0, typeorm_1.LessThanOrEqual)(val);
|
|
56
|
+
break;
|
|
57
|
+
case '$ne':
|
|
58
|
+
where[key] = (0, typeorm_1.Not)(val);
|
|
59
|
+
break;
|
|
60
|
+
case '$in':
|
|
61
|
+
where[key] = (0, typeorm_1.In)((0, core_1.toArray)(val));
|
|
62
|
+
break;
|
|
63
|
+
case '$like':
|
|
64
|
+
where[key] = (0, typeorm_1.ILike)(`%${val}%`);
|
|
65
|
+
break;
|
|
66
|
+
case '$begin':
|
|
67
|
+
where[key] = (0, typeorm_1.ILike)(`${val}%`);
|
|
68
|
+
break;
|
|
69
|
+
case '$end':
|
|
70
|
+
where[key] = (0, typeorm_1.ILike)(`%${val}`);
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
throw new mysql_exception_1.MysqlException(`Operator ${op} not supported`, { op, val });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
where[key] = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return where;
|
|
82
|
+
}
|
|
83
|
+
static parseOrder(sort) {
|
|
84
|
+
const order = {};
|
|
85
|
+
for (const [key, value] of Object.entries(sort)) {
|
|
86
|
+
order[key] = value === 'asc' ? 'ASC' : 'DESC';
|
|
87
|
+
}
|
|
88
|
+
return order;
|
|
89
|
+
}
|
|
90
|
+
static parseRelations(populate) {
|
|
91
|
+
const relations = {};
|
|
92
|
+
for (const [path, value] of Object.entries(populate)) {
|
|
93
|
+
if (value === '*') {
|
|
94
|
+
relations[path] = true;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === 'object') {
|
|
98
|
+
relations[path] = MysqlFinder.parseRelations(value['populate'] || {});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return relations;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.MysqlFinder = MysqlFinder;
|
|
105
|
+
//# sourceMappingURL=mysql.finder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.finder.js","sourceRoot":"","sources":["../../src/helpers/mysql.finder.ts"],"names":[],"mappings":";;;AAAA,uCAAoF;AACp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,CAAC,EAAE,CAAC;YACrD,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;gBAClB,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;gBACvB,SAAS;YACX,CAAC;YACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,SAAS,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA1GD,kCA0GC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { MysqlModel } from '../models';
|
|
1
|
+
import { ICondition, IPopulate, ISort } from '@joktec/core';
|
|
2
|
+
import { SelectQueryBuilder } from 'typeorm';
|
|
4
3
|
export declare class MysqlHelper {
|
|
5
|
-
static
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
9
|
-
static
|
|
4
|
+
static applyCondition<T>(qb: SelectQueryBuilder<T>, condition?: ICondition<T>): void;
|
|
5
|
+
static buildCondition<T>(qb: SelectQueryBuilder<T>, condition: ICondition<T>): SelectQueryBuilder<T>;
|
|
6
|
+
static applyProjection<T>(qb: SelectQueryBuilder<T>, select?: string | string[]): void;
|
|
7
|
+
static applyOrder<T>(qb: SelectQueryBuilder<T>, sort?: ISort<T>): void;
|
|
8
|
+
static applyRelations<T>(qb: SelectQueryBuilder<T>, populate?: IPopulate<T>): void;
|
|
10
9
|
}
|
|
11
10
|
//# sourceMappingURL=mysql.helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/mysql.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mysql.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/mysql.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,WAAW;IACtB,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;IAiB7E,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IAmF5E,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAM/E,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAO/D,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;CAU5E"}
|
|
@@ -1,104 +1,116 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MysqlHelper = void 0;
|
|
4
|
-
const core_1 = require("@joktec/core");
|
|
5
|
-
const typeorm_1 = require("typeorm");
|
|
6
|
-
const mysql_exception_1 = require("../mysql.exception");
|
|
7
4
|
class MysqlHelper {
|
|
8
|
-
static
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
11
|
-
acc[field] = (0, core_1.toBool)(direction);
|
|
12
|
-
return acc;
|
|
13
|
-
}, {});
|
|
14
|
-
}
|
|
15
|
-
return (0, core_1.toArray)(select, { split: ',' }).reduce((acc, field) => {
|
|
16
|
-
acc[field] = true;
|
|
17
|
-
return acc;
|
|
18
|
-
}, {});
|
|
19
|
-
}
|
|
20
|
-
static parseFilter(query) {
|
|
21
|
-
const { condition = {}, keyword } = query;
|
|
22
|
-
const where = MysqlHelper.parseCondition(condition);
|
|
23
|
-
if (keyword && typeof where === 'object') {
|
|
24
|
-
where['name'] = (0, typeorm_1.ILike)(`%${keyword}%`);
|
|
25
|
-
}
|
|
26
|
-
return { where };
|
|
27
|
-
}
|
|
28
|
-
static parseCondition(condition) {
|
|
29
|
-
const where = {};
|
|
5
|
+
static applyCondition(qb, condition) {
|
|
6
|
+
if (!condition)
|
|
7
|
+
return;
|
|
30
8
|
for (const [key, value] of Object.entries(condition)) {
|
|
31
|
-
if (key === '$
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
if (key === '$or') {
|
|
10
|
+
const orConditions = value.map((c) => MysqlHelper.buildCondition(qb, c));
|
|
11
|
+
qb.orWhere(orConditions.join(' OR '));
|
|
34
12
|
}
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
13
|
+
else if (key === '$and') {
|
|
14
|
+
const andConditions = value.map((c) => MysqlHelper.buildCondition(qb, c));
|
|
15
|
+
qb.andWhere(andConditions.join(' AND '));
|
|
38
16
|
}
|
|
17
|
+
else {
|
|
18
|
+
const whereClause = MysqlHelper.buildCondition(qb, { [key]: value });
|
|
19
|
+
qb.andWhere(whereClause);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static buildCondition(qb, condition) {
|
|
24
|
+
for (const [key, value] of Object.entries(condition)) {
|
|
39
25
|
if (typeof value === 'object') {
|
|
40
26
|
for (const [op, val] of Object.entries(value)) {
|
|
41
27
|
switch (op) {
|
|
42
28
|
case '$eq':
|
|
43
|
-
|
|
29
|
+
qb.andWhere(`${qb.alias}.${key} = :${key}`, { [key]: val });
|
|
44
30
|
break;
|
|
45
31
|
case '$gt':
|
|
46
|
-
|
|
32
|
+
qb.andWhere(`${qb.alias}.${key} > :${key}`, { [key]: val });
|
|
47
33
|
break;
|
|
48
34
|
case '$gte':
|
|
49
|
-
|
|
35
|
+
qb.andWhere(`${qb.alias}.${key} >= :${key}`, { [key]: val });
|
|
50
36
|
break;
|
|
51
37
|
case '$lt':
|
|
52
|
-
|
|
38
|
+
qb.andWhere(`${qb.alias}.${key} < :${key}`, { [key]: val });
|
|
53
39
|
break;
|
|
54
40
|
case '$lte':
|
|
55
|
-
|
|
41
|
+
qb.andWhere(`${qb.alias}.${key} <= :${key}`, { [key]: val });
|
|
56
42
|
break;
|
|
57
43
|
case '$ne':
|
|
58
|
-
|
|
44
|
+
qb.andWhere(`${qb.alias}.${key} != :${key}`, { [key]: val });
|
|
59
45
|
break;
|
|
60
46
|
case '$in':
|
|
61
|
-
|
|
47
|
+
qb.andWhere(`${qb.alias}.${key} IN (:...${key})`, { [key]: val });
|
|
48
|
+
break;
|
|
49
|
+
case '$nin':
|
|
50
|
+
qb.andWhere(`${qb.alias}.${key} NOT IN (:...${key})`, { [key]: val });
|
|
51
|
+
break;
|
|
52
|
+
case '$all':
|
|
53
|
+
qb.andWhere(`${qb.alias}.${key} @> ARRAY[:...${key}]`, { [key]: val });
|
|
62
54
|
break;
|
|
63
55
|
case '$like':
|
|
64
|
-
|
|
56
|
+
qb.andWhere(`${qb.alias}.${key} LIKE :${key}`, { [key]: `%${val}%` });
|
|
65
57
|
break;
|
|
66
58
|
case '$begin':
|
|
67
|
-
|
|
59
|
+
qb.andWhere(`${qb.alias}.${key} LIKE :${key}`, { [key]: `${val}%` });
|
|
68
60
|
break;
|
|
69
61
|
case '$end':
|
|
70
|
-
|
|
62
|
+
qb.andWhere(`${qb.alias}.${key} LIKE :${key}`, { [key]: `%${val}` });
|
|
63
|
+
break;
|
|
64
|
+
case '$exists':
|
|
65
|
+
qb.andWhere(`${qb.alias}.${key} IS NOT NULL`);
|
|
66
|
+
break;
|
|
67
|
+
case '$nil':
|
|
68
|
+
qb.andWhere(`${qb.alias}.${key} IS NULL`);
|
|
69
|
+
break;
|
|
70
|
+
case '$empty':
|
|
71
|
+
qb.andWhere(`${qb.alias}.${key} = ''`);
|
|
72
|
+
break;
|
|
73
|
+
case '$not':
|
|
74
|
+
qb.andWhere(`${qb.alias}.${key} != :${key}`, { [key]: val });
|
|
75
|
+
break;
|
|
76
|
+
case '$size':
|
|
77
|
+
qb.andWhere(`array_length(${key}, 1) = :${key}`, { [key]: val });
|
|
71
78
|
break;
|
|
72
79
|
default:
|
|
73
|
-
throw new
|
|
80
|
+
throw new Error(`Unsupported operator: ${op}`);
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
else {
|
|
78
|
-
|
|
85
|
+
qb.andWhere(`${qb.alias}.${key} = :${key}`, { [key]: value });
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
|
-
return
|
|
88
|
+
return qb;
|
|
82
89
|
}
|
|
83
|
-
static
|
|
84
|
-
|
|
90
|
+
static applyProjection(qb, select) {
|
|
91
|
+
if (!select)
|
|
92
|
+
return;
|
|
93
|
+
const fields = Array.isArray(select) ? select : select.split(',');
|
|
94
|
+
qb.select(fields.map(field => `${qb.alias}.${field.trim()}`));
|
|
95
|
+
}
|
|
96
|
+
static applyOrder(qb, sort) {
|
|
97
|
+
if (!sort)
|
|
98
|
+
return;
|
|
85
99
|
for (const [key, value] of Object.entries(sort)) {
|
|
86
|
-
|
|
100
|
+
qb.addOrderBy(`${qb.alias}.${key}`, value === 'asc' ? 'ASC' : 'DESC');
|
|
87
101
|
}
|
|
88
|
-
return order;
|
|
89
102
|
}
|
|
90
|
-
static
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
static applyRelations(qb, populate) {
|
|
104
|
+
if (!populate)
|
|
105
|
+
return;
|
|
106
|
+
for (const [relation, value] of Object.entries(populate)) {
|
|
93
107
|
if (value === '*') {
|
|
94
|
-
|
|
95
|
-
continue;
|
|
108
|
+
qb.leftJoinAndSelect(`${qb.alias}.${relation}`, relation);
|
|
96
109
|
}
|
|
97
|
-
if (typeof value === 'object') {
|
|
98
|
-
|
|
110
|
+
else if (typeof value === 'object') {
|
|
111
|
+
qb.leftJoinAndSelect(`${qb.alias}.${relation}`, relation);
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
|
-
return relations;
|
|
102
114
|
}
|
|
103
115
|
}
|
|
104
116
|
exports.MysqlHelper = MysqlHelper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.helper.js","sourceRoot":"","sources":["../../src/helpers/mysql.helper.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"mysql.helper.js","sourceRoot":"","sources":["../../src/helpers/mysql.helper.ts"],"names":[],"mappings":";;;AAGA,MAAa,WAAW;IACtB,MAAM,CAAC,cAAc,CAAI,EAAyB,EAAE,SAAyB;QAC3E,IAAI,CAAC,SAAS;YAAE,OAAO;QAEvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACrD,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;gBAClB,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAgB,EAAE,EAAE,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;gBACxF,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YACxC,CAAC;iBAAM,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;gBAC1B,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAgB,EAAE,EAAE,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;gBACzF,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YAC3C,CAAC;iBAAM,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B,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA5HD,kCA4HC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.utils.d.ts","sourceRoot":"","sources":["../../src/helpers/mysql.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,MAAM,CAWlE;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,kBAAkB,CAAC,GAAG,CAAC,UAGzD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printSql = printSql;
|
|
4
|
+
exports.exportSql = exportSql;
|
|
5
|
+
function printSql(query, parameters) {
|
|
6
|
+
let sql = query;
|
|
7
|
+
parameters.forEach((param) => {
|
|
8
|
+
sql = sql.replace('?', () => {
|
|
9
|
+
if (typeof param === 'string')
|
|
10
|
+
return `'${param}'`;
|
|
11
|
+
else if (param instanceof Date)
|
|
12
|
+
return `'${param.toISOString()}'`;
|
|
13
|
+
else if (param === null || param === undefined)
|
|
14
|
+
return 'NULL';
|
|
15
|
+
else
|
|
16
|
+
return param.toString();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return sql;
|
|
20
|
+
}
|
|
21
|
+
function exportSql(builder) {
|
|
22
|
+
const [query, params] = builder.getQueryAndParameters();
|
|
23
|
+
return printSql(query, params);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=mysql.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.utils.js","sourceRoot":"","sources":["../../src/helpers/mysql.utils.ts"],"names":[],"mappings":";;AAEA,4BAWC;AAED,8BAGC;AAhBD,SAAgB,QAAQ,CAAC,KAAa,EAAE,UAAkB;IACxD,IAAI,GAAG,GAAW,KAAK,CAAC;IACxB,UAAU,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;QAChC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE;YAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO,IAAI,KAAK,GAAG,CAAC;iBAC9C,IAAI,KAAK,YAAY,IAAI;gBAAE,OAAO,IAAI,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC;iBAC7D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAC;;gBACzD,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,SAAS,CAAC,OAAgC;IACxD,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IACxD,OAAO,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export * from './mysql.service';
|
|
|
4
4
|
export * from './mysql.config';
|
|
5
5
|
export * from './mysql.repo';
|
|
6
6
|
export * from './mysql.exception';
|
|
7
|
+
export * from './mysql.benchmark';
|
|
8
|
+
export * from './decorators';
|
|
9
|
+
export * from './helpers';
|
|
7
10
|
export * from './models';
|
|
8
11
|
export * from 'typeorm';
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,9 @@ __exportStar(require("./mysql.service"), exports);
|
|
|
20
20
|
__exportStar(require("./mysql.config"), exports);
|
|
21
21
|
__exportStar(require("./mysql.repo"), exports);
|
|
22
22
|
__exportStar(require("./mysql.exception"), exports);
|
|
23
|
+
__exportStar(require("./mysql.benchmark"), exports);
|
|
24
|
+
__exportStar(require("./decorators"), exports);
|
|
25
|
+
__exportStar(require("./helpers"), exports);
|
|
23
26
|
__exportStar(require("./models"), exports);
|
|
24
27
|
__exportStar(require("typeorm"), exports);
|
|
25
28
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,iDAA+B;AAC/B,kDAAgC;AAChC,iDAA+B;AAC/B,+CAA6B;AAC7B,oDAAkC;AAClC,2CAAyB;AACzB,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,iDAA+B;AAC/B,kDAAgC;AAChC,iDAA+B;AAC/B,+CAA6B;AAC7B,oDAAkC;AAClC,oDAAkC;AAClC,+CAA6B;AAC7B,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LogService } from '@joktec/core';
|
|
2
|
+
import { Logger } from 'typeorm';
|
|
3
|
+
import { MysqlBenchmarkConfig } from './mysql.config';
|
|
4
|
+
export declare class MysqlBenchmark implements Logger {
|
|
5
|
+
private benchmark;
|
|
6
|
+
private logService;
|
|
7
|
+
constructor(benchmark: MysqlBenchmarkConfig, logService: LogService);
|
|
8
|
+
logQuery(query: string, parameters?: any[]): void;
|
|
9
|
+
logQueryError(error: string | Error, query: string, parameters?: any[]): void;
|
|
10
|
+
logQuerySlow(time: number, query: string, parameters?: any[]): void;
|
|
11
|
+
logSchemaBuild(message: string): void;
|
|
12
|
+
logMigration(message: string): void;
|
|
13
|
+
log(level: 'log' | 'info' | 'warn', message: any): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=mysql.benchmark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.benchmark.d.ts","sourceRoot":"","sources":["../src/mysql.benchmark.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAiB,MAAM,gBAAgB,CAAC;AAGrE,qBACa,cAAe,YAAW,MAAM;IAEzC,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,UAAU;gBADV,SAAS,EAAE,oBAAoB,EAC/B,UAAU,EAAE,UAAU;IAKhC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE;IAO1C,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE;IAQtE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE;IAK5D,cAAc,CAAC,OAAO,EAAE,MAAM;IAM9B,YAAY,CAAC,OAAO,EAAE,MAAM;IAI5B,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG;CAgBjD"}
|