@vizzly/semantic-layer-public
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -6,6 +6,9 @@ import Joi from '@vizzly/joi'; | ||
export type ConfigValidationOptions = { | ||
onlyClient?: Client; | ||
onlyClients?: Array<Client>; | ||
dataSetIdToClientMapping?: { | ||
[dataSetId: string]: Client; | ||
}; | ||
checkConnectionSpecificDataSets?: boolean; | ||
}; | ||
declare const _default: (config: unknown, options?: Partial<ConfigValidationOptions>) => Joi.ValidationResult; | ||
declare const _default: (config: any, options?: Partial<ConfigValidationOptions>) => Joi.ValidationResult; | ||
export default _default; |
@@ -12,2 +12,3 @@ "use strict"; | ||
const constants_2 = require("../QueryEngineConfig/constants"); | ||
const DataSetNotLinkedToConnection_1 = require("../errors/DataSetNotLinkedToConnection"); | ||
const REDACT_KEYS_FROM_ERROR_MESSAGE = ['unencryptedCredentials', 'encryptedCredentials']; | ||
@@ -133,5 +134,27 @@ const SUPPORTED_SECURE_FILTER_OPS = Object.keys(constants_2.supportedOperatorsConstants); | ||
const alternativeDataSetSchemas = (options) => { | ||
if (options.onlyClient) | ||
return sqlDataSetSchema(fieldSchema(options.onlyClient)); | ||
return joi_1.default.alternatives(...constants_1.SUPPORTED_CLIENTS.map((client) => sqlDataSetSchema(fieldSchema(client)))); | ||
var _a; | ||
// If only one client exists in the list of allowed clients, return that schema for that one client. | ||
if (((_a = options.onlyClients) === null || _a === void 0 ? void 0 : _a.length) === 1) | ||
return sqlDataSetSchema(fieldSchema(options.onlyClients[0])); | ||
// Build out a schema that validates any of the desired client types in-case we can't be more specific in | ||
// the validation. | ||
const fallbackValidations = joi_1.default.alternatives(...(options.onlyClients || constants_1.SUPPORTED_CLIENTS).map((client) => sqlDataSetSchema(fieldSchema(client)))); | ||
// If a mapping has been provided of data set IDs to client types, then use it to provide a more accurate | ||
// validation and error message if there is a problem. Not a "this data set could be any of these data sets for 7 different integrations" | ||
if (options.dataSetIdToClientMapping) { | ||
const whereClauses = Object.entries(options.dataSetIdToClientMapping).map(([dataSetId, client]) => ({ | ||
is: dataSetId, | ||
then: sqlDataSetSchema(fieldSchema(client)), | ||
})); | ||
// Build the alternative options, but also provide a 'catch all' in-case the data set mapping fails. | ||
return joi_1.default.alternatives().conditional('.id', [ | ||
...whereClauses, | ||
{ | ||
is: true, | ||
then: fallbackValidations, | ||
}, | ||
]); | ||
} | ||
// This really is the end of the road, just provide the broadest validation. | ||
return fallbackValidations; | ||
}; | ||
@@ -141,4 +164,6 @@ const configSchema = (fullObj, options) => joi_1.default.object({ | ||
connections: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.object({ | ||
name: joi_1.default.string().allow(''), | ||
client: joi_1.default.string().allow(...constants_1.SUPPORTED_CLIENTS), | ||
client: joi_1.default.string() | ||
.allow(...constants_1.SUPPORTED_CLIENTS) | ||
.required(), | ||
name: joi_1.default.string().optional().allow(''), | ||
encryptedCredentials: joi_1.default.string().optional(), | ||
@@ -153,4 +178,5 @@ unencryptedCredentials: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.object()).optional(), | ||
const clientType = (_b = (_a = fullObj === null || fullObj === void 0 ? void 0 : fullObj.connections) === null || _a === void 0 ? void 0 : _a[connectionId]) === null || _b === void 0 ? void 0 : _b.client; | ||
if (!clientType) | ||
throw new Error(`Data sets must be linked to a connection using a 'connectionId' property.`); | ||
if (!clientType) { | ||
throw new DataSetNotLinkedToConnection_1.DataSetNotLinkedToConnection(value.id); | ||
} | ||
const validationResult = sqlDataSetSchema(fieldSchema(clientType)).validate(value, joiOptions); | ||
@@ -175,3 +201,3 @@ if (validationResult.error) | ||
exports.default = (config, options = {}) => { | ||
const validationResult = configSchema(config, Object.assign(Object.assign({}, DEFAULT_SCHEMA_OPTIONS), options)).validate(config, joiOptions); | ||
const validationResult = configSchema(config, Object.assign(Object.assign(Object.assign({}, DEFAULT_SCHEMA_OPTIONS), options), { dataSetIdToClientMapping: buildDataSetToClientTypeMapping(config) })).validate(config, joiOptions); | ||
if (validationResult.error) { | ||
@@ -189,1 +215,17 @@ validationResult.error.details.map((detail) => { | ||
}; | ||
const buildDataSetToClientTypeMapping = (config) => { | ||
let dataSetIdToClientMapping = {}; | ||
if (config && typeof (config === null || config === void 0 ? void 0 : config.dataSets) === 'object' && typeof (config === null || config === void 0 ? void 0 : config.connections) === 'object') { | ||
config.dataSets.forEach((dataSet) => { | ||
var _a, _b; | ||
if (dataSetIdToClientMapping) { | ||
const connectionId = dataSet.connectionId || '___vizzly_default_conn'; | ||
const clientType = (_b = (_a = config === null || config === void 0 ? void 0 : config.connections) === null || _a === void 0 ? void 0 : _a[connectionId]) === null || _b === void 0 ? void 0 : _b.client; | ||
if (clientType) { | ||
dataSetIdToClientMapping[dataSet.id] = clientType; | ||
} | ||
} | ||
}); | ||
} | ||
return dataSetIdToClientMapping; | ||
}; |
{ | ||
"name": "@vizzly/semantic-layer-public", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"source": "src/index.ts", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
52751
45
1223