@embeddable.com/sdk-core 0.2.0 → 2.0.0

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.
package/lib/index.cjs.js CHANGED
@@ -1,30 +1,112 @@
1
1
  'use strict';
2
2
 
3
- var axios = require('axios');
3
+ var path = require('node:path');
4
4
 
5
- var executeDataRequest = function (request, variables) {
6
- var _a, _b, _c;
5
+ var normalizeEntities = function (entities, _a) {
6
+ var _b = _a.mapFn, mapFn = _b === void 0 ? function (x) { return x; } : _b, _c = _a.filterFn, filterFn = _c === void 0 ? Boolean : _c;
7
+ if (!entities)
8
+ return undefined;
9
+ var filtered = entities.filter(filterFn);
10
+ if (filtered.length === 0)
11
+ return undefined;
12
+ return filtered.map(mapFn);
13
+ };
14
+ var getName = function (x) { return x.name; };
15
+ var validateOrderBy = function (orderByParam, dimensions, measures) {
16
+ var unknownDimensionsOrMeasures = [];
17
+ var dimensionAndMeasureNames = measures
18
+ .concat(dimensions)
19
+ .map(function (x) { return x.name; });
20
+ for (var _i = 0, orderByParam_1 = orderByParam; _i < orderByParam_1.length; _i++) {
21
+ var orderBy = orderByParam_1[_i];
22
+ var name_1 = orderBy.property.name;
23
+ if (dimensionAndMeasureNames.includes(name_1))
24
+ continue;
25
+ unknownDimensionsOrMeasures.push(name_1);
26
+ }
27
+ return unknownDimensionsOrMeasures;
28
+ };
29
+
30
+ var LOAD_DATA_EVENT = "embeddable-event:load-data";
31
+ var isLoadDataParams = function (ldp) {
32
+ return typeof ldp === "object" && "requestParams" in ldp && "dataLoader" in ldp;
33
+ };
34
+ var executeDataRequest = function (request, componentId, propertyName) {
35
+ var _a;
7
36
  if (!request.from)
8
- return Promise.reject('No dataset selected');
9
- var dimensions = (_a = request.dimensions) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
10
- var measures = (_b = request.measures) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
11
- var timeDimensions = (_c = request.timeDimensions) === null || _c === void 0 ? void 0 : _c.filter(function (d) { return d.dimension; });
37
+ return "No dataset selected";
38
+ var dimensions = normalizeEntities(request.dimensions, { mapFn: getName });
39
+ var measures = normalizeEntities(request.measures, { mapFn: getName });
40
+ var timeDimensions = normalizeEntities(request.timeDimensions, {
41
+ // @ts-expect-error
42
+ filterFn: getName,
43
+ });
44
+ var dimensionsOrMeasuresDefined = dimensions || measures || timeDimensions;
45
+ if (!dimensionsOrMeasuresDefined)
46
+ return "At least a dimension or a measure should be selected.";
47
+ var unknownDimensionsOrMeasures = validateOrderBy((_a = request.orderBy) !== null && _a !== void 0 ? _a : [], dimensions !== null && dimensions !== void 0 ? dimensions : [], measures !== null && measures !== void 0 ? measures : []);
48
+ if (unknownDimensionsOrMeasures.length) {
49
+ return "Cannot order by ".concat(unknownDimensionsOrMeasures.join(", "), " as no such ").concat(unknownDimensionsOrMeasures.length === 1 ? "property" : "properties", " has been loaded.");
50
+ }
12
51
  var query = {
13
52
  datasetId: request.from.datasetId,
14
- dimensions: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.length) ? dimensions : undefined,
15
- measures: (measures === null || measures === void 0 ? void 0 : measures.length) ? measures : undefined,
16
- timeDimensions: (timeDimensions === null || timeDimensions === void 0 ? void 0 : timeDimensions.length) ? timeDimensions : undefined,
17
- variableValues: variables
53
+ embeddableId: request.from.embeddableId,
54
+ dimensions: dimensions,
55
+ measures: measures,
56
+ timeDimensions: timeDimensions,
57
+ offset: request.offset,
58
+ limit: request.limit,
18
59
  };
19
- if (!query.dimensions && !query.timeDimensions)
20
- return Promise.reject('No dimension selected');
21
- return axios.post("".concat("https://api.embeddable.com", "/data-modeling/query"), query);
60
+ window.dispatchEvent(new CustomEvent(LOAD_DATA_EVENT, {
61
+ bubbles: false,
62
+ detail: {
63
+ query: query,
64
+ componentId: componentId,
65
+ propertyName: propertyName,
66
+ },
67
+ }));
22
68
  };
