@infrab4a/connect 4.25.0-beta.5 → 4.25.0-beta.7
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/index.cjs.js
CHANGED
|
@@ -5098,21 +5098,19 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
5098
5098
|
});
|
|
5099
5099
|
}
|
|
5100
5100
|
async find(params, options) {
|
|
5101
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
5101
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5102
5102
|
this.logger = DebugHelper.from(this, 'find');
|
|
5103
|
-
|
|
5103
|
+
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
5104
|
+
const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
|
|
5105
|
+
const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
|
|
5106
|
+
if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
|
|
5104
5107
|
const cacheKey = generateCacheKey(this.model, params);
|
|
5105
5108
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
5106
5109
|
if (cachedData) {
|
|
5107
|
-
const json = JSON.parse(cachedData);
|
|
5108
|
-
const data = (_c = json.data) === null || _c === void 0 ? void 0 : _c.map((item) => this.convertDataFromHasura(item));
|
|
5109
5110
|
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
5110
|
-
return
|
|
5111
|
+
return this.bindResult(JSON.parse(cachedData), { enableCount, findOptions, tableFiltersNamed });
|
|
5111
5112
|
}
|
|
5112
5113
|
}
|
|
5113
|
-
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
5114
|
-
const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
|
|
5115
|
-
const enableCount = (_d = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _d !== void 0 ? _d : true;
|
|
5116
5114
|
const variablesFilters = lodash.isNil(filters)
|
|
5117
5115
|
? {}
|
|
5118
5116
|
: {
|
|
@@ -5163,7 +5161,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
5163
5161
|
]
|
|
5164
5162
|
: []),
|
|
5165
5163
|
...((!this.lastDistinct[tableFiltersNamed] &&
|
|
5166
|
-
((
|
|
5164
|
+
((_e = (_d = params.options) === null || _d === void 0 ? void 0 : _d.distinct) === null || _e === void 0 ? void 0 : _e.map((distinct) => {
|
|
5167
5165
|
var _a, _b;
|
|
5168
5166
|
const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
5169
5167
|
const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
|
|
@@ -5183,38 +5181,42 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
5183
5181
|
}))) ||
|
|
5184
5182
|
[]),
|
|
5185
5183
|
]);
|
|
5184
|
+
if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = options === null || options === void 0 ? void 0 : options.cache) === null || _g === void 0 ? void 0 : _g.enabled)) {
|
|
5185
|
+
const cacheKey = generateCacheKey(this.model, params);
|
|
5186
|
+
await this.cache.cacheAdapter.set({
|
|
5187
|
+
key: cacheKey,
|
|
5188
|
+
data: JSON.stringify(result),
|
|
5189
|
+
expirationInSeconds: ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.ttl) || this.cache.ttlDefault,
|
|
5190
|
+
});
|
|
5191
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5192
|
+
}
|
|
5193
|
+
return this.bindResult(result, { enableCount, findOptions, tableFiltersNamed });
|
|
5194
|
+
}
|
|
5195
|
+
bindResult(result, { enableCount, findOptions, tableFiltersNamed, }) {
|
|
5196
|
+
var _a, _b, _c, _d;
|
|
5186
5197
|
const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
|
|
5187
|
-
const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((
|
|
5198
|
+
const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
|
|
5188
5199
|
? {
|
|
5189
5200
|
minimal: findOptions.minimal.reduce((minimals, current) => {
|
|
5190
5201
|
var _a;
|
|
5191
5202
|
return (Object.assign(Object.assign({}, minimals), lodash.set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
|
|
5192
5203
|
}, {}),
|
|
5193
5204
|
}
|
|
5194
|
-
: {})), (((
|
|
5205
|
+
: {})), (((_b = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _b === void 0 ? void 0 : _b.length)
|
|
5195
5206
|
? {
|
|
5196
5207
|
maximum: findOptions.maximum.reduce((maximums, current) => {
|
|
5197
5208
|
var _a;
|
|
5198
5209
|
return (Object.assign(Object.assign({}, maximums), lodash.set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
|
|
5199
5210
|
}, {}),
|
|
5200
5211
|
}
|
|
5201
|
-
: {})), (((
|
|
5202
|
-
distinct: (
|
|
5212
|
+
: {})), (((_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _c === void 0 ? void 0 : _c.length) && {
|
|
5213
|
+
distinct: (_d = this.lastDistinct[tableFiltersNamed]) !== null && _d !== void 0 ? _d : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
|
|
5203
5214
|
var _a, _b;
|
|
5204
5215
|
const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
5205
5216
|
const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
|
|
5206
5217
|
return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
|
|
5207
5218
|
}, {})),
|
|
5208
5219
|
}));
|
|
5209
|
-
if (((_l = this.cache) === null || _l === void 0 ? void 0 : _l.cacheAdapter) && ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.enabled)) {
|
|
5210
|
-
const cacheKey = generateCacheKey(this.model, params);
|
|
5211
|
-
await this.cache.cacheAdapter.set({
|
|
5212
|
-
key: cacheKey,
|
|
5213
|
-
data: JSON.stringify(findResult),
|
|
5214
|
-
expirationInSeconds: ((_o = options === null || options === void 0 ? void 0 : options.cache) === null || _o === void 0 ? void 0 : _o.ttl) || this.cache.ttlDefault,
|
|
5215
|
-
});
|
|
5216
|
-
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5217
|
-
}
|
|
5218
5220
|
return findResult;
|
|
5219
5221
|
}
|
|
5220
5222
|
};
|
package/index.esm.js
CHANGED
|
@@ -5092,21 +5092,19 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
5092
5092
|
});
|
|
5093
5093
|
}
|
|
5094
5094
|
async find(params, options) {
|
|
5095
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
5095
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5096
5096
|
this.logger = DebugHelper.from(this, 'find');
|
|
5097
|
-
|
|
5097
|
+
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
5098
|
+
const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
|
|
5099
|
+
const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
|
|
5100
|
+
if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
|
|
5098
5101
|
const cacheKey = generateCacheKey(this.model, params);
|
|
5099
5102
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
5100
5103
|
if (cachedData) {
|
|
5101
|
-
const json = JSON.parse(cachedData);
|
|
5102
|
-
const data = (_c = json.data) === null || _c === void 0 ? void 0 : _c.map((item) => this.convertDataFromHasura(item));
|
|
5103
5104
|
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
5104
|
-
return
|
|
5105
|
+
return this.bindResult(JSON.parse(cachedData), { enableCount, findOptions, tableFiltersNamed });
|
|
5105
5106
|
}
|
|
5106
5107
|
}
|
|
5107
|
-
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
5108
|
-
const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
|
|
5109
|
-
const enableCount = (_d = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _d !== void 0 ? _d : true;
|
|
5110
5108
|
const variablesFilters = isNil(filters)
|
|
5111
5109
|
? {}
|
|
5112
5110
|
: {
|
|
@@ -5157,7 +5155,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
5157
5155
|
]
|
|
5158
5156
|
: []),
|
|
5159
5157
|
...((!this.lastDistinct[tableFiltersNamed] &&
|
|
5160
|
-
((
|
|
5158
|
+
((_e = (_d = params.options) === null || _d === void 0 ? void 0 : _d.distinct) === null || _e === void 0 ? void 0 : _e.map((distinct) => {
|
|
5161
5159
|
var _a, _b;
|
|
5162
5160
|
const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
5163
5161
|
const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
|
|
@@ -5177,38 +5175,42 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
5177
5175
|
}))) ||
|
|
5178
5176
|
[]),
|
|
5179
5177
|
]);
|
|
5178
|
+
if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = options === null || options === void 0 ? void 0 : options.cache) === null || _g === void 0 ? void 0 : _g.enabled)) {
|
|
5179
|
+
const cacheKey = generateCacheKey(this.model, params);
|
|
5180
|
+
await this.cache.cacheAdapter.set({
|
|
5181
|
+
key: cacheKey,
|
|
5182
|
+
data: JSON.stringify(result),
|
|
5183
|
+
expirationInSeconds: ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.ttl) || this.cache.ttlDefault,
|
|
5184
|
+
});
|
|
5185
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5186
|
+
}
|
|
5187
|
+
return this.bindResult(result, { enableCount, findOptions, tableFiltersNamed });
|
|
5188
|
+
}
|
|
5189
|
+
bindResult(result, { enableCount, findOptions, tableFiltersNamed, }) {
|
|
5190
|
+
var _a, _b, _c, _d;
|
|
5180
5191
|
const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
|
|
5181
|
-
const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((
|
|
5192
|
+
const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
|
|
5182
5193
|
? {
|
|
5183
5194
|
minimal: findOptions.minimal.reduce((minimals, current) => {
|
|
5184
5195
|
var _a;
|
|
5185
5196
|
return (Object.assign(Object.assign({}, minimals), set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
|
|
5186
5197
|
}, {}),
|
|
5187
5198
|
}
|
|
5188
|
-
: {})), (((
|
|
5199
|
+
: {})), (((_b = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _b === void 0 ? void 0 : _b.length)
|
|
5189
5200
|
? {
|
|
5190
5201
|
maximum: findOptions.maximum.reduce((maximums, current) => {
|
|
5191
5202
|
var _a;
|
|
5192
5203
|
return (Object.assign(Object.assign({}, maximums), set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
|
|
5193
5204
|
}, {}),
|
|
5194
5205
|
}
|
|
5195
|
-
: {})), (((
|
|
5196
|
-
distinct: (
|
|
5206
|
+
: {})), (((_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _c === void 0 ? void 0 : _c.length) && {
|
|
5207
|
+
distinct: (_d = this.lastDistinct[tableFiltersNamed]) !== null && _d !== void 0 ? _d : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
|
|
5197
5208
|
var _a, _b;
|
|
5198
5209
|
const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
5199
5210
|
const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
|
|
5200
5211
|
return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
|
|
5201
5212
|
}, {})),
|
|
5202
5213
|
}));
|
|
5203
|
-
if (((_l = this.cache) === null || _l === void 0 ? void 0 : _l.cacheAdapter) && ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.enabled)) {
|
|
5204
|
-
const cacheKey = generateCacheKey(this.model, params);
|
|
5205
|
-
await this.cache.cacheAdapter.set({
|
|
5206
|
-
key: cacheKey,
|
|
5207
|
-
data: JSON.stringify(findResult),
|
|
5208
|
-
expirationInSeconds: ((_o = options === null || options === void 0 ? void 0 : options.cache) === null || _o === void 0 ? void 0 : _o.ttl) || this.cache.ttlDefault,
|
|
5209
|
-
});
|
|
5210
|
-
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5211
|
-
}
|
|
5212
5214
|
return findResult;
|
|
5213
5215
|
}
|
|
5214
5216
|
};
|
package/package.json
CHANGED
|
@@ -7,6 +7,22 @@ export declare const withFindHasuraGraphQL: <MBase extends ModelBaseStructure<MB
|
|
|
7
7
|
find(params?: FindRepositoryParams<MBase>, options?: {
|
|
8
8
|
cache?: RepositoryCacheOptions;
|
|
9
9
|
}): Promise<RepositoryFindResult<MBase>>;
|
|
10
|
+
bindResult(result: any, { enableCount, findOptions, tableFiltersNamed, }: {
|
|
11
|
+
enableCount: boolean;
|
|
12
|
+
findOptions: {
|
|
13
|
+
enableCount?: boolean;
|
|
14
|
+
minimal?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];
|
|
15
|
+
maximum?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];
|
|
16
|
+
distinct?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];
|
|
17
|
+
};
|
|
18
|
+
tableFiltersNamed: string;
|
|
19
|
+
}): {
|
|
20
|
+
distinct: any;
|
|
21
|
+
maximum?: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> extends infer T extends import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> ? { [key in keyof T]: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase>[key]; } : never;
|
|
22
|
+
minimal?: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> extends infer T extends import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> ? { [key in keyof T]: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase>[key]; } : never;
|
|
23
|
+
data: MBase[];
|
|
24
|
+
count: any;
|
|
25
|
+
};
|
|
10
26
|
bindOrderByAttributes: (orderBy: RepositoryOrderBy<MBase>, fields: HasuraGraphQLFields<MBase>) => any[];
|
|
11
27
|
bindAggretageAttributes: (aggregates: {
|
|
12
28
|
minimal?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];
|