@embeddable.com/sdk-core 0.0.14 → 0.1.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/bin/embeddable CHANGED
@@ -1,15 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const { build } = require("../scripts/build");
5
- const { login } = require("../scripts/login");
6
- const { push } = require("../scripts/push");
7
-
8
- const COMMANDS_MAP = {
9
- build,
10
- login,
11
- push
12
- };
4
+ const COMMANDS_MAP = require("../scripts");
13
5
 
14
6
  async function main () {
15
7
  const command = process.argv[2];
@@ -0,0 +1 @@
1
+ export declare const embedOption: (typeName: string, option: any) => void;
@@ -0,0 +1,4 @@
1
+ export declare const embedType: (typeName: string, typeConfig: {
2
+ label: string;
3
+ toString: (_: any) => string;
4
+ }) => void;
package/lib/index.cjs.js CHANGED
@@ -2,90 +2,69 @@
2
2
 
3
3
  var axios = require('axios');
4
4
 
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
- /* global Reflect, Promise, SuppressedError, Symbol */
20
-
21
-
22
- function __awaiter(thisArg, _arguments, P, generator) {
23
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
- step((generator = generator.apply(thisArg, _arguments || [])).next());
29
- });
30
- }
31
-
32
- function __generator(thisArg, body) {
33
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
34
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
- function verb(n) { return function (v) { return step([n, v]); }; }
36
- function step(op) {
37
- if (f) throw new TypeError("Generator is already executing.");
38
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
39
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
40
- if (y = 0, t) op = [op[0] & 2, t.value];
41
- switch (op[0]) {
42
- case 0: case 1: t = op; break;
43
- case 4: _.label++; return { value: op[1], done: false };
44
- case 5: _.label++; y = op[1]; op = [0]; continue;
45
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
- default:
47
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
- if (t[2]) _.ops.pop();
52
- _.trys.pop(); continue;
53
- }
54
- op = body.call(thisArg, _);
55
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
- }
58
- }
59
-
60
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
61
- var e = new Error(message);
62
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
5
+ var executeDataRequest = function (request, variables) {
6
+ var _a, _b, _c;
7
+ 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; });
12
+ var query = {
13
+ 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
18
+ };
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);
63
22
  };
23
+ var loadData = function (requestParams) { return ({
24
+ requestParams: requestParams,
25
+ dataLoader: executeDataRequest
26
+ }); };
64
27
 
65
- function loadData(request) {
66
- var _a, _b, _c;
67
- return __awaiter(this, void 0, void 0, function () {
68
- var dimensions, measures, timeDimensions, query, response;
69
- return __generator(this, function (_d) {
70
- switch (_d.label) {
71
- case 0:
72
- dimensions = (_a = request.dimensions) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
73
- measures = (_b = request.measures) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
74
- timeDimensions = (_c = request.timeDimensions) === null || _c === void 0 ? void 0 : _c.filter(function (d) { return d.dimension; });
75
- query = {
76
- dimensions: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.length) ? dimensions : undefined,
77
- measures: (measures === null || measures === void 0 ? void 0 : measures.length) ? measures : undefined,
78
- timeDimensions: (timeDimensions === null || timeDimensions === void 0 ? void 0 : timeDimensions.length) ? timeDimensions : undefined
79
- };
80
- if (!query.dimensions && !query.timeDimensions)
81
- return [2 /*return*/, null];
82
- return [4 /*yield*/, axios.post("".concat("https://api.embeddable.com", "/data-modeling/query?datasourceId=").concat(request.from), query)];
83
- case 1:
84
- response = _d.sent();
85
- return [2 /*return*/, response.data];
86
- }
87
- });
28
+ var UPDATE_VALUE_EVENT = "embeddable:value:changed";
29
+ var setValue = function (value, componentId, eventName) {
30
+ var event = new CustomEvent(UPDATE_VALUE_EVENT, {
31
+ bubbles: false,
32
+ detail: {
33
+ componentId: componentId,
34
+ value: value,
35
+ eventName: eventName
36
+ },
88
37
  });
89
- }
38
+ window.dispatchEvent(event);
39
+ };
40
+
41
+ var embedType = function (typeName, typeConfig) {
42
+ // @ts-ignore
43
+ window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
44
+ // @ts-ignore
45
+ window.__EMBEDDABLE__.types = window.__EMBEDDABLE__.types || {};
46
+ // @ts-ignore
47
+ window.__EMBEDDABLE__.types[typeName] = typeConfig;
48
+ };
49
+
50
+ var embedOption = function (typeName, option) {
51
+ // @ts-ignore
52
+ window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
53
+ // @ts-ignore
54
+ if (!window.__EMBEDDABLE__.types[typeName])
55
+ return;
56
+ // @ts-ignore
57
+ window.__EMBEDDABLE__.types[typeName].options = window.__EMBEDDABLE__.types[typeName].options || [];
58
+ // @ts-ignore
59
+ if (window.__EMBEDDABLE__.types[typeName].toString) {
60
+ // @ts-ignore
61
+ option.__proto__.toString = function () { return window.__EMBEDDABLE__.types[typeName].toString(option); };
62
+ }
63
+ // @ts-ignore
64
+ window.__EMBEDDABLE__.types[typeName].options.push(option);
65
+ };
90
66
 
67
+ exports.embedOption = embedOption;
68
+ exports.embedType = embedType;
91
69
  exports.loadData = loadData;
70
+ exports.setValue = setValue;
package/lib/index.d.ts CHANGED
@@ -1 +1,4 @@
1
- export { loadData } from './loadData';
1
+ export * from './loadData';
2
+ export { setValue } from './setValue';
3
+ export { embedType } from './embedType';
4
+ export { embedOption } from './embedOption';
package/lib/index.esm.js CHANGED
@@ -1,89 +1,65 @@
1
1
  import axios from 'axios';
2
2
 
3
- /******************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
- /* global Reflect, Promise, SuppressedError, Symbol */
18
-
19
-
20
- function __awaiter(thisArg, _arguments, P, generator) {
21
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
- step((generator = generator.apply(thisArg, _arguments || [])).next());
27
- });
28
- }
29
-
30
- function __generator(thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
37
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- }
57
-
58
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
59
- var e = new Error(message);
60
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3
+ var executeDataRequest = function (request, variables) {
4
+ var _a, _b, _c;
5
+ 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; });
10
+ var query = {
11
+ 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
16
+ };
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);
61
20
  };
