@8base/utils
Advanced tools
Comparing version 0.16.5 to 0.16.6
@@ -5,2 +5,4 @@ "use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,2 +13,4 @@ value: true | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var R = _interopRequireWildcard(require("ramda")); | ||
@@ -28,3 +32,3 @@ | ||
var createQueryColumnsList = function createQueryColumnsList(tablesList, tableName) { | ||
var queryObjectConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var prevKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ''; | ||
@@ -36,7 +40,9 @@ | ||
var _queryObjectConfig$de = queryObjectConfig.deep, | ||
deep = _queryObjectConfig$de === void 0 ? 3 : _queryObjectConfig$de, | ||
_queryObjectConfig$wi = queryObjectConfig.withMeta, | ||
withMeta = _queryObjectConfig$wi === void 0 ? false : _queryObjectConfig$wi, | ||
includeColumns = queryObjectConfig.includeColumns; | ||
var _config$deep = config.deep, | ||
deep = _config$deep === void 0 ? 3 : _config$deep, | ||
_config$withMeta = config.withMeta, | ||
withMeta = _config$withMeta === void 0 ? false : _config$withMeta, | ||
_config$flatten = config.flatten, | ||
flatten = _config$flatten === void 0 ? true : _config$flatten, | ||
includeColumns = config.includeColumns; | ||
var transformedList = fields.filter(function (field) { | ||
@@ -60,3 +66,3 @@ var isMeta = tableFieldSelectors.isMetaField(field); | ||
var currentKeyString = prevKey ? "".concat(prevKey, ".").concat(fieldName) : fieldName; | ||
var title = prevKey ? "".concat(prevKey, ".").concat(capitalizeFirstLetter(fieldName)) : capitalizeFirstLetter(fieldName); | ||
var title = capitalizeFirstLetter(fieldName); | ||
var refTable = getTableByName(tablesList, refTableName); | ||
@@ -87,3 +93,12 @@ var meta = { | ||
}, currentKeyString); | ||
return innerKeys; | ||
return flatten ? [].concat((0, _toConsumableArray2.default)(innerKeys), [{ | ||
name: currentKeyString, | ||
title: title, | ||
meta: meta | ||
}]) : { | ||
name: currentKeyString, | ||
title: title, | ||
meta: meta, | ||
children: innerKeys | ||
}; | ||
} else if (isRelation) { | ||
@@ -90,0 +105,0 @@ return [{ |
{ | ||
"name": "@8base/utils", | ||
"version": "0.16.5", | ||
"version": "0.16.6", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.js", |
@@ -7,2 +7,7 @@ // @flow | ||
type CreateQueryColumnsListConfig = { | ||
flatten?: boolean, | ||
} & QueryGeneratorConfig | ||
const getTableByName = (tablesList: TableSchema[], tableName: string) => | ||
@@ -18,7 +23,7 @@ tablesList.find(({ name }) => tableName === name); | ||
tableName: string, | ||
queryObjectConfig: QueryGeneratorConfig = {}, | ||
config: CreateQueryColumnsListConfig = {}, | ||
prevKey?: string = '', | ||
) => { | ||
const { fields = [] } = getTableByName(tablesList, tableName) || {}; | ||
const { deep = 3, withMeta = false, includeColumns } = queryObjectConfig; | ||
const { deep = 3, withMeta = false, flatten = true, includeColumns } = config; | ||
@@ -48,3 +53,3 @@ const transformedList = fields | ||
const title = prevKey ? `${prevKey}.${capitalizeFirstLetter(fieldName)}` : capitalizeFirstLetter(fieldName); | ||
const title = capitalizeFirstLetter(fieldName); | ||
const refTable = getTableByName(tablesList, refTableName); | ||
@@ -67,5 +72,12 @@ | ||
} else if (isRelation && refTableName && refTable && deep > 1) { | ||
const innerKeys = createQueryColumnsList(tablesList, refTableName, { deep: deep - 1, withMeta, includeColumns }, currentKeyString); | ||
const innerKeys = createQueryColumnsList( | ||
tablesList, | ||
refTableName, | ||
{ deep: deep - 1, withMeta, includeColumns }, | ||
currentKeyString, | ||
); | ||
return innerKeys; | ||
return flatten | ||
? [...innerKeys, { name: currentKeyString, title, meta }] | ||
: { name: currentKeyString, title, meta, children: innerKeys }; | ||
} else if (isRelation) { | ||
@@ -72,0 +84,0 @@ return [{ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
412874
3405