@vizzly/semantic-layer-public 0.0.210 → 0.0.212

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.
@@ -0,0 +1 @@
1
+ export * from './upcast';
@@ -0,0 +1,17 @@
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);
@@ -0,0 +1,157 @@
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 {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
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 {};
@@ -0,0 +1,65 @@
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;
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ 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,8 +26,9 @@ 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.VizzlyConfig = exports.QueryEngineConfig = void 0;
29
+ exports.Query = 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,2 +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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly/semantic-layer-public",
3
- "version": "0.0.210",
3
+ "version": "0.0.212",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",