23
69
  var loadData = function (requestParams) { return ({
24
70
  requestParams: requestParams,
25
- dataLoader: executeDataRequest
71
+ dataLoader: executeDataRequest,
26
72
  }); };
27
73
 
74
+ var defineConfig = function (_a) {
75
+ var plugins = _a.plugins;
76
+ var coreRoot = path.resolve(__dirname, "..");
77
+ var clientRoot = process.cwd();
78
+ return {
79
+ core: {
80
+ rootDir: coreRoot,
81
+ templatesDir: path.resolve(coreRoot, "templates"),
82
+ configsDir: path.resolve(coreRoot, "configs"),
83
+ },
84
+ client: {
85
+ rootDir: clientRoot,
86
+ buildDir: path.resolve(clientRoot, ".embeddable-build"),
87
+ srcDir: path.resolve(clientRoot, "src"),
88
+ tmpDir: path.resolve(clientRoot, ".embeddable-tmp"),
89
+ componentDir: path.resolve(clientRoot, ".embeddable-build", "component"),
90
+ stencilBuild: path.resolve(clientRoot, ".embeddable-build", "dist", "embeddable-wrapper"),
91
+ archiveFile: path.resolve(clientRoot, "embeddable-build.zip"),
92
+ },
93
+ outputOptions: {
94
+ typesEntryPointFilename: "embeddable-types-entry-point.js",
95
+ },
96
+ plugins: plugins,
97
+ };
98
+ };
99
+
100
+ var getOperationObject = function (operation, value) { return ({
101
+ operation: operation,
102
+ value: value,
103
+ __embeddableVariableMeta: true,
104
+ }); };
105
+ var Value = {
106
+ noFilter: function () { return getOperationObject("NO_FILTER"); },
107
+ of: function (value) { return getOperationObject("VALUE", value); },
108
+ };
109
+
28
110
  var UPDATE_VALUE_EVENT = "embeddable:value:changed";