21
+ var loadData = function (requestParams) { return ({
22
+ requestParams: requestParams,
23
+ dataLoader: executeDataRequest
24
+ }); };
62
25
 
63
- function loadData(request) {
64
- var _a, _b, _c;
65
- return __awaiter(this, void 0, void 0, function () {
66
- var dimensions, measures, timeDimensions, query, response;
67
- return __generator(this, function (_d) {
68
- switch (_d.label) {
69
- case 0:
70
- dimensions = (_a = request.dimensions) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
71
- measures = (_b = request.measures) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
72
- timeDimensions = (_c = request.timeDimensions) === null || _c === void 0 ? void 0 : _c.filter(function (d) { return d.dimension; });
73
- query = {
74
- dimensions: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.length) ? dimensions : undefined,
75
- measures: (measures === null || measures === void 0 ? void 0 : measures.length) ? measures : undefined,
76
- timeDimensions: (timeDimensions === null || timeDimensions === void 0 ? void 0 : timeDimensions.length) ? timeDimensions : undefined
77
- };
78
- if (!query.dimensions && !query.timeDimensions)
79
- return [2 /*return*/, null];
80
- return [4 /*yield*/, axios.post("".concat("https://api.embeddable.com", "/data-modeling/query?datasourceId=").concat(request.from), query)];
81
- case 1:
82
- response = _d.sent();
83
- return [2 /*return*/, response.data];
84
- }
85
- });
26
+ var UPDATE_VALUE_EVENT = "embeddable:value:changed";
27
+ var setValue = function (value, componentId, eventName) {
28
+ var event = new CustomEvent(UPDATE_VALUE_EVENT, {
29
+ bubbles: false,
30
+ detail: {
31
+ componentId: componentId,
32
+ value: value,
33
+ eventName: eventName
34
+ },
86
35
  });
87
- }
36
+ window.dispatchEvent(event);
37
+ };
38
+
39
+ var embedType = function (typeName, typeConfig) {
40
+ // @ts-ignore
41
+ window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
42
+ // @ts-ignore
43
+ window.__EMBEDDABLE__.types = window.__EMBEDDABLE__.types || {};
44
+ // @ts-ignore
45
+ window.__EMBEDDABLE__.types[typeName] = typeConfig;
46
+ };
47
+
48
+ var embedOption = function (typeName, option) {
49
+ // @ts-ignore
50
+ window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
51
+ // @ts-ignore
52
+ if (!window.__EMBEDDABLE__.types[typeName])
53
+ return;
54
+ // @ts-ignore
55
+ window.__EMBEDDABLE__.types[typeName].options = window.__EMBEDDABLE__.types[typeName].options || [];
56
+ // @ts-ignore
57
+ if (window.__EMBEDDABLE__.types[typeName].toString) {
58
+ // @ts-ignore
59
+ option.__proto__.toString = function () { return window.__EMBEDDABLE__.types[typeName].toString(option); };
60
+ }
61
+ // @ts-ignore
62
+ window.__EMBEDDABLE__.types[typeName].options.push(option);
63
+ };
88
64
 
89
- export { loadData };
65
+ export { embedOption, embedType, loadData, setValue };
package/lib/index.umd.js CHANGED
@@ -4,92 +4,71 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.embeddableSdk = {}, global.axios));
5
5
  })(this, (function (exports, axios) { 'use strict';
6
6
 
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol */
22
-
23
-
24
- function __awaiter(thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- }
33
-
34
- function __generator(thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- }
61
-
62
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
63
- var e = new Error(message);
64
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
7
+ var executeDataRequest = function (request, variables) {
8
+ var _a, _b, _c;
9
+ 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; });
14
+ var query = {
15
+ 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
20
+ };
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);
65
24
  };
