@vizzly/semantic-layer-public 0.0.213 → 0.0.215

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.
@@ -100,6 +100,10 @@ exports.timeDimensionsConstants = {
100
100
  publicName: 'Day of week',
101
101
  dateFormat: 'day_of_week_iso',
102
102
  },
103
+ monthOfYearOnly: {
104
+ publicName: 'Month of year',
105
+ dateFormat: 'month_of_year_only',
106
+ },
103
107
  dayOfMonthOnly: {
104
108
  publicName: 'Day of month',
105
109
  dateFormat: 'day_of_month',
@@ -2,3 +2,4 @@ export * from './getQueryEngineConfig';
2
2
  export * from './merge';
3
3
  export * as Constants from './constants';
4
4
  export * as Support from './support';
5
+ export * from './removeUnsupportedFeatures';
@@ -31,3 +31,4 @@ __exportStar(require("./getQueryEngineConfig"), exports);
31
31
  __exportStar(require("./merge"), exports);
32
32
  exports.Constants = __importStar(require("./constants"));
33
33
  exports.Support = __importStar(require("./support"));
34
+ __exportStar(require("./removeUnsupportedFeatures"), exports);
@@ -0,0 +1,12 @@
1
+ import { FrontendFeature, QueryEngineConfig } from './types';
2
+ /**
3
+ * Sometimes the query engine will support a feature which the dashboard does not.
4
+ * An example being returning a number that represents a month of the year. However
5
+ * the dashboard will not know how to format this - e.g convert the number 1 into "January"
6
+ * as a number formatting option.
7
+ *
8
+ * Therefore the query engine config should be modified to only add in features which the
9
+ * dashboard can understand. This is the function that takes a list of supported functions
10
+ * from the frontend, adjusts the query engine config and then returns it.
11
+ * */
12
+ export declare const removeUnsupportedFeatures: (config: QueryEngineConfig, frontendSupportedFeatures: FrontendFeature[]) => QueryEngineConfig;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeUnsupportedFeatures = void 0;
4
+ const lodash_1 = require("lodash");
5
+ /**
6
+ * Sometimes the query engine will support a feature which the dashboard does not.
7
+ * An example being returning a number that represents a month of the year. However
8
+ * the dashboard will not know how to format this - e.g convert the number 1 into "January"
9
+ * as a number formatting option.
10
+ *
11
+ * Therefore the query engine config should be modified to only add in features which the
12
+ * dashboard can understand. This is the function that takes a list of supported functions
13
+ * from the frontend, adjusts the query engine config and then returns it.
14
+ * */
15
+ const removeUnsupportedFeatures = (config, frontendSupportedFeatures) => {
16
+ const newConfig = (0, lodash_1.cloneDeep)(config);
17
+ if (!frontendSupportedFeatures.includes('formatter:monthOfYearOnly')) {
18
+ delete newConfig['supportedTimeTruncFunctions']['monthOfYearOnly'];
19
+ }
20
+ return newConfig;
21
+ };
22
+ exports.removeUnsupportedFeatures = removeUnsupportedFeatures;
@@ -29,6 +29,7 @@ const queryEngineConfig = () => ({
29
29
  'dayOfWeekOnly',
30
30
  'weekOfYearOnly',
31
31
  'hourOfDayOnly',
32
+ 'monthOfYearOnly',
32
33
  ]),
33
34
  supportedAggregates: (0, support_1.supportedAggregates)([
34
35
  'sum',
@@ -50,4 +50,14 @@ export type SupportedAggregates = {
50
50
  [id: string]: SupportedAggregate;
51
51
  };
52
52
  export type SupportedAggregateOption = string;
53
- export type SupportedTimeFunctions = 'minute' | 'hour' | 'second' | 'week' | 'quarter' | 'year' | 'month' | 'day' | 'dayOfMonthOnly' | 'dayOfWeekOnly' | 'hourOfDayOnly' | 'weekOfYearOnly';
53
+ export type SupportedTimeFunctions = 'minute' | 'hour' | 'second' | 'week' | 'quarter' | 'year' | 'month' | 'day' | 'dayOfMonthOnly' | 'dayOfWeekOnly' | 'hourOfDayOnly' | 'weekOfYearOnly' | 'monthOfYearOnly';
54
+ /**
55
+ * Sometimes the query engine will support a feature which the dashboard does not.
56
+ * An example being returning a number that represents a month of the year. However
57
+ * the dashboard will not know how to format this - e.g convert the number 1 into "January"
58
+ * as a number formatting option.
59
+ *
60
+ * Therefore the query engine config should be modified to only add in features which the
61
+ * dashboard can understand. Listed here are the definitions of features which are supported.
62
+ * */
63
+ export type FrontendFeature = 'formatter:monthOfYearOnly';
@@ -25,6 +25,7 @@ const SUPPORTED_ALLOWED_GRANULARITIES = [
25
25
  'dayOfWeekOnly',
26
26
  'weekOfYearOnly',
27
27
  'hourOfDayOnly',
28
+ 'monthOfYearOnly',
28
29
  ];
29
30
  const SUPPORTED_JOINS = ['rightJoin', 'leftJoin', 'innerJoin', 'outerJoin', 'leftOuterJoin', 'rightOuterJoin'];
30
31
  exports.ALLOWED_ID_REGEX = /^[a-zA-Z0-9_+:\/=\-\s]*$/;
package/dist/index.d.ts CHANGED
@@ -2,4 +2,3 @@ export * as QueryEngineConfig from './QueryEngineConfig';
2
2
  export * as VizzlyConfig from './VizzlyConfig';
3
3
  export * from './types';
4
4
  export * from './timezones';
5
- export * as Query from './Query';
package/dist/index.js CHANGED
@@ -26,9 +26,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Query = exports.VizzlyConfig = exports.QueryEngineConfig = void 0;
29
+ exports.VizzlyConfig = exports.QueryEngineConfig = void 0;
30
30
  exports.QueryEngineConfig = __importStar(require("./QueryEngineConfig"));
31
31
  exports.VizzlyConfig = __importStar(require("./VizzlyConfig"));
32
32
  __exportStar(require("./types"), exports);
33
33
  __exportStar(require("./timezones"), exports);
34
- exports.Query = __importStar(require("./Query"));
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export type OriginId = 'direct' | 'environment' | 'vizzly_api' | 'github' | 'remote' | 's3' | 'file' | 'encrypted_blob';
2
2
  export type * from './QueryEngineConfig/types';
3
- export type * from './Query/types';
3
+ export type * from './QueryEngineConfig/types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly/semantic-layer-public",
3
- "version": "0.0.213",
3
+ "version": "0.0.215",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,16 +18,13 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/jest": "^29.5.12",
21
- "@types/uuid": "^9.0.8",
22
21
  "jest": "^29.7.0",
23
- "prettier": "^3.2.5",
24
22
  "ts-jest": "^29.1.2",
25
23
  "typescript": "^5.4.5",
26
- "uuid": "^9.0.1",
27
- "@vizzly/sqlbuilder-public": "0.1.17"
24
+ "@vizzly/sqlbuilder-public": "0.1.24"
28
25
  },
29
26
  "peerDependencies": {
30
- "@vizzly/sqlbuilder-public": "0.1.17",
27
+ "@vizzly/sqlbuilder-public": "0.1.24",
31
28
  "@vizzly/joi": "^17.11.0"
32
29
  }
33
30
  }
@@ -1 +0,0 @@
1
- export * from './upcast';
@@ -1,17 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./upcast"), exports);
@@ -1,157 +0,0 @@
1
- export type SQLOperator = string;
2
- export type SQLTimeFunction = string;
3
- export type SQLAggregateFunction = string;
4
- export type SQLFunction = SQLTimeFunction | SQLAggregateFunction;
5
- type SQLMathsOp = '*' | '-' | '/' | '+';
6
- export type SQLSubQuery = SubQuery<SQLFunction, SQLOperator, SQLMathsOp>;
7
- export type SQLQuery = Query<SQLFunction, SQLOperator, SQLMathsOp>;
8
- export type SQLQueryFilterV0 = Query<SQLFunction, SQLOperator, SQLMathsOp, QueryNameSpace.FiltersV0>;
9
- export type SQLViewQuery = {
10
- sql: string;
11
- dataSetFilters: {
12
- [dataSetId: string]: SQLQuery['filter'];
13
- };
14
- };
15
- export declare namespace QueryNameSpace {
16
- type FiltersV0<SupportedFunction = SQLFunction, ComparisonOperator = SQLOperator, MathsOp = SQLMathsOp> = QueryNameSpace.Filter<QueryNameSpace.FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp>, ComparisonOperator>[][];
17
- /**
18
- * Which direction should the values be sorted in?
19
- */
20
- type SortDirection = 'asc' | 'desc';
21
- /**
22
- * ID of the field. This is the same ID that is used in
23
- * the data sets.
24
- */
25
- type Field = string;
26
- /**
27
- * Index of the measure to group the aggregates on.
28
- * Index starts from 0.
29
- */
30
- type Group = {
31
- index: number;
32
- };
33
- /**
34
- * Index of the measure to sort the results by.
35
- * Index starts from 0.
36
- */
37
- type Order = {
38
- index: number;
39
- direction: SortDirection;
40
- };
41
- /**
42
- * Defines filters to apply on the query. This can be thought of
43
- * as the WHERE clause in a SQL statement.
44
- */
45
- type Filter<Field, ComparisonOperator> = {
46
- field: Field | BasicType;
47
- op: ComparisonOperator;
48
- value: any;
49
- };
50
- type SecureFilterGuard<ComparisonOperator> = {
51
- fieldId: string;
52
- op: ComparisonOperator;
53
- };
54
- /**
55
- * Limit the number of results returned from the query.
56
- */
57
- type Limit = number;
58
- /**
59
- * Sets the offset of results to return.
60
- */
61
- type Offset = number;
62
- type Cases<SupportedFunction = string> = {
63
- returns: BasicType | {
64
- type: 'field';
65
- value: string;
66
- function: SupportedFunction;
67
- };
68
- filter: QueryNameSpace.FiltersV0;
69
- };
70
- type BasicType = {
71
- type: 'number';
72
- value: number;
73
- } | {
74
- type: 'string';
75
- value: string;
76
- } | {
77
- type: 'boolean';
78
- value: boolean | null;
79
- } | {
80
- type: 'null';
81
- };
82
- type ComplexType<SupportedFunction = string, ComparisonOperator = string, MathsOp = string, FilterVersion = RecursiveFilter> = {
83
- type: 'field';
84
- value: string;
85
- function: SupportedFunction;
86
- } | {
87
- type: 'switchField';
88
- value: {
89
- cases: Cases<SupportedFunction>[];
90
- };
91
- } | {
92
- type: 'subquery';
93
- value: SubQuery<SupportedFunction, ComparisonOperator, MathsOp, FilterVersion>;
94
- } | {
95
- type: 'maths';
96
- left: FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp>;
97
- op: MathsOp;
98
- right: FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp>;
99
- } | {
100
- type: 'date_maths';
101
- left: FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp>;
102
- op: string;
103
- right: FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp>;
104
- } | {
105
- type: 'function';
106
- function: SupportedFunction;
107
- value: FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp>;
108
- };
109
- type FieldDefinition<SupportedFunction = SQLFunction, ComparisonOperator = SQLOperator, MathsOp = SQLMathsOp, FilterVersion = RecursiveFilter> = BasicType | ComplexType<SupportedFunction, ComparisonOperator, MathsOp, FilterVersion>;
110
- }
111
- export type SubQuery<SupportedFunction = string, ComparisonOperator = string, MathsOp = string, FilterVersion = RecursiveFilter> = {
112
- measure: [QueryNameSpace.FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp>];
113
- filter: FilterVersion;
114
- };
115
- /** For when a query cannot be generalised into the TraditionalQuery format. We can provide a very specific query for a specific purpose. */
116
- type BasePreparedQuery<PreparedQueryType> = {
117
- type: 'preparedQuery';
118
- timeZone: TimeZone;
119
- preparedQueryType: PreparedQueryType;
120
- };
121
- /** A prepared query that returns unique values for a single array field */
122
- export type UniqueArrayValuesQuery<FilterVersion = RecursiveFilter> = BasePreparedQuery<'uniqueArrayValues'> & {
123
- dataSetId: string;
124
- fieldId: string;
125
- filter: FilterVersion;
126
- };
127
- export type PreAggregatedQuery<FilterVersion = RecursiveFilter> = BasePreparedQuery<'preAggregated'> & {
128
- dataSetId: string;
129
- filter: {
130
- [dataSetId: string]: FilterVersion;
131
- };
132
- };
133
- export type PreparedQuery = UniqueArrayValuesQuery | PreAggregatedQuery;
134
- export type PreparedQueryFilterV0 = UniqueArrayValuesQuery<QueryNameSpace.FiltersV0> | PreAggregatedQuery<QueryNameSpace.FiltersV0>;
135
- export type TimeZone = string;
136
- type Where = {
137
- type: 'where';
138
- value: QueryNameSpace.Filter<QueryNameSpace.FieldDefinition, SQLOperator>;
139
- };
140
- export type RecursiveFilter = {
141
- type: 'andWhere' | 'orWhere';
142
- value: Array<RecursiveFilter>;
143
- } | Where;
144
- /** Most commonly used query format. */
145
- export type Query<SupportedFunction = string, ComparisonOperator = string, MathsOp = string, FilterVersion = RecursiveFilter> = {
146
- type: 'query';
147
- timeZone: TimeZone;
148
- dataSetId: string;
149
- measure: Array<QueryNameSpace.FieldDefinition<SupportedFunction, ComparisonOperator, MathsOp, FilterVersion>>;
150
- filter: FilterVersion;
151
- order: Array<QueryNameSpace.Order>;
152
- group: Array<QueryNameSpace.Group>;
153
- limit?: QueryNameSpace.Limit;
154
- offset?: QueryNameSpace.Offset;
155
- };
156
- export type DataType = 'number' | 'boolean' | 'string' | 'date_time' | 'string[]';
157
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- import { PreparedQuery, PreparedQueryFilterV0, SQLQuery, SQLQueryFilterV0 } from './types';
2
- type ModernQueryTypes = SQLQuery | PreparedQuery;
3
- type PreviousQueryTypes = SQLQueryFilterV0 | PreparedQueryFilterV0;
4
- export declare const upCastQuery: (query: ModernQueryTypes | PreviousQueryTypes) => ModernQueryTypes;
5
- export {};
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upCastQuery = void 0;
4
- const lodash_1 = require("lodash");
5
- const upcastV0Filter = (filter) => {
6
- if ((0, lodash_1.isArray)(filter)) {
7
- return {
8
- type: 'orWhere',
9
- value: filter.map((andFilters) => ({
10
- type: 'andWhere',
11
- value: andFilters.map((filter) => {
12
- if (filter.field.type === 'subquery') {
13
- filter.field.value.filter = upcastV0Filter(filter.field.value.filter);
14
- }
15
- return {
16
- type: 'where',
17
- value: filter,
18
- };
19
- }),
20
- })),
21
- };
22
- }
23
- return filter;
24
- };
25
- const upcastMeasure = (metric) => {
26
- if (metric.type === 'subquery') {
27
- const newFilter = (0, lodash_1.isArray)(metric.value.filter) ? upcastV0Filter(metric.value.filter) : metric.value.filter;
28
- return Object.assign(Object.assign({}, metric), { value: {
29
- measure: metric.value.measure.map(upcastMeasure),
30
- filter: newFilter,
31
- } });
32
- }
33
- else if (metric.type === 'maths') {
34
- return {
35
- left: upcastMeasure(metric.left),
36
- right: upcastMeasure(metric.right),
37
- op: metric.op,
38
- type: metric.type,
39
- };
40
- }
41
- return metric;
42
- };
43
- const upCastPrimaryQuery = (query) => {
44
- return Object.assign(Object.assign({}, query), { measure: query.measure.map((metric) => {
45
- return upcastMeasure(metric);
46
- }), filter: (0, lodash_1.isArray)(query.filter) ? upcastV0Filter(query.filter) : query.filter });
47
- // throw 'Not implemented.';
48
- };
49
- const upCastPreparedQuery = (query) => {
50
- if (query.preparedQueryType === 'preAggregated') {
51
- const newFilter = {};
52
- Object.keys(query.filter).forEach((dataSetId) => {
53
- newFilter[dataSetId] = upcastV0Filter(query.filter[dataSetId]);
54
- });
55
- return Object.assign(Object.assign({}, query), { filter: newFilter });
56
- }
57
- return Object.assign(Object.assign({}, query), { filter: upcastV0Filter(query.filter) });
58
- };
59
- const upCastQuery = (query) => {
60
- if (query.type === 'query') {
61
- return upCastPrimaryQuery(query);
62
- }
63
- return upCastPreparedQuery(query);
64
- };
65
- exports.upCastQuery = upCastQuery;