@vizzly/semantic-layer-public 0.0.4 → 0.0.6
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.
|
@@ -3,8 +3,11 @@ import { Client } from '@vizzly/sqlbuilder-public';
|
|
|
3
3
|
export declare const ALLOWED_ID_REGEX: RegExp;
|
|
4
4
|
export declare const ID_REGEX_ERROR_MESSAGE = "IDs must only use alpha numeric characters and _";
|
|
5
5
|
export type ConfigValidationOptions = {
|
|
6
|
-
|
|
6
|
+
onlyClients?: Array<Client>;
|
|
7
|
+
dataSetIdToClientMapping?: {
|
|
8
|
+
[dataSetId: string]: Client;
|
|
9
|
+
};
|
|
7
10
|
checkConnectionSpecificDataSets?: boolean;
|
|
8
11
|
};
|
|
9
|
-
declare const _default: (config:
|
|
12
|
+
declare const _default: (config: any, options?: Partial<ConfigValidationOptions>) => Joi.ValidationResult;
|
|
10
13
|
export default _default;
|
|
@@ -9,11 +9,12 @@ const getQueryEngineConfig_1 = require("../QueryEngineConfig/getQueryEngineConfi
|
|
|
9
9
|
const constants_1 = require("./constants");
|
|
10
10
|
const support_1 = require("../QueryEngineConfig/support");
|
|
11
11
|
const constants_2 = require("../QueryEngineConfig/constants");
|
|
12
|
+
const DataSetNotLinkedToConnection_1 = require("../errors/DataSetNotLinkedToConnection");
|
|
12
13
|
const REDACT_KEYS_FROM_ERROR_MESSAGE = ['unencryptedCredentials', 'encryptedCredentials'];
|
|
13
14
|
const SUPPORTED_SECURE_FILTER_OPS = Object.keys(constants_2.supportedOperatorsConstants);
|
|
14
15
|
const SUPPORTED_ALLOWED_GRANULARITIES = ['second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
|
|
15
16
|
const SUPPORTED_JOINS = ['rightJoin', 'leftJoin', 'innerJoin', 'outerJoin', 'leftOuterJoin', 'rightOuterJoin'];
|
|
16
|
-
exports.ALLOWED_ID_REGEX = /^[a-zA-Z0-9_
|
|
17
|
+
exports.ALLOWED_ID_REGEX = /^[a-zA-Z0-9_+/=-\s]*$/;
|
|
17
18
|
exports.ID_REGEX_ERROR_MESSAGE = 'IDs must only use alpha numeric characters and _';
|
|
18
19
|
const DEFAULT_SCHEMA_OPTIONS = { checkConnectionSpecificDataSets: true };
|
|
19
20
|
const joiOptions = { abortEarly: false, allowUnknown: true };
|
|
@@ -129,15 +130,39 @@ const sqlDataSetSchema = (fieldSchema) => joi_1.default.object(Object.assign(Obj
|
|
|
129
130
|
* has been requested.
|
|
130
131
|
* */
|
|
131
132
|
const alternativeDataSetSchemas = (options) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
var _a;
|
|
134
|
+
// If only one client exists in the list of allowed clients, return that schema for that one client.
|
|
135
|
+
if (((_a = options.onlyClients) === null || _a === void 0 ? void 0 : _a.length) === 1)
|
|
136
|
+
return sqlDataSetSchema(fieldSchema(options.onlyClients[0]));
|
|
137
|
+
// Build out a schema that validates any of the desired client types in-case we can't be more specific in
|
|
138
|
+
// the validation.
|
|
139
|
+
const fallbackValidations = joi_1.default.alternatives(...(options.onlyClients || constants_1.SUPPORTED_CLIENTS).map((client) => sqlDataSetSchema(fieldSchema(client))));
|
|
140
|
+
// If a mapping has been provided of data set IDs to client types, then use it to provide a more accurate
|
|
141
|
+
// 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"
|
|
142
|
+
if (options.dataSetIdToClientMapping) {
|
|
143
|
+
const whereClauses = Object.entries(options.dataSetIdToClientMapping).map(([dataSetId, client]) => ({
|
|
144
|
+
is: dataSetId,
|
|
145
|
+
then: sqlDataSetSchema(fieldSchema(client)),
|
|
146
|
+
}));
|
|
147
|
+
// Build the alternative options, but also provide a 'catch all' in-case the data set mapping fails.
|
|
148
|
+
return joi_1.default.alternatives().conditional('.id', [
|
|
149
|
+
...whereClauses,
|
|
150
|
+
{
|
|
151
|
+
is: true,
|
|
152
|
+
then: fallbackValidations,
|
|
153
|
+
},
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
// This really is the end of the road, just provide the broadest validation.
|
|
157
|
+
return fallbackValidations;
|
|
135
158
|
};
|
|
136
159
|
const configSchema = (fullObj, options) => joi_1.default.object({
|
|
137
160
|
version: joi_1.default.number(),
|
|
138
161
|
connections: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.object({
|
|
139
|
-
|
|
140
|
-
|
|
162
|
+
client: joi_1.default.string()
|
|
163
|
+
.allow(...constants_1.SUPPORTED_CLIENTS)
|
|
164
|
+
.required(),
|
|
165
|
+
name: joi_1.default.string().optional().allow(''),
|
|
141
166
|
encryptedCredentials: joi_1.default.string().optional(),
|
|
142
167
|
unencryptedCredentials: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.object()).optional(),
|
|
143
168
|
})),
|
|
@@ -147,8 +172,9 @@ const configSchema = (fullObj, options) => joi_1.default.object({
|
|
|
147
172
|
var _a, _b;
|
|
148
173
|
const connectionId = value.connectionId || '___vizzly_default_conn';
|
|
149
174
|
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;
|
|
150
|
-
if (!clientType)
|
|
151
|
-
throw new
|
|
175
|
+
if (!clientType) {
|
|
176
|
+
throw new DataSetNotLinkedToConnection_1.DataSetNotLinkedToConnection(value.id);
|
|
177
|
+
}
|
|
152
178
|
const validationResult = sqlDataSetSchema(fieldSchema(clientType)).validate(value, joiOptions);
|
|
153
179
|
if (validationResult.error)
|
|
154
180
|
throw validationResult.error;
|
|
@@ -168,7 +194,7 @@ const configSchema = (fullObj, options) => joi_1.default.object({
|
|
|
168
194
|
.optional(),
|
|
169
195
|
});
|
|
170
196
|
exports.default = (config, options = {}) => {
|
|
171
|
-
const validationResult = configSchema(config, Object.assign(Object.assign({}, DEFAULT_SCHEMA_OPTIONS), options)).validate(config, joiOptions);
|
|
197
|
+
const validationResult = configSchema(config, Object.assign(Object.assign(Object.assign({}, DEFAULT_SCHEMA_OPTIONS), options), { dataSetIdToClientMapping: buildDataSetToClientTypeMapping(config) })).validate(config, joiOptions);
|
|
172
198
|
if (validationResult.error) {
|
|
173
199
|
validationResult.error.details.map((detail) => {
|
|
174
200
|
var _a, _b;
|
|
@@ -181,3 +207,19 @@ exports.default = (config, options = {}) => {
|
|
|
181
207
|
}
|
|
182
208
|
return validationResult;
|
|
183
209
|
};
|
|
210
|
+
const buildDataSetToClientTypeMapping = (config) => {
|
|
211
|
+
let dataSetIdToClientMapping = {};
|
|
212
|
+
if (config && typeof (config === null || config === void 0 ? void 0 : config.dataSets) === 'object' && typeof (config === null || config === void 0 ? void 0 : config.connections) === 'object') {
|
|
213
|
+
config.dataSets.forEach((dataSet) => {
|
|
214
|
+
var _a, _b;
|
|
215
|
+
if (dataSetIdToClientMapping) {
|
|
216
|
+
const connectionId = dataSet.connectionId || '___vizzly_default_conn';
|
|
217
|
+
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;
|
|
218
|
+
if (clientType) {
|
|
219
|
+
dataSetIdToClientMapping[dataSet.id] = clientType;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return dataSetIdToClientMapping;
|
|
225
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSetNotLinkedToConnection = void 0;
|
|
4
|
+
class DataSetNotLinkedToConnection extends Error {
|
|
5
|
+
constructor(dataSetId) {
|
|
6
|
+
super(`Data set ${dataSetId} must be linked to a connection by setting a 'connectionId' property that references a connection in the 'connections' section.`);
|
|
7
|
+
this.name = 'DataSetNotLinkedToConnection';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.DataSetNotLinkedToConnection = DataSetNotLinkedToConnection;
|