25
+ var loadData = function (requestParams) { return ({
26
+ requestParams: requestParams,
27
+ dataLoader: executeDataRequest
28
+ }); };
66
29
 
67
- function loadData(request) {
68
- var _a, _b, _c;
69
- return __awaiter(this, void 0, void 0, function () {
70
- var dimensions, measures, timeDimensions, query, response;
71
- return __generator(this, function (_d) {
72
- switch (_d.label) {
73
- case 0:
74
- dimensions = (_a = request.dimensions) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
75
- measures = (_b = request.measures) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
76
- timeDimensions = (_c = request.timeDimensions) === null || _c === void 0 ? void 0 : _c.filter(function (d) { return d.dimension; });
77
- query = {
78
- dimensions: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.length) ? dimensions : undefined,
79
- measures: (measures === null || measures === void 0 ? void 0 : measures.length) ? measures : undefined,
80
- timeDimensions: (timeDimensions === null || timeDimensions === void 0 ? void 0 : timeDimensions.length) ? timeDimensions : undefined
81
- };
82
- if (!query.dimensions && !query.timeDimensions)
83
- return [2 /*return*/, null];
84
- return [4 /*yield*/, axios.post("".concat("https://api.embeddable.com", "/data-modeling/query?datasourceId=").concat(request.from), query)];
85
- case 1:
86
- response = _d.sent();
87
- return [2 /*return*/, response.data];
88
- }
89
- });
30
+ var UPDATE_VALUE_EVENT = "embeddable:value:changed";
31
+ var setValue = function (value, componentId, eventName) {
32
+ var event = new CustomEvent(UPDATE_VALUE_EVENT, {
33
+ bubbles: false,
34
+ detail: {
35
+ componentId: componentId,
36
+ value: value,
37
+ eventName: eventName
38
+ },
90
39
  });
91
- }
40
+ window.dispatchEvent(event);
41
+ };
42
+
43
+ var embedType = function (typeName, typeConfig) {
44
+ // @ts-ignore
45
+ window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
46
+ // @ts-ignore
47
+ window.__EMBEDDABLE__.types = window.__EMBEDDABLE__.types || {};
48
+ // @ts-ignore
49
+ window.__EMBEDDABLE__.types[typeName] = typeConfig;
50
+ };
51
+
52
+ var embedOption = function (typeName, option) {
53
+ // @ts-ignore
54
+ window.__EMBEDDABLE__ = window.__EMBEDDABLE__ || {};
55
+ // @ts-ignore
56
+ if (!window.__EMBEDDABLE__.types[typeName])
57
+ return;
58
+ // @ts-ignore
59
+ window.__EMBEDDABLE__.types[typeName].options = window.__EMBEDDABLE__.types[typeName].options || [];
60
+ // @ts-ignore
61
+ if (window.__EMBEDDABLE__.types[typeName].toString) {
62
+ // @ts-ignore
63
+ option.__proto__.toString = function () { return window.__EMBEDDABLE__.types[typeName].toString(option); };
64
+ }
65
+ // @ts-ignore
66
+ window.__EMBEDDABLE__.types[typeName].options.push(option);
67
+ };
92
68
 
69
+ exports.embedOption = embedOption;
70
+ exports.embedType = embedType;
93
71
  exports.loadData = loadData;
72
+ exports.setValue = setValue;
94
73
 
95
74
  }));
