@vizzly/semantic-layer-public 0.0.95 → 0.0.97
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.
|
@@ -9,5 +9,7 @@ export type ConfigValidationOptions = {
|
|
|
9
9
|
};
|
|
10
10
|
checkConnectionSpecificDataSets?: boolean;
|
|
11
11
|
};
|
|
12
|
+
export declare const _fieldSchema: (client: Client) => Joi.ObjectSchema<any>;
|
|
13
|
+
export declare const _sqlDataSetSchema: (fieldSchema: Joi.Schema) => Joi.ObjectSchema<any>;
|
|
12
14
|
declare const _default: (config: any, options?: Partial<ConfigValidationOptions>) => Joi.ValidationResult;
|
|
13
15
|
export default _default;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ID_REGEX_ERROR_MESSAGE = exports.ALLOWED_ID_REGEX = void 0;
|
|
6
|
+
exports._sqlDataSetSchema = exports._fieldSchema = exports.ID_REGEX_ERROR_MESSAGE = exports.ALLOWED_ID_REGEX = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("@vizzly/joi"));
|
|
8
8
|
const getQueryEngineConfig_1 = require("../QueryEngineConfig/getQueryEngineConfig");
|
|
9
9
|
const constants_1 = require("./constants");
|
|
@@ -18,7 +18,7 @@ exports.ALLOWED_ID_REGEX = /^[a-zA-Z0-9_+:\/=\-\s]*$/;
|
|
|
18
18
|
exports.ID_REGEX_ERROR_MESSAGE = 'IDs must only use alpha numeric characters and _';
|
|
19
19
|
const DEFAULT_SCHEMA_OPTIONS = { checkConnectionSpecificDataSets: true };
|
|
20
20
|
const joiOptions = { abortEarly: false, allowUnknown: true };
|
|
21
|
-
const
|
|
21
|
+
const _fieldSchema = (client) => {
|
|
22
22
|
return joi_1.default.object({
|
|
23
23
|
id: joi_1.default.string()
|
|
24
24
|
.required()
|
|
@@ -81,6 +81,7 @@ const fieldSchema = (client) => {
|
|
|
81
81
|
.optional(),
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
|
+
exports._fieldSchema = _fieldSchema;
|
|
84
85
|
const sqlJoinSchema = joi_1.default.object({
|
|
85
86
|
type: joi_1.default.string()
|
|
86
87
|
.valid(...SUPPORTED_JOINS)
|
|
@@ -120,11 +121,16 @@ const baseDataSetSchema = (fieldSchema) => ({
|
|
|
120
121
|
fields: joi_1.default.array().min(1).items(fieldSchema).unique('id').message('Field IDs must be unique').required(),
|
|
121
122
|
secureFilterGuards: joi_1.default.array().items(secureFilterGuardSchema).optional(),
|
|
122
123
|
});
|
|
123
|
-
const
|
|
124
|
+
const _sqlDataSetSchema = (fieldSchema) => joi_1.default.object(Object.assign(Object.assign({}, baseDataSetSchema(fieldSchema)), { joins: joi_1.default.array()
|
|
124
125
|
.items(sqlJoinSchema)
|
|
125
|
-
.unique(
|
|
126
|
+
.unique((a, b) => {
|
|
127
|
+
const rightMatches = JSON.stringify(a['right']) === JSON.stringify(b['right']);
|
|
128
|
+
const noAs = !a['as'] && !b['as'];
|
|
129
|
+
return noAs && rightMatches;
|
|
130
|
+
})
|
|
126
131
|
.message('A table cannot be referenced in a right join multiple times.')
|
|
127
132
|
.optional() }));
|
|
133
|
+
exports._sqlDataSetSchema = _sqlDataSetSchema;
|
|
128
134
|
/**
|
|
129
135
|
* Return schema to validate a schema. Either
|
|
130
136
|
* alternatives where any is valid. Or a specific one that
|
|
@@ -134,16 +140,16 @@ const alternativeDataSetSchemas = (options) => {
|
|
|
134
140
|
var _a;
|
|
135
141
|
// If only one client exists in the list of allowed clients, return that schema for that one client.
|
|
136
142
|
if (((_a = options.onlyClients) === null || _a === void 0 ? void 0 : _a.length) === 1)
|
|
137
|
-
return
|
|
143
|
+
return (0, exports._sqlDataSetSchema)((0, exports._fieldSchema)(options.onlyClients[0]));
|
|
138
144
|
// Build out a schema that validates any of the desired client types in-case we can't be more specific in
|
|
139
145
|
// the validation.
|
|
140
|
-
const fallbackValidations = joi_1.default.alternatives(...(options.onlyClients || constants_1.SUPPORTED_CLIENTS).map((client) =>
|
|
146
|
+
const fallbackValidations = joi_1.default.alternatives(...(options.onlyClients || constants_1.SUPPORTED_CLIENTS).map((client) => (0, exports._sqlDataSetSchema)((0, exports._fieldSchema)(client))));
|
|
141
147
|
// If a mapping has been provided of data set IDs to client types, then use it to provide a more accurate
|
|
142
148
|
// 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"
|
|
143
149
|
if (options.dataSetIdToClientMapping) {
|
|
144
150
|
const whereClauses = Object.entries(options.dataSetIdToClientMapping).map(([dataSetId, client]) => ({
|
|
145
151
|
is: dataSetId,
|
|
146
|
-
then:
|
|
152
|
+
then: (0, exports._sqlDataSetSchema)((0, exports._fieldSchema)(client)),
|
|
147
153
|
}));
|
|
148
154
|
// Build the alternative options, but also provide a 'catch all' in-case the data set mapping fails.
|
|
149
155
|
return joi_1.default.alternatives().conditional('.id', [
|
|
@@ -176,7 +182,7 @@ const configSchema = (fullObj, options) => joi_1.default.object({
|
|
|
176
182
|
if (!clientType) {
|
|
177
183
|
throw new DataSetNotLinkedToConnection_1.DataSetNotLinkedToConnection(value.id);
|
|
178
184
|
}
|
|
179
|
-
const validationResult =
|
|
185
|
+
const validationResult = (0, exports._sqlDataSetSchema)((0, exports._fieldSchema)(clientType)).validate(value, joiOptions);
|
|
180
186
|
if (validationResult.error)
|
|
181
187
|
throw validationResult.error;
|
|
182
188
|
return value;
|