@vizzly/semantic-layer-public 0.0.2 → 0.0.4

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.
Files changed (43) hide show
  1. package/dist/QueryEngineConfig/QueryEngineConfig.d.ts +2 -0
  2. package/dist/QueryEngineConfig/QueryEngineConfig.js +7 -0
  3. package/dist/QueryEngineConfig/bigquery.d.ts +2 -0
  4. package/dist/QueryEngineConfig/bigquery.js +46 -0
  5. package/dist/QueryEngineConfig/constants.d.ts +4 -0
  6. package/dist/QueryEngineConfig/constants.js +121 -0
  7. package/dist/QueryEngineConfig/getQueryEngineConfig.d.ts +3 -0
  8. package/dist/QueryEngineConfig/getQueryEngineConfig.js +57 -0
  9. package/dist/QueryEngineConfig/index.d.ts +4 -0
  10. package/dist/QueryEngineConfig/index.js +33 -0
  11. package/dist/QueryEngineConfig/localJS.d.ts +2 -0
  12. package/dist/QueryEngineConfig/localJS.js +42 -0
  13. package/dist/QueryEngineConfig/mariadb.d.ts +2 -0
  14. package/dist/QueryEngineConfig/mariadb.js +36 -0
  15. package/dist/QueryEngineConfig/merge.d.ts +3 -0
  16. package/dist/QueryEngineConfig/merge.js +27 -0
  17. package/dist/QueryEngineConfig/microsoftSQLServer.d.ts +2 -0
  18. package/dist/QueryEngineConfig/microsoftSQLServer.js +46 -0
  19. package/dist/QueryEngineConfig/mysql.d.ts +2 -0
  20. package/dist/QueryEngineConfig/mysql.js +35 -0
  21. package/dist/QueryEngineConfig/postgres.d.ts +2 -0
  22. package/dist/QueryEngineConfig/postgres.js +46 -0
  23. package/dist/QueryEngineConfig/redshift.d.ts +2 -0
  24. package/dist/QueryEngineConfig/redshift.js +46 -0
  25. package/dist/QueryEngineConfig/snowflake.d.ts +2 -0
  26. package/dist/QueryEngineConfig/snowflake.js +45 -0
  27. package/dist/QueryEngineConfig/support.d.ts +22 -0
  28. package/dist/QueryEngineConfig/support.js +117 -0
  29. package/dist/QueryEngineConfig/supportedFeature.d.ts +2 -0
  30. package/dist/QueryEngineConfig/supportedFeature.js +8 -0
  31. package/dist/QueryEngineConfig/types.d.ts +53 -0
  32. package/dist/QueryEngineConfig/types.js +2 -0
  33. package/dist/VizzlyConfig/constants.d.ts +13 -0
  34. package/dist/VizzlyConfig/constants.js +87 -0
  35. package/dist/VizzlyConfig/index.d.ts +2 -0
  36. package/dist/VizzlyConfig/index.js +8 -0
  37. package/dist/VizzlyConfig/validate.d.ts +10 -0
  38. package/dist/VizzlyConfig/validate.js +183 -0
  39. package/dist/errors/VizzlyConfigValidationError.d.ts +2 -0
  40. package/dist/errors/VizzlyConfigValidationError.js +6 -0
  41. package/dist/index.d.ts +2 -1
  42. package/dist/index.js +26 -3
  43. package/package.json +7 -2