package/lib/loadData.d.ts CHANGED
@@ -1,12 +1,22 @@
1
+ import axios from 'axios';
1
2
  export type TimeDimensions = {
2
3
  dimension: string;
3
4
  granularity: string;
4
5
  };
6
+ export type Dataset = {
7
+ datasetId: string;
8
+ };
5
9
  export type LoadDataRequest = {
6
- from: string;
10
+ from: Dataset;
7
11
  measures?: string[];
8
12
  dimensions: string[];
9
13
  timeDimensions?: TimeDimensions[];
10
14
  orderBy?: string[];
11
15
  };
12
- export declare function loadData(request: LoadDataRequest): Promise<any>;
16
+ export type LoadDataParams = {
17
+ requestParams: LoadDataRequest;
18
+ dataLoader: typeof executeDataRequest;
19
+ };
20
+ declare const executeDataRequest: (request: LoadDataRequest, variables?: Record<string, any>) => Promise<axios.AxiosResponse<any, any>>;
21
+ export declare const loadData: (requestParams: LoadDataRequest) => LoadDataParams;
22
+ export {};
@@ -0,0 +1 @@
1
+ export declare const setValue: <T>(value: T, componentId: string, eventName?: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-core",
3
- "version": "0.0.14",
3
+ "version": "0.1.0",
4
4
  "description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
5
5
  "keywords": [
6
6
  "embeddable",
package/scripts/build.js CHANGED
@@ -2,7 +2,7 @@ const path = require("path");
2
2
  const { prepare } = require("./prepare");
3
3
  const { generate } = require("./generate");
4
4
  const { cleanup } = require("./cleanup");
5
- const {createContext} = require("./createContext");
5
+ const { createContext } = require("./createContext");
6
6
 
7
7
  async function build(pluginOptions = {}) {
8
8
  const ctx = {
@@ -0,0 +1,52 @@
1
+ const fs = require("node:fs/promises");
2
+ const path = require("node:path");
3
+ const vite = require("vite");
4
+
5
+ const { findEmbFiles } = require("./findEmbFiles");
6
+
7
+
8
+ const EMB_TYPE_FILE_REGEX = /^(.*)\.type\.emb\.[jt]s$/;
9
+
10
+ async function buildTypes(ctx) {
11
+ await generate(ctx);
12
+
13
+ await build(ctx);
14
+
15
+ await cleanup(ctx);
16
+ }
17
+
18
+ module.exports = { buildTypes };
19
+
20
+
21
+ async function generate(ctx) {
22
+ const typeFiles = await findEmbFiles(ctx.client.srcDir, EMB_TYPE_FILE_REGEX);
23
+
24
+ const typeImports = typeFiles.map(([fileName, filePath]) =>
25
+ `import './${path.relative(ctx.client.rootDir, filePath)}';`
26
+ ).join('\n');
27
+
28
+ await fs.writeFile(
29
+ path.resolve(ctx.client.rootDir, ctx.outputOptions.typesEntryPointFilename),
30
+ typeImports
31
+ );
32
+ }
33
+
34
+ async function build(ctx) {
35
+ process.chdir(ctx.client.rootDir);
36
+
37
+ await vite.build({
38
+ build: {
39
+ emptyOutDir: false,
40
+ lib: {
41
+ entry: `./${ctx.outputOptions.typesEntryPointFilename}`,
42
+ formats: ['es'],
43
+ fileName: 'embeddable-types'
44
+ },
45
+ outDir: '.embeddable-build/'
46
+ },
47
+ });
48
+ }
49
+
50
+ async function cleanup(ctx) {
51
+ await fs.rm(path.resolve(ctx.client.rootDir, 'embeddable-types-entry-point.js'));
52
+ }
@@ -10,6 +10,7 @@ function createContext (coreRoot, clientRoot) {
10
10
  client: {
11
11
  rootDir: clientRoot,
12
12
  buildDir: path.resolve(clientRoot, '.embeddable-build'),
13
+ srcDir: path.resolve(clientRoot, 'src'),
13
14
  tmpDir: path.resolve(clientRoot, '.embeddable-tmp'),
14
15
  componentDir: path.resolve(clientRoot, '.embeddable-build', 'component'),
15
16
  stencilBuild: path.resolve(clientRoot, '.embeddable-build', 'dist', 'embeddable-wrapper'),
@@ -0,0 +1,33 @@
1
+ const fs = require("fs/promises");
2
+ const path = require("path");
3
+
4
+ async function findEmbFiles (initialSrcDir, regex) {
5
+ const filesList = [];
6
+
7
+ async function findEmbFilesRec(srcDir) {
8
+ const allFiles = await fs.readdir(srcDir);
9
+
10
+ for (const file of allFiles) {
11
+ const filePath = path.join(srcDir, file)
12
+
13
+ const status = await fs.lstat(filePath);
14
+
15
+ if (status.isDirectory()) {
16
+ await findEmbFilesRec(filePath)
17
+ }
18
+
19
+ const fileName = file.match(regex);
20
+
21
+ if (fileName) {
22
+ filesList.push([fileName[1], filePath]);
23
+ }
24
+ }
25
+ }
26
+
27
+ await findEmbFilesRec(initialSrcDir);
28
+
29
+
30
+ return filesList;
31
+ }
32
+
33
+ module.exports = { findEmbFiles };
@@ -4,7 +4,6 @@ const path = require("path");
4
4
  const stencilNodeApi = require("@stencil/core/sys/node");
5
5
  const stencil = require("@stencil/core/cli");
6
6
 
7
-
8
7
  const STYLE_IMPORTS_TOKEN = '{{STYLES_IMPORT}}';
9
8
  const RENDER_IMPORT_TOKEN = '{{RENDER_IMPORT}}';
10
9
 
@@ -0,0 +1,13 @@
1
+ const { build } = require("./build");
2
+ const { buildTypes } = require("./buildTypes");
3
+ const { findEmbFiles } = require("./findEmbFiles");
4
+ const { login } = require("./login");
5
+ const { push } = require("./push");
6
+
7
+ module.exports = {
8
+ build,
9
+ buildTypes,
10
+ findEmbFiles,
11
+ login,
12
+ push
13
+ }
package/scripts/login.js CHANGED
@@ -32,7 +32,7 @@ async function login () {
32
32
  const { username, password } = await prompt.get(PROMPT_SCHEMA);
33
33
 
34
34
  const authResponse = await axios.post(
35
- 'http://localhost:8080/auth/token', // TODO: hardcoded for now.
35
+ 'https://metadata.embeddable.com/auth/token', // TODO: hardcoded for now.
36
36
  { username, password }
37
37
  );
38
38
 
package/scripts/push.js CHANGED
@@ -5,8 +5,11 @@ const archiver = require('archiver');
5
5
  const axios = require('axios');
6
6
  const oraP = import('ora');
7
7
 
8
- const {createContext} = require("./createContext");
9
- const {getToken} = require('./login');
8
+ const { findEmbFiles } = require('./findEmbFiles');
9
+ const { createContext } = require("./createContext");
10
+ const { getToken } = require('./login');
11
+
12
+ const EMB_YAML_FILE_REGEX = /^(.*)\.emb\.ya?ml$/;
10
13
 
11
14
  async function push () {
12
15
  const ora = (await oraP).default;
@@ -16,7 +19,10 @@ async function push () {
16
19
  const token = await verify(ctx);
17
20
 
18
21
  const spinnerArchive = ora("archivation...").start();
19
- await archive(ctx);
22
+
23
+ const filesList = await findEmbFiles(ctx.client.srcDir, EMB_YAML_FILE_REGEX);
24
+
25
+ await archive(ctx, filesList);
20
26
  spinnerArchive.succeed("archivation competed");
21
27
 
22
28
  const spinnerPushing = ora("publishing...").start();
@@ -45,7 +51,7 @@ async function verify(ctx) {
45
51
  return token;
46
52
  }
47
53
 
48
- function archive(ctx) {
54
+ function archive(ctx, yamlFiles) {
49
55
  const output = fsSync.createWriteStream(ctx.client.archiveFile);
50
56
  const _archiver = archiver('zip', {
51
57
  zlib: { level: 9 }
@@ -53,6 +59,11 @@ function archive(ctx) {
53
59
 
54
60
  _archiver.pipe(output);
55
61
  _archiver.directory(ctx.client.buildDir, false);
62
+
63
+ for (const fileData of yamlFiles) {
64
+ _archiver.file(fileData[1], { name: `${fileData[0]}.emb.yaml` })
65
+ }
66
+
56
67
  _archiver.finalize();
57
68
 
58
69
  return new Promise((resolve, _reject) => {
@@ -70,7 +81,7 @@ async function sendBuild(ctx, token) {
70
81
  form.set('file', file, 'embeddable-build.zip');
71
82
 
72
83
  await axios.post(
73
- 'http://localhost:8080/sdk/upload-files',
84
+ 'https://metadata.embeddable.com/sdk/upload-files',
74
85
  form,
75
86
  {
76
87
  headers: {