29
111
  var setValue = function (value, componentId, eventName) {
30
112
  var event = new CustomEvent(UPDATE_VALUE_EVENT, {
@@ -32,7 +114,7 @@ var setValue = function (value, componentId, eventName) {
32
114
  detail: {
33
115
  componentId: componentId,
34
116
  value: value,
35
- eventName: eventName
117
+ eventName: eventName,
36
118
  },
37
119
  });
38
120
  window.dispatchEvent(event);
@@ -72,27 +154,28 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
72
154
  };
73
155
 
74
156
  var embedType = function (typeName, typeConfig) {
75
- // @ts-ignore
76
- window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
77
- // @ts-ignore
78
- window.__EMBEDDABLE__.types = window.__EMBEDDABLE__.types || {};
79
- // @ts-ignore
80
- window.__EMBEDDABLE__.types[typeName] = __assign({ name: typeName }, typeConfig);
157
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
158
+ globalThis.__EMBEDDABLE__.types = globalThis.__EMBEDDABLE__.types || {};
159
+ globalThis.__EMBEDDABLE__.types[typeName] = __assign({ name: typeName }, typeConfig);
160
+ return {
161
+ toString: function () { return typeName; },
162
+ typeConfig: typeConfig,
163
+ };
81
164
  };
82
165
 
83
166
  var embedOption = function (typeName, option) {
84
- // @ts-ignore
85
- window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
86
- // @ts-ignore
87
- if (!window.__EMBEDDABLE__.types[typeName])
167
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
168
+ if (!globalThis.__EMBEDDABLE__.types[typeName])
88
169
  return;
89
- // @ts-ignore
90
- window.__EMBEDDABLE__.types[typeName].options = window.__EMBEDDABLE__.types[typeName].options || [];
91
- // @ts-ignore
92
- window.__EMBEDDABLE__.types[typeName].options.push(option);
170
+ globalThis.__EMBEDDABLE__.types[typeName].options =
171
+ globalThis.__EMBEDDABLE__.types[typeName].options || [];
172
+ globalThis.__EMBEDDABLE__.types[typeName].options.push(option);
93
173
  };
94
174
 
175
+ exports.Value = Value;
176
+ exports.defineConfig = defineConfig;
95
177
  exports.embedOption = embedOption;
96
178
  exports.embedType = embedType;
179
+ exports.isLoadDataParams = isLoadDataParams;
97
180
  exports.loadData = loadData;
98
181
  exports.setValue = setValue;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from './loadData';
2
- export { setValue } from './setValue';
3
- export { embedType } from './embedType';
4
- export { embedOption } from './embedOption';
1
+ export * from "./loadData";
2
+ export { defineConfig } from "./defineConfig";
3
+ export { Value } from "./operations";
4
+ export { setValue } from "./setValue";
5
+ export { embedType } from "./embedType";
6
+ export { embedOption } from "./embedOption";
package/lib/index.esm.js CHANGED
@@ -1,28 +1,110 @@
1
- import axios from 'axios';
1
+ import path from 'node:path';
2
2
 
3
- var executeDataRequest = function (request, variables) {
4
- var _a, _b, _c;
3
+ var normalizeEntities = function (entities, _a) {
4
+ var _b = _a.mapFn, mapFn = _b === void 0 ? function (x) { return x; } : _b, _c = _a.filterFn, filterFn = _c === void 0 ? Boolean : _c;
5
+ if (!entities)
6
+ return undefined;
7
+ var filtered = entities.filter(filterFn);
8
+ if (filtered.length === 0)
9
+ return undefined;
10
+ return filtered.map(mapFn);
11
+ };
12
+ var getName = function (x) { return x.name; };
13
+ var validateOrderBy = function (orderByParam, dimensions, measures) {
14
+ var unknownDimensionsOrMeasures = [];
15
+ var dimensionAndMeasureNames = measures
16
+ .concat(dimensions)
17
+ .map(function (x) { return x.name; });
18
+ for (var _i = 0, orderByParam_1 = orderByParam; _i < orderByParam_1.length; _i++) {
19
+ var orderBy = orderByParam_1[_i];
20
+ var name_1 = orderBy.property.name;
21
+ if (dimensionAndMeasureNames.includes(name_1))
22
+ continue;
23
+ unknownDimensionsOrMeasures.push(name_1);
24
+ }
25
+ return unknownDimensionsOrMeasures;
26
+ };
27
+
28
+ var LOAD_DATA_EVENT = "embeddable-event:load-data";
29
+ var isLoadDataParams = function (ldp) {
30
+ return typeof ldp === "object" && "requestParams" in ldp && "dataLoader" in ldp;
31
+ };
32
+ var executeDataRequest = function (request, componentId, propertyName) {
33
+ var _a;
5
34
  if (!request.from)
6
- return Promise.reject('No dataset selected');
7
- var dimensions = (_a = request.dimensions) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
8
- var measures = (_b = request.measures) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
9
- var timeDimensions = (_c = request.timeDimensions) === null || _c === void 0 ? void 0 : _c.filter(function (d) { return d.dimension; });
35
+ return "No dataset selected";
36
+ var dimensions = normalizeEntities(request.dimensions, { mapFn: getName });
37
+ var measures = normalizeEntities(request.measures, { mapFn: getName });
38
+ var timeDimensions = normalizeEntities(request.timeDimensions, {
39
+ // @ts-expect-error
40
+ filterFn: getName,
41
+ });
42
+ var dimensionsOrMeasuresDefined = dimensions || measures || timeDimensions;
43
+ if (!dimensionsOrMeasuresDefined)
44
+ return "At least a dimension or a measure should be selected.";
45
+ var unknownDimensionsOrMeasures = validateOrderBy((_a = request.orderBy) !== null && _a !== void 0 ? _a : [], dimensions !== null && dimensions !== void 0 ? dimensions : [], measures !== null && measures !== void 0 ? measures : []);
46
+ if (unknownDimensionsOrMeasures.length) {
47
+ return "Cannot order by ".concat(unknownDimensionsOrMeasures.join(", "), " as no such ").concat(unknownDimensionsOrMeasures.length === 1 ? "property" : "properties", " has been loaded.");
48
+ }
10
49
  var query = {
11
50
  datasetId: request.from.datasetId,
12
- dimensions: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.length) ? dimensions : undefined,
13
- measures: (measures === null || measures === void 0 ? void 0 : measures.length) ? measures : undefined,
14
- timeDimensions: (timeDimensions === null || timeDimensions === void 0 ? void 0 : timeDimensions.length) ? timeDimensions : undefined,
15
- variableValues: variables
51
+ embeddableId: request.from.embeddableId,
52
+ dimensions: dimensions,
53
+ measures: measures,
54
+ timeDimensions: timeDimensions,
55
+ offset: request.offset,
56
+ limit: request.limit,
16
57
  };
17
- if (!query.dimensions && !query.timeDimensions)
18
- return Promise.reject('No dimension selected');
19
- return axios.post("".concat("https://api.embeddable.com", "/data-modeling/query"), query);
58
+ window.dispatchEvent(new CustomEvent(LOAD_DATA_EVENT, {
59
+ bubbles: false,
60
+ detail: {
61
+ query: query,
62
+ componentId: componentId,
63
+ propertyName: propertyName,
64
+ },
65
+ }));
20
66
  };
21
67
  var loadData = function (requestParams) { return ({
22
68
  requestParams: requestParams,
23
- dataLoader: executeDataRequest
69
+ dataLoader: executeDataRequest,
24
70
  }); };
25
71
 
72
+ var defineConfig = function (_a) {
73
+ var plugins = _a.plugins;
74
+ var coreRoot = path.resolve(__dirname, "..");
75
+ var clientRoot = process.cwd();
76
+ return {
77
+ core: {
78
+ rootDir: coreRoot,
79
+ templatesDir: path.resolve(coreRoot, "templates"),
80
+ configsDir: path.resolve(coreRoot, "configs"),
81
+ },
82
+ client: {
83
+ rootDir: clientRoot,
84
+ buildDir: path.resolve(clientRoot, ".embeddable-build"),
85
+ srcDir: path.resolve(clientRoot, "src"),
86
+ tmpDir: path.resolve(clientRoot, ".embeddable-tmp"),
87
+ componentDir: path.resolve(clientRoot, ".embeddable-build", "component"),
88
+ stencilBuild: path.resolve(clientRoot, ".embeddable-build", "dist", "embeddable-wrapper"),
89
+ archiveFile: path.resolve(clientRoot, "embeddable-build.zip"),
90
+ },
91
+ outputOptions: {
92
+ typesEntryPointFilename: "embeddable-types-entry-point.js",
93
+ },
94
+ plugins: plugins,
95
+ };
96
+ };
97
+
98
+ var getOperationObject = function (operation, value) { return ({
99
+ operation: operation,
100
+ value: value,
101
+ __embeddableVariableMeta: true,
102
+ }); };
103
+ var Value = {
104
+ noFilter: function () { return getOperationObject("NO_FILTER"); },
105
+ of: function (value) { return getOperationObject("VALUE", value); },
106
+ };
107
+
26
108
  var UPDATE_VALUE_EVENT = "embeddable:value:changed";
27
109
  var setValue = function (value, componentId, eventName) {
28
110
  var event = new CustomEvent(UPDATE_VALUE_EVENT, {
@@ -30,7 +112,7 @@ var setValue = function (value, componentId, eventName) {
30
112
  detail: {
31
113
  componentId: componentId,
32
114
  value: value,
33
- eventName: eventName
115
+ eventName: eventName,
34
116
  },
35
117
  });
36
118
  window.dispatchEvent(event);
@@ -70,24 +152,22 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
70
152
  };
71
153
 
72
154
  var embedType = function (typeName, typeConfig) {
73
- // @ts-ignore
74
- window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
75
- // @ts-ignore
76
- window.__EMBEDDABLE__.types = window.__EMBEDDABLE__.types || {};
77
- // @ts-ignore
78
- window.__EMBEDDABLE__.types[typeName] = __assign({ name: typeName }, typeConfig);
155
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
156
+ globalThis.__EMBEDDABLE__.types = globalThis.__EMBEDDABLE__.types || {};
157
+ globalThis.__EMBEDDABLE__.types[typeName] = __assign({ name: typeName }, typeConfig);
158
+ return {
159
+ toString: function () { return typeName; },
160
+ typeConfig: typeConfig,
161
+ };
79
162
  };
80
163
 
81
164
  var embedOption = function (typeName, option) {
82
- // @ts-ignore
83
- window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
84
- // @ts-ignore
85
- if (!window.__EMBEDDABLE__.types[typeName])
165
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
166
+ if (!globalThis.__EMBEDDABLE__.types[typeName])
86
167
  return;
87
- // @ts-ignore
88
- window.__EMBEDDABLE__.types[typeName].options = window.__EMBEDDABLE__.types[typeName].options || [];
89
- // @ts-ignore
90
- window.__EMBEDDABLE__.types[typeName].options.push(option);
168
+ globalThis.__EMBEDDABLE__.types[typeName].options =
169
+ globalThis.__EMBEDDABLE__.types[typeName].options || [];
170
+ globalThis.__EMBEDDABLE__.types[typeName].options.push(option);
91
171
  };
92
172
 
93
- export { embedOption, embedType, loadData, setValue };
173
+ export { Value, defineConfig, embedOption, embedType, isLoadDataParams, loadData, setValue };
package/lib/index.umd.js CHANGED
@@ -1,32 +1,114 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('axios')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'axios'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.embeddableSdk = {}, global.axios));
5
- })(this, (function (exports, axios) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('node:path')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'node:path'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.embeddableSdk = {}, global.path));
5
+ })(this, (function (exports, path) { 'use strict';
6
6
 
7
- var executeDataRequest = function (request, variables) {
8
- var _a, _b, _c;
7
+ var normalizeEntities = function (entities, _a) {
8
+ var _b = _a.mapFn, mapFn = _b === void 0 ? function (x) { return x; } : _b, _c = _a.filterFn, filterFn = _c === void 0 ? Boolean : _c;
9
+ if (!entities)
10
+ return undefined;
11
+ var filtered = entities.filter(filterFn);
12
+ if (filtered.length === 0)
13
+ return undefined;
14
+ return filtered.map(mapFn);
15
+ };
16
+ var getName = function (x) { return x.name; };
17
+ var validateOrderBy = function (orderByParam, dimensions, measures) {
18
+ var unknownDimensionsOrMeasures = [];
19
+ var dimensionAndMeasureNames = measures
20
+ .concat(dimensions)
21
+ .map(function (x) { return x.name; });
22
+ for (var _i = 0, orderByParam_1 = orderByParam; _i < orderByParam_1.length; _i++) {
23
+ var orderBy = orderByParam_1[_i];
24
+ var name_1 = orderBy.property.name;
25
+ if (dimensionAndMeasureNames.includes(name_1))
26
+ continue;
27
+ unknownDimensionsOrMeasures.push(name_1);
28
+ }
29
+ return unknownDimensionsOrMeasures;
30
+ };
31
+
32
+ var LOAD_DATA_EVENT = "embeddable-event:load-data";
33
+ var isLoadDataParams = function (ldp) {
34
+ return typeof ldp === "object" && "requestParams" in ldp && "dataLoader" in ldp;
35
+ };
36
+ var executeDataRequest = function (request, componentId, propertyName) {
37
+ var _a;
9
38
  if (!request.from)
10
- return Promise.reject('No dataset selected');
11
- var dimensions = (_a = request.dimensions) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
12
- var measures = (_b = request.measures) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
13
- var timeDimensions = (_c = request.timeDimensions) === null || _c === void 0 ? void 0 : _c.filter(function (d) { return d.dimension; });
39
+ return "No dataset selected";
40
+ var dimensions = normalizeEntities(request.dimensions, { mapFn: getName });
41
+ var measures = normalizeEntities(request.measures, { mapFn: getName });
42
+ var timeDimensions = normalizeEntities(request.timeDimensions, {
43
+ // @ts-expect-error
44
+ filterFn: getName,
45
+ });
46
+ var dimensionsOrMeasuresDefined = dimensions || measures || timeDimensions;
47
+ if (!dimensionsOrMeasuresDefined)
48
+ return "At least a dimension or a measure should be selected.";
49
+ var unknownDimensionsOrMeasures = validateOrderBy((_a = request.orderBy) !== null && _a !== void 0 ? _a : [], dimensions !== null && dimensions !== void 0 ? dimensions : [], measures !== null && measures !== void 0 ? measures : []);
50
+ if (unknownDimensionsOrMeasures.length) {
51
+ return "Cannot order by ".concat(unknownDimensionsOrMeasures.join(", "), " as no such ").concat(unknownDimensionsOrMeasures.length === 1 ? "property" : "properties", " has been loaded.");
52
+ }
14
53
  var query = {
15
54
  datasetId: request.from.datasetId,
16
- dimensions: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.length) ? dimensions : undefined,
17
- measures: (measures === null || measures === void 0 ? void 0 : measures.length) ? measures : undefined,
18
- timeDimensions: (timeDimensions === null || timeDimensions === void 0 ? void 0 : timeDimensions.length) ? timeDimensions : undefined,
19
- variableValues: variables
55
+ embeddableId: request.from.embeddableId,
56
+ dimensions: dimensions,
57
+ measures: measures,
58
+ timeDimensions: timeDimensions,
59
+ offset: request.offset,
60
+ limit: request.limit,
20
61
  };
21
- if (!query.dimensions && !query.timeDimensions)
22
- return Promise.reject('No dimension selected');
23
- return axios.post("".concat("https://api.embeddable.com", "/data-modeling/query"), query);
62
+ window.dispatchEvent(new CustomEvent(LOAD_DATA_EVENT, {
63
+ bubbles: false,
64
+ detail: {
65
+ query: query,
66
+ componentId: componentId,
67
+ propertyName: propertyName,
68
+ },
69
+ }));
24
70
  };
25
71
  var loadData = function (requestParams) { return ({
26
72
  requestParams: requestParams,
27
- dataLoader: executeDataRequest
73
+ dataLoader: executeDataRequest,
28
74
  }); };
29
75
 
76
+ var defineConfig = function (_a) {
77
+ var plugins = _a.plugins;
78
+ var coreRoot = path.resolve(__dirname, "..");
79
+ var clientRoot = process.cwd();
80
+ return {
81
+ core: {
82
+ rootDir: coreRoot,
83
+ templatesDir: path.resolve(coreRoot, "templates"),
84
+ configsDir: path.resolve(coreRoot, "configs"),
85
+ },
86
+ client: {
87
+ rootDir: clientRoot,
88
+ buildDir: path.resolve(clientRoot, ".embeddable-build"),
89
+ srcDir: path.resolve(clientRoot, "src"),
90
+ tmpDir: path.resolve(clientRoot, ".embeddable-tmp"),
91
+ componentDir: path.resolve(clientRoot, ".embeddable-build", "component"),
92
+ stencilBuild: path.resolve(clientRoot, ".embeddable-build", "dist", "embeddable-wrapper"),
93
+ archiveFile: path.resolve(clientRoot, "embeddable-build.zip"),
94
+ },
95
+ outputOptions: {
96
+ typesEntryPointFilename: "embeddable-types-entry-point.js",
97
+ },
98
+ plugins: plugins,
99
+ };
100
+ };
101
+
102
+ var getOperationObject = function (operation, value) { return ({
103
+ operation: operation,
104
+ value: value,
105
+ __embeddableVariableMeta: true,
106
+ }); };
107
+ var Value = {
108
+ noFilter: function () { return getOperationObject("NO_FILTER"); },
109
+ of: function (value) { return getOperationObject("VALUE", value); },
110
+ };
111
+
30
112
  var UPDATE_VALUE_EVENT = "embeddable:value:changed";
31
113
  var setValue = function (value, componentId, eventName) {
32
114
  var event = new CustomEvent(UPDATE_VALUE_EVENT, {
@@ -34,7 +116,7 @@
34
116
  detail: {
35
117
  componentId: componentId,
36
118
  value: value,
37
- eventName: eventName
119
+ eventName: eventName,
38
120
  },
39
121
  });
40
122
  window.dispatchEvent(event);
@@ -74,28 +156,29 @@
74
156
  };
75
157
 
76
158
  var embedType = function (typeName, typeConfig) {
77
- // @ts-ignore
78
- window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
79
- // @ts-ignore
80
- window.__EMBEDDABLE__.types = window.__EMBEDDABLE__.types || {};
81
- // @ts-ignore
82
- window.__EMBEDDABLE__.types[typeName] = __assign({ name: typeName }, typeConfig);
159
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
160
+ globalThis.__EMBEDDABLE__.types = globalThis.__EMBEDDABLE__.types || {};
161
+ globalThis.__EMBEDDABLE__.types[typeName] = __assign({ name: typeName }, typeConfig);
162
+ return {
163
+ toString: function () { return typeName; },
164
+ typeConfig: typeConfig,
165
+ };
83
166
  };
84
167
 
85
168
  var embedOption = function (typeName, option) {
86
- // @ts-ignore
87
- window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
88
- // @ts-ignore
89
- if (!window.__EMBEDDABLE__.types[typeName])
169
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
170
+ if (!globalThis.__EMBEDDABLE__.types[typeName])
90
171
  return;
91
- // @ts-ignore
92
- window.__EMBEDDABLE__.types[typeName].options = window.__EMBEDDABLE__.types[typeName].options || [];
93
- // @ts-ignore
94
- window.__EMBEDDABLE__.types[typeName].options.push(option);
172
+ globalThis.__EMBEDDABLE__.types[typeName].options =
173
+ globalThis.__EMBEDDABLE__.types[typeName].options || [];
174
+ globalThis.__EMBEDDABLE__.types[typeName].options.push(option);
95
175
  };
96
176
 
177
+ exports.Value = Value;
178
+ exports.defineConfig = defineConfig;
97
179
  exports.embedOption = embedOption;
98
180
  exports.embedType = embedType;
181
+ exports.isLoadDataParams = isLoadDataParams;
99
182
  exports.loadData = loadData;
100
183
  exports.setValue = setValue;
101
184
 
package/lib/loadData.d.ts CHANGED
@@ -1,22 +1,74 @@
1
- import axios from 'axios';
2
- export type TimeDimensions = {
3
- dimension: string;
4
- granularity: string;
1
+ declare const cubeNativeType: {
2
+ readonly string: "string";
3
+ readonly number: "number";
4
+ readonly time: "time";
5
+ };
6
+ export type NativeType = keyof typeof cubeNativeType;
7
+ export type Dimension = {
8
+ name: string;
9
+ title: string;
10
+ nativeType: NativeType;
11
+ description?: string;
12
+ meta?: object;
13
+ };
14
+ export type Measure = {
15
+ name: string;
16
+ title: string;
17
+ nativeType: NativeType;
18
+ description?: string;
19
+ meta?: object;
20
+ };
21
+ export type DimensionOrMeasure = Dimension | Measure;
22
+ declare const timeDimensionGranularity: {
23
+ second: string;
24
+ minute: string;
25
+ hour: string;
26
+ day: string;
27
+ week: string;
28
+ month: string;
29
+ quarter: string;
30
+ year: string;
31
+ };
32
+ export type Granularity = keyof typeof timeDimensionGranularity;
33
+ export type TimeDimension = {
34
+ name: string;
35
+ granularity: Granularity;
36
+ };
37
+ export type OrderDirection = "asc" | "desc";
38
+ export type OrderBy = {
39
+ property: DimensionOrMeasure;
40
+ direction: OrderDirection;
41
+ };
42
+ export type LoadDataEvent = {
43
+ query: QueryRequest;
44
+ componentId: string;
45
+ propertyName: string;
46
+ };
47
+ type QueryRequest = {
48
+ embeddableId: string;
49
+ datasetId: string;
50
+ dimensions: string[];
51
+ measures?: string[];
52
+ timeDimensions?: TimeDimension[];
5
53
  };
6
54
  export type Dataset = {
55
+ embeddableId: string;
7
56
  datasetId: string;
8
57
  };
9
58
  export type LoadDataRequest = {
10
59
  from: Dataset;
11
- measures?: string[];
12
- dimensions: string[];
13
- timeDimensions?: TimeDimensions[];
14
- orderBy?: string[];
60
+ measures?: Measure[];
61
+ dimensions?: Dimension[];
62
+ timeDimensions?: TimeDimension[];
63
+ orderBy?: OrderBy[];
64
+ limit?: number;
65
+ offset?: number;
15
66
  };
16
67
  export type LoadDataParams = {
17
68
  requestParams: LoadDataRequest;
18
69
  dataLoader: typeof executeDataRequest;
19
70
  };
20
- declare const executeDataRequest: (request: LoadDataRequest, variables?: Record<string, any>) => Promise<axios.AxiosResponse<any, any>>;
71
+ export declare const isLoadDataParams: (ldp: unknown) => ldp is LoadDataParams;
72
+ declare const executeDataRequest: (request: LoadDataRequest, componentId: string, propertyName: string) => string;
21
73
  export declare const loadData: (requestParams: LoadDataRequest) => LoadDataParams;
22
74
  export {};
@@ -0,0 +1,11 @@
1
+ type OperationType = "NO_FILTER" | "VALUE";
2
+ type Operation = {
3
+ operation: OperationType;
4
+ value?: unknown;
5
+ };
6
+ export type ValueOperationType = {
7
+ noFilter: () => Operation;
8
+ of: (value: unknown) => Operation;
9
+ };
10
+ export declare const Value: ValueOperationType;
11
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Dimension, Measure, OrderBy } from "./loadData";
2
+ export declare const normalizeEntities: <T>(entities: T[], { mapFn, filterFn, }: {
3
+ mapFn?: (_: T) => any;
4
+ filterFn?: (_: T) => boolean;
5
+ }) => any[];
6
+ export declare const getName: <T extends {
7
+ name: string;
8
+ }>(x: T) => string;
9
+ export declare const validateOrderBy: (orderByParam: OrderBy[], dimensions: Dimension[], measures: Measure[]) => any[];