@@ -0,0 +1,22 @@
1
+ import { NormalizedDataType } from '@vizzly/sqlbuilder-public';
2
+ import { QueryEngineConfig, SupportedAggregateOption, SupportedAggregates, SupportedOperators, SupportedTimeFunctions, SupportedTimeTruncFunctions, SupportedTransformationFunctions } from './types';
3
+ declare const vizzlySupportedTransformationFunctions: SupportedTransformationFunctions;
4
+ export declare const supportedTransformationFunctions: (keys?: Array<keyof typeof vizzlySupportedTransformationFunctions>) => SupportedTransformationFunctions;
5
+ export declare const supportedAggregatesFunction: (queryEngineConfig: QueryEngineConfig, dataType: NormalizedDataType, supportedAggregateOptions?: SupportedAggregateOption[]) => SupportedAggregateOption[];
6
+ export declare const supportedOperators: (keys?: Array<string>) => SupportedOperators;
7
+ export declare const supportedTimeTruncFunctions: (keys?: Array<SupportedTimeFunctions>) => SupportedTimeTruncFunctions;
8
+ export declare const supportedAggregates: (keys?: Array<string>) => SupportedAggregates;
9
+ export declare const isSupportedAggregateFunction: (supportedAggregateFunctions: SupportedAggregates, proposedFunction: string) => boolean;
10
+ export declare const isSupportedAggregate: (value: string | undefined, supportedAggregates: SupportedAggregates) => boolean;
11
+ export declare const isSupportedTimeTruncFunction: (supportedTimeFunctions: SupportedTimeTruncFunctions, proposedFunction: string) => boolean;
12
+ export declare const ALL_SUPPORTED_CONSTANTS: ({
13
+ namespace: string;
14
+ constants: SupportedOperators;
15
+ } | {
16
+ namespace: string;
17
+ constants: SupportedTimeTruncFunctions;
18
+ })[];
19
+ export declare const validOperatorsForField: (field: {
20
+ dataType: NormalizedDataType;
21
+ }, queryEngineConfig: QueryEngineConfig) => string[];
22
+ export {};
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validOperatorsForField = exports.ALL_SUPPORTED_CONSTANTS = exports.isSupportedTimeTruncFunction = exports.isSupportedAggregate = exports.isSupportedAggregateFunction = exports.supportedAggregates = exports.supportedTimeTruncFunctions = exports.supportedOperators = exports.supportedAggregatesFunction = exports.supportedTransformationFunctions = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const constants_1 = require("./constants");
6
+ const vizzlySupportedTransformationFunctions = {
7
+ round_to_0_dp: {
8
+ publicName: 'Round to 0dp',
9
+ validDataTypes: ['number'],
10
+ },
11
+ round_to_2_dp: {
12
+ publicName: 'Round to 2dp',
13
+ validDataTypes: ['number'],
14
+ },
15
+ };
16
+ const supportedTransformationFunctions = (keys) => {
17
+ const supportedAggregates = (0, lodash_1.cloneDeep)(vizzlySupportedTransformationFunctions);
18
+ if (!keys)
19
+ return supportedAggregates;
20
+ let supportedTimeDimensions = {};
21
+ keys.forEach((key) => {
22
+ if (!supportedAggregates[key])
23
+ throw `Transformation function ${key} is not managed by Vizzly`;
24
+ supportedTimeDimensions[key] = supportedAggregates[key];
25
+ });
26
+ return supportedTimeDimensions;
27
+ };
28
+ exports.supportedTransformationFunctions = supportedTransformationFunctions;
29
+ const supportedAggregatesFunction = (queryEngineConfig, dataType, supportedAggregateOptions) => {
30
+ const supportedAggregates = queryEngineConfig.supportedAggregates;
31
+ // Derive default order from supportedAggregates
32
+ const derivedDefaultOrder = Object.keys(supportedAggregates).filter((aggregateId) => supportedAggregates[aggregateId].validDataTypes.includes(dataType));
33
+ // supportedAggregateOptions?.forEach((option) => {
34
+ // if (!supportedAggregates.hasOwnProperty(option)) {
35
+ // logWarning(`Unsupported aggregate option: ${option} on ${dataType}`);
36
+ // }
37
+ // });
38
+ // Determine the order of aggregates to use
39
+ let orderToUse = supportedAggregateOptions && supportedAggregateOptions.length > 0
40
+ ? supportedAggregateOptions.filter((option) => derivedDefaultOrder.includes(option))
41
+ : derivedDefaultOrder;
42
+ // If no valid options found in supportedAggregateOptions, use derivedDefaultOrder
43
+ if (supportedAggregateOptions && supportedAggregateOptions.length > 0 && orderToUse.length === 0) {
44
+ orderToUse = derivedDefaultOrder;
45
+ }
46
+ // Return the aggregates in the order determined
47
+ return orderToUse;
48
+ };
49
+ exports.supportedAggregatesFunction = supportedAggregatesFunction;
50
+ const supportedOperators = (keys) => {
51
+ const supportedOperators = (0, lodash_1.cloneDeep)(constants_1.supportedOperatorsConstants);
52
+ if (!keys)
53
+ return supportedOperators;
54
+ let supportedOperatorsSubset = {};
55
+ keys.forEach((key) => {
56
+ if (!constants_1.supportedOperatorsConstants[key])
57
+ throw `Operator ${key} not managed by Vizzly`;
58
+ supportedOperatorsSubset[key] = constants_1.supportedOperatorsConstants[key];
59
+ });
60
+ return supportedOperatorsSubset;
61
+ };
62
+ exports.supportedOperators = supportedOperators;
63
+ const supportedTimeTruncFunctions = (keys) => {
64
+ const supportedAggregates = (0, lodash_1.cloneDeep)(constants_1.timeDimensionsConstants);
65
+ if (!keys)
66
+ return supportedAggregates;
67
+ let supportedTimeDimensions = {};
68
+ keys.forEach((key) => {
69
+ if (!supportedAggregates[key])
70
+ throw `Time trunc function ${key} not managed by Vizzly`;
71
+ supportedTimeDimensions[key] = supportedAggregates[key];
72
+ });
73
+ return supportedTimeDimensions;
74
+ };
75
+ exports.supportedTimeTruncFunctions = supportedTimeTruncFunctions;
76
+ // Aggregates supported by the Vizzly query engine.
77
+ const supportedAggregates = (keys) => {
78
+ const supportedAggregates = (0, lodash_1.cloneDeep)(constants_1.supportedAggregatesConstants);
79
+ if (!keys)
80
+ return supportedAggregates;
81
+ let supportedAggregatesSubset = {};
82
+ keys.forEach((key) => {
83
+ if (!supportedAggregates[key])
84
+ throw `Aggregate ${key} not managed by Vizzly`;
85
+ supportedAggregatesSubset[key] = supportedAggregates[key];
86
+ });
87
+ return supportedAggregatesSubset;
88
+ };
89
+ exports.supportedAggregates = supportedAggregates;
90
+ const isSupportedAggregateFunction = (supportedAggregateFunctions, proposedFunction) => {
91
+ return [...Object.keys(supportedAggregateFunctions), 'none'].includes(proposedFunction);
92
+ };
93
+ exports.isSupportedAggregateFunction = isSupportedAggregateFunction;
94
+ const isSupportedAggregate = (value, supportedAggregates) => {
95
+ if (typeof value !== 'string') {
96
+ return false;
97
+ }
98
+ return supportedAggregates.hasOwnProperty(value);
99
+ };
100
+ exports.isSupportedAggregate = isSupportedAggregate;
101
+ const isSupportedTimeTruncFunction = (supportedTimeFunctions, proposedFunction) => {
102
+ return [...Object.keys(supportedTimeFunctions), 'none'].includes(proposedFunction);
103
+ };
104
+ exports.isSupportedTimeTruncFunction = isSupportedTimeTruncFunction;
105
+ exports.ALL_SUPPORTED_CONSTANTS = [
106
+ { namespace: 'config.supported_operator', constants: constants_1.supportedOperatorsConstants },
107
+ { namespace: 'config.supported_aggregate', constants: constants_1.supportedAggregatesConstants },
108
+ { namespace: 'config.supported_time', constants: constants_1.timeDimensionsConstants },
109
+ ];
110
+ const validOperatorsForField = (field, queryEngineConfig) => {
111
+ let operatorIds = [...Object.keys(queryEngineConfig.supportedOperators)];
112
+ operatorIds = operatorIds.filter((operatorId) => {
113
+ return constants_1.supportedOperatorsConstants[operatorId].validDataTypes.includes(field.dataType);
114
+ });
115
+ return operatorIds;
116
+ };
117
+ exports.validOperatorsForField = validOperatorsForField;
@@ -0,0 +1,2 @@
1
+ import { SupportedFeature } from './types';
2
+ export declare const hasSupportedFeature: (features: SupportedFeature[] | undefined, featuresToCheck: SupportedFeature | SupportedFeature[]) => boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasSupportedFeature = void 0;
4
+ const hasSupportedFeature = (features, featuresToCheck) => {
5
+ const checkArray = Array.isArray(featuresToCheck) ? featuresToCheck : [featuresToCheck];
6
+ return checkArray.some((feature) => features === null || features === void 0 ? void 0 : features.includes(feature));
7
+ };
8
+ exports.hasSupportedFeature = hasSupportedFeature;
@@ -0,0 +1,53 @@
1
+ import { NormalizedDataType } from '@vizzly/sqlbuilder-public';
2
+ export type SupportedFeature = 'subquery' | 'simpleMaths' | 'aggregateMaths' | 'switchField' | 'configManagerUi' | 'roundedNumbers' | 'sqlDefinedDataSet' | 'encryptedDashboards' | 'sqlViews';
3
+ export type QueryEngineConfig = {
4
+ origin?: 'in-browser' | 'query-engine' | 'custom';
5
+ supportedFeatures: SupportedFeature[];
6
+ supportedOperators: SupportedOperators;
7
+ supportedAggregates: SupportedAggregates;
8
+ supportedTimeTruncFunctions: SupportedTimeTruncFunctions;
9
+ supportedTransformationFunctions: SupportedTransformationFunctions;
10
+ };
11
+ export type QueryEngineEndpoint = string | {
12
+ endpoint: string;
13
+ dynamicConfig?: Object;
14
+ customHeaders?: () => {
15
+ [headerKey: string]: string;
16
+ };
17
+ };
18
+ export type SupportedFunction = {
19
+ publicName: string;
20
+ validDataTypes: Array<Exclude<NormalizedDataType, 'date_time'>>;
21
+ };
22
+ export type SupportedTransformationFunctions = {
23
+ [id: string]: SupportedFunction;
24
+ };
25
+ export type SupportedTimeTruncFunction = {
26
+ publicName: string;
27
+ /**
28
+ * Once from the query engine, what is
29
+ * the most appropriate format for it
30
+ * to be displayed in?
31
+ * */
32
+ dateFormat: DateTimeFormat | (string & {});
33
+ };
34
+ export type SupportedTimeTruncFunctions = {
35
+ [key: string]: SupportedTimeTruncFunction;
36
+ };
37
+ export type SupportedOperator = {
38
+ publicName: string;
39
+ validDataTypes: Array<'number' | 'boolean' | 'string' | 'date_time' | 'string[]'>;
40
+ };
41
+ export type SupportedOperators = {
42
+ [id: string]: SupportedOperator;
43
+ };
44
+ export type DateTimeFormat = 'DD/MM/YYYY' | 'MM/DD/YYYY' | 'DD-MM-YYYY' | 'MM-DD-YYYY' | 'DD MMMM YYYY, hh:mm' | 'dddd DD MMMM YYYY, hh:mm' | 'hh:mm' | 'hh:mm:ss' | 'DD MMMM YYYY' | 'MMMM YYYY' | 'YYYY' | 'YYYY-MM-DD[T]HH:mm:ss' | 'quarter' | 'week';
45
+ export type SupportedAggregate = {
46
+ publicName: string;
47
+ validDataTypes: Array<NormalizedDataType>;
48
+ };
49
+ export type SupportedAggregates = {
50
+ [id: string]: SupportedAggregate;
51
+ };
52
+ export type SupportedAggregateOption = string;
53
+ export type SupportedTimeFunctions = 'minute' | 'hour' | 'second' | 'week' | 'quarter' | 'year' | 'month' | 'day';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { Client, NormalizedDataType } from '@vizzly/sqlbuilder-public';
2
+ export declare const SUPPORTED_CLIENTS: Array<Client>;
3
+ export declare const NATIVE_DATA_TYPES: {
4
+ [client: string]: {
5
+ [dT: string]: string;
6
+ };
7
+ };
8
+ export declare const vizzlyToPossibleNativeDataTypes: (client: Client, dataType: NormalizedDataType) => string[];
9
+ export declare const ENVIRONMENT_VARIABLES_TO_REQUIRED: {
10
+ [client: string]: {
11
+ [key: string]: boolean;
12
+ };
13
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENVIRONMENT_VARIABLES_TO_REQUIRED = exports.vizzlyToPossibleNativeDataTypes = exports.NATIVE_DATA_TYPES = exports.SUPPORTED_CLIENTS = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const sqlbuilder_public_1 = require("@vizzly/sqlbuilder-public");
6
+ exports.SUPPORTED_CLIENTS = [
7
+ 'bigquery',
8
+ 'mariadb',
9
+ 'postgres',
10
+ 'snowflake',
11
+ 'mysql',
12
+ 'microsoftSQLServer',
13
+ 'redshift',
14
+ ];
15
+ const buildDataTypeMapping = (client) => (0, lodash_1.reduce)(Object.keys(sqlbuilder_public_1.NATIVE_DATA_TYPES_DATABASE[client]), (acc, dT) => (Object.assign(Object.assign({}, acc), { [dT]: dT })), {});
16
+ exports.NATIVE_DATA_TYPES = {
17
+ mysql: buildDataTypeMapping('mysql'),
18
+ snowflake: buildDataTypeMapping('snowflake'),
19
+ postgres: buildDataTypeMapping('postgres'),
20
+ redshift: buildDataTypeMapping('redshift'),
21
+ mariadb: buildDataTypeMapping('mariadb'),
22
+ bigquery: buildDataTypeMapping('bigquery'),
23
+ microsoftSQLServer: buildDataTypeMapping('microsoftSQLServer'),
24
+ };
25
+ const vizzlyToPossibleNativeDataTypes = (client, dataType) => {
26
+ let nativeDataTypes = [];
27
+ Object.entries(sqlbuilder_public_1.NATIVE_DATA_TYPES_DATABASE[client]).forEach(([nativeDataType, { normalizedType }]) => {
28
+ if (normalizedType == dataType)
29
+ nativeDataTypes = [...nativeDataTypes, nativeDataType];
30
+ });
31
+ return nativeDataTypes;
32
+ };
33
+ exports.vizzlyToPossibleNativeDataTypes = vizzlyToPossibleNativeDataTypes;
34
+ exports.ENVIRONMENT_VARIABLES_TO_REQUIRED = {
35
+ postgres: {
36
+ VIZZLY_POSTGRES_PASSWORD: true,
37
+ VIZZLY_POSTGRES_DATABASE: true,
38
+ VIZZLY_POSTGRES_USER: true,
39
+ VIZZLY_POSTGRES_HOST: true,
40
+ VIZZLY_POSTGRES_PORT: false,
41
+ },
42
+ mariadb: {
43
+ VIZZLY_MARIADB_PASSWORD: true,
44
+ VIZZLY_MARIADB_DATABASE: true,
45
+ VIZZLY_MARIADB_USER: true,
46
+ VIZZLY_MARIADB_HOST: true,
47
+ VIZZLY_MARIADB_PORT: false,
48
+ },
49
+ mysql: {
50
+ VIZZLY_MYSQL_PASSWORD: true,
51
+ VIZZLY_MYSQL_DATABASE: true,
52
+ VIZZLY_MYSQL_USER: true,
53
+ VIZZLY_MYSQL_HOST: true,
54
+ VIZZLY_MYSQL_PORT: false,
55
+ },
56
+ elasticsearch: {
57
+ VIZZLY_ELASTICSEARCH_CLOUD_ID: true,
58
+ VIZZLY_ELASTICSEARCH_API_KEY: true,
59
+ VIZZLY_ELASTICSEARCH_NODE: true,
60
+ VIZZLY_ELASTICSEARCH_USERNAME: true,
61
+ VIZZLY_ELASTICSEARCH_PASSWORD: true,
62
+ VIZZLY_ELASTICSEARCH_API_KEY_ID: true,
63
+ },
64
+ bigquery: {
65
+ VIZZLY_BIGQUERY_PROJECT_ID: true,
66
+ VIZZLY_BIGQUERY_REGION: true,
67
+ VIZZLY_BIGQUERY_KEY_FILENAME: false,
68
+ VIZZLY_BIGQUERY_CREDENTIALS: false,
69
+ },
70
+ snowflake: {
71
+ VIZZLY_SNOWFLAKE_PASSWORD: true,
72
+ VIZZLY_SNOWFLAKE_DATABASE: false,
73
+ VIZZLY_SNOWFLAKE_USERNAME: true,
74
+ VIZZLY_SNOWFLAKE_ACCOUNT: true,
75
+ VIZZLY_SNOWFLAKE_WAREHOUSE: true,
76
+ VIZZLY_SNOWFLAKE_ROLE: true,
77
+ VIZZLY_SNOWFLAKE_SCHEMA: false,
78
+ VIZZLY_SNOWFLAKE_SESSION_KEEP_ALIVE: false,
79
+ },
80
+ microsoftSQLServer: {
81
+ VIZZLY_MICROSOFT_SQL_SERVER_PASSWORD: true,
82
+ VIZZLY_MICROSOFT_SQL_SERVER_DATABASE: true,
83
+ VIZZLY_MICROSOFT_SQL_SERVER_USER: true,
84
+ VIZZLY_MICROSOFT_SQL_SERVER_HOST: true,
85
+ VIZZLY_MICROSOFT_SQL_SERVER_PORT: false,
86
+ },
87
+ };
@@ -0,0 +1,2 @@
1
+ import validate, { ConfigValidationOptions } from './validate';
2
+ export { validate, ConfigValidationOptions };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.validate = void 0;
7
+ const validate_1 = __importDefault(require("./validate"));
8
+ exports.validate = validate_1.default;
@@ -0,0 +1,10 @@
1
+ import Joi from '@vizzly/joi';
2
+ import { Client } from '@vizzly/sqlbuilder-public';
3
+ export declare const ALLOWED_ID_REGEX: RegExp;
4
+ export declare const ID_REGEX_ERROR_MESSAGE = "IDs must only use alpha numeric characters and _";
5
+ export type ConfigValidationOptions = {
6
+ onlyClient?: Client;
7
+ checkConnectionSpecificDataSets?: boolean;
8
+ };
9
+ declare const _default: (config: unknown, options?: Partial<ConfigValidationOptions>) => Joi.ValidationResult;
10
+ export default _default;
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ID_REGEX_ERROR_MESSAGE = exports.ALLOWED_ID_REGEX = void 0;
7
+ const joi_1 = __importDefault(require("@vizzly/joi"));
8
+ const getQueryEngineConfig_1 = require("../QueryEngineConfig/getQueryEngineConfig");
9
+ const constants_1 = require("./constants");
10
+ const support_1 = require("../QueryEngineConfig/support");
11
+ const constants_2 = require("../QueryEngineConfig/constants");
12
+ const REDACT_KEYS_FROM_ERROR_MESSAGE = ['unencryptedCredentials', 'encryptedCredentials'];
13
+ const SUPPORTED_SECURE_FILTER_OPS = Object.keys(constants_2.supportedOperatorsConstants);
14
+ const SUPPORTED_ALLOWED_GRANULARITIES = ['second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
15
+ const SUPPORTED_JOINS = ['rightJoin', 'leftJoin', 'innerJoin', 'outerJoin', 'leftOuterJoin', 'rightOuterJoin'];
16
+ exports.ALLOWED_ID_REGEX = /^[a-zA-Z0-9_+/=-]*$/;
17
+ exports.ID_REGEX_ERROR_MESSAGE = 'IDs must only use alpha numeric characters and _';
18
+ const DEFAULT_SCHEMA_OPTIONS = { checkConnectionSpecificDataSets: true };
19
+ const joiOptions = { abortEarly: false, allowUnknown: true };
20
+ const fieldSchema = (client) => {
21
+ return joi_1.default.object({
22
+ id: joi_1.default.string()
23
+ .required()
24
+ .regex(exports.ALLOWED_ID_REGEX, exports.ID_REGEX_ERROR_MESSAGE)
25
+ .description('A unique identifier for this field. It should not change unless the meaning of the field, or the data type has changed.'),
26
+ publicName: joi_1.default.string()
27
+ .optional()
28
+ .allow('')
29
+ .description('The name of this field that you want your users to see. This can be changed as much as you like without causing a breaking change.'),
30
+ address: joi_1.default.array()
31
+ .items(joi_1.default.string())
32
+ .optional()
33
+ .description('The address of the column in your database. For example; ["database_name", "table_name", "column_name"] or for BigQuery; ["bigquery project id", "bigquery data set id", "table name", "column name"]'),
34
+ description: joi_1.default.string()
35
+ .allow('')
36
+ .optional()
37
+ .max(110)
38
+ .description('A description of what the purpose of this data set is'),
39
+ sql: joi_1.default.string()
40
+ .optional()
41
+ .description('Provide a SQL definition of the field, instead of a table & name combination.'),
42
+ dataType: joi_1.default.valid(...Object.values(constants_1.NATIVE_DATA_TYPES[client])).required(),
43
+ canBeDimension: joi_1.default.boolean().optional(),
44
+ canBeMeasure: joi_1.default.boolean().optional(),
45
+ canBeUsedInSort: joi_1.default.boolean().optional(),
46
+ allowedGranularities: joi_1.default.array()
47
+ .items(joi_1.default.string().valid(...SUPPORTED_ALLOWED_GRANULARITIES))
48
+ .optional(),
49
+ allowedOperators: joi_1.default.alternatives()
50
+ .conditional('..dataType', {
51
+ is: joi_1.default.string().valid(...(0, constants_1.vizzlyToPossibleNativeDataTypes)(client, 'string')),
52
+ then: joi_1.default.array()
53
+ .items(joi_1.default.string().valid(...(0, support_1.validOperatorsForField)({ dataType: 'string' }, (0, getQueryEngineConfig_1.getQueryEngineConfig)(client))))
54
+ .description('For fields that have a string data type.'),
55
+ })
56
+ .conditional('..dataType', {
57
+ is: joi_1.default.string().valid(...(0, constants_1.vizzlyToPossibleNativeDataTypes)(client, 'number')),
58
+ then: joi_1.default.array()
59
+ .items(joi_1.default.string().valid(...(0, support_1.validOperatorsForField)({ dataType: 'number' }, (0, getQueryEngineConfig_1.getQueryEngineConfig)(client))))
60
+ .description('For fields that have a number data type.'),
61
+ })
62
+ .conditional('..dataType', {
63
+ is: joi_1.default.string().valid(...(0, constants_1.vizzlyToPossibleNativeDataTypes)(client, 'date_time')),
64
+ then: joi_1.default.array()
65
+ .items(joi_1.default.valid(...(0, support_1.validOperatorsForField)({ dataType: 'date_time' }, (0, getQueryEngineConfig_1.getQueryEngineConfig)(client))))
66
+ .description('For fields that have a date time data type.'),
67
+ })
68
+ .conditional('..dataType', {
69
+ is: joi_1.default.string().valid(...(0, constants_1.vizzlyToPossibleNativeDataTypes)(client, 'boolean')),
70
+ then: joi_1.default.array()
71
+ .items(joi_1.default.string().valid(...(0, support_1.validOperatorsForField)({ dataType: 'boolean' }, (0, getQueryEngineConfig_1.getQueryEngineConfig)(client))))
72
+ .description('For fields that have a boolean data type.'),
73
+ })
74
+ .conditional('..dataType', {
75
+ is: joi_1.default.string().valid(...(0, constants_1.vizzlyToPossibleNativeDataTypes)(client, 'string[]')),
76
+ then: joi_1.default.array()
77
+ .items(joi_1.default.string().valid(...(0, support_1.validOperatorsForField)({ dataType: 'string[]' }, (0, getQueryEngineConfig_1.getQueryEngineConfig)(client))))
78
+ .description('For fields that have a string array data type.'),
79
+ })
80
+ .optional(),
81
+ });
82
+ };
83
+ const sqlJoinSchema = joi_1.default.object({
84
+ type: joi_1.default.string()
85
+ .valid(...SUPPORTED_JOINS)
86
+ .required(),
87
+ left: joi_1.default.array().items(joi_1.default.string()).required(),
88
+ right: joi_1.default.array().items(joi_1.default.string()).required(),
89
+ });
90
+ const secureFilterGuardSchema = joi_1.default.object({
91
+ fieldId: joi_1.default.string().required(),
92
+ op: joi_1.default.string()
93
+ .valid(...SUPPORTED_SECURE_FILTER_OPS)
94
+ .required(),
95
+ });
96
+ const baseDataSetSchema = (fieldSchema) => ({
97
+ id: joi_1.default.string()
98
+ .required()
99
+ .regex(exports.ALLOWED_ID_REGEX, exports.ID_REGEX_ERROR_MESSAGE)
100
+ .description('A unique ID for the data set. This should not change unless the meaning of the data set represents changes.'),
101
+ connectionId: joi_1.default.string().optional(),
102
+ hide: joi_1.default.boolean().optional().description('Hide the data set from the dashboard.'),
103
+ name: joi_1.default.string()
104
+ .required()
105
+ .description('A public name for the data set. This can change as much as you like without causing a breaking change.'),
106
+ description: joi_1.default.string().allow('').optional().max(110).description('A description of what this field represents'),
107
+ sql: joi_1.default.string()
108
+ .optional()
109
+ .description('Optionally define the data set using a SQL statement. If used, the `table` value for each field should equal `vizzly_data_set`.'),
110
+ testParameters: joi_1.default.string()
111
+ .optional()
112
+ .description('Test parameters that are used when creating SQL backed data sets. This is a stringified JSON object.'),
113
+ preAggregated: joi_1.default.alternatives(joi_1.default.array().items(joi_1.default.string()).description('Array of data set IDs relied on by the pre-aggregated data set'), joi_1.default.boolean()
114
+ .allow(false)
115
+ .description('Only `False` is a valid boolean option. For truthy values, provide an array of data set IDs'))
116
+ .optional()
117
+ .description('Optional - For pre-aggregated data sets or SQL views, provide a list of data sets that are relied upon.'),
118
+ fields: joi_1.default.array().min(1).items(fieldSchema).unique('id').message('Field IDs must be unique').required(),
119
+ secureFilterGuards: joi_1.default.array().items(secureFilterGuardSchema).optional(),
120
+ });
121
+ const sqlDataSetSchema = (fieldSchema) => joi_1.default.object(Object.assign(Object.assign({}, baseDataSetSchema(fieldSchema)), { joins: joi_1.default.array()
122
+ .items(sqlJoinSchema)
123
+ .unique('right')
124
+ .message('A table cannot be referenced in a right join multiple times.')
125
+ .optional() }));
126
+ /**
127
+ * Return schema to validate a schema. Either
128
+ * alternatives where any is valid. Or a specific one that
129
+ * has been requested.
130
+ * */
131
+ const alternativeDataSetSchemas = (options) => {
132
+ if (options.onlyClient)
133
+ return sqlDataSetSchema(fieldSchema(options.onlyClient));
134
+ return joi_1.default.alternatives(...constants_1.SUPPORTED_CLIENTS.map((client) => sqlDataSetSchema(fieldSchema(client))));
135
+ };
136
+ const configSchema = (fullObj, options) => joi_1.default.object({
137
+ version: joi_1.default.number(),
138
+ connections: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.object({
139
+ name: joi_1.default.string().allow(''),
140
+ client: joi_1.default.string().allow(...constants_1.SUPPORTED_CLIENTS),
141
+ encryptedCredentials: joi_1.default.string().optional(),
142
+ unencryptedCredentials: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.object()).optional(),
143
+ })),
144
+ dataSets: joi_1.default.array()
145
+ .items(options.checkConnectionSpecificDataSets
146
+ ? joi_1.default.object().custom((value) => {
147
+ var _a, _b;
148
+ const connectionId = value.connectionId || '___vizzly_default_conn';
149
+ 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 Error(`Data sets must be linked to a connection using a 'connectionId' property.`);
152
+ const validationResult = sqlDataSetSchema(fieldSchema(clientType)).validate(value, joiOptions);
153
+ if (validationResult.error)
154
+ throw validationResult.error;
155
+ return value;
156
+ }, 'Data sets linked to connections')
157
+ : alternativeDataSetSchemas(options))
158
+ .unique('id')
159
+ .message('dataSet[x].id must be unique.')
160
+ .required(),
161
+ executableDashboardConfigForPDF: joi_1.default.string()
162
+ .allow(null)
163
+ .optional()
164
+ .description('JavaScript dashboard config for server-side generated PDFs'),
165
+ publicKeys: joi_1.default.array().items(joi_1.default.string()).optional(),
166
+ sqlViews: joi_1.default.object()
167
+ .pattern(joi_1.default.string(), joi_1.default.object({ name: joi_1.default.string().required(), sql: joi_1.default.string().allow('').required() }))
168
+ .optional(),
169
+ });
170
+ exports.default = (config, options = {}) => {
171
+ const validationResult = configSchema(config, Object.assign(Object.assign({}, DEFAULT_SCHEMA_OPTIONS), options)).validate(config, joiOptions);
172
+ if (validationResult.error) {
173
+ validationResult.error.details.map((detail) => {
174
+ var _a, _b;
175
+ if (REDACT_KEYS_FROM_ERROR_MESSAGE.includes(((_a = detail.context) === null || _a === void 0 ? void 0 : _a.key) || '')) {
176
+ if ((_b = detail.context) === null || _b === void 0 ? void 0 : _b.value) {
177
+ detail.context.value = '-- VIZZLY REDACTED --';
178
+ }
179
+ }
180
+ });
181
+ }
182
+ return validationResult;
183
+ };
@@ -0,0 +1,2 @@
1
+ export declare class VizzlyConfigValidationError extends Error {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VizzlyConfigValidationError = void 0;
4
+ class VizzlyConfigValidationError extends Error {
5
+ }
6
+ exports.VizzlyConfigValidationError = VizzlyConfigValidationError;
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export declare const hi: () => void;
1
+ export * as QueryEngineConfig from './QueryEngineConfig';
2
+ export * as VizzlyConfig from './VizzlyConfig';
package/dist/index.js CHANGED
@@ -1,5 +1,28 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hi = void 0;
4
- const hi = () => console.log('hi');
5
- exports.hi = hi;
26
+ exports.VizzlyConfig = exports.QueryEngineConfig = void 0;
27
+ exports.QueryEngineConfig = __importStar(require("./QueryEngineConfig"));
28
+ exports.VizzlyConfig = __importStar(require("./VizzlyConfig"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly/semantic-layer-public",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,9 +18,14 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/jest": "^29.5.12",
21
+ "@types/uuid": "^9.0.8",
21
22
  "jest": "^29.7.0",
22
23
  "prettier": "^3.2.5",
23
24
  "ts-jest": "^29.1.2",
24
- "typescript": "^5.4.5"
25
+ "typescript": "^5.4.5",
26
+ "uuid": "^9.0.1"
27
+ },
28
+ "dependencies": {
29
+ "@vizzly/sqlbuilder-public": "^0.0.63"
25
30
  }
26
31
  }