datajunction 0.0.1-rc.0 → 0.0.1-rc.1

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/.babelrc CHANGED
@@ -1,8 +1,4 @@
1
1
  {
2
- "presets": [
3
- "es2015"
4
- ],
5
- "plugins": [
6
- "transform-object-rest-spread"
7
- ]
8
- }
2
+ "presets": ["es2015"],
3
+ "plugins": ["transform-object-rest-spread"]
4
+ }
package/.eslintrc.js CHANGED
@@ -1,15 +1,13 @@
1
1
  module.exports = {
2
2
  env: {
3
3
  browser: true,
4
- es2021: true
4
+ es2021: true,
5
5
  },
6
6
  extends: 'standard',
7
- overrides: [
8
- ],
7
+ overrides: [],
9
8
  parserOptions: {
10
9
  ecmaVersion: 'latest',
11
- sourceType: 'module'
10
+ sourceType: 'module',
12
11
  },
13
- rules: {
14
- }
12
+ rules: {},
15
13
  }
@@ -0,0 +1 @@
1
+ ./dist
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 4,
4
+ "semi": false,
5
+ "singleQuote": true
6
+ }
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.datajunction=t():e.datajunction=t()}(this,(()=>(()=>{"use strict";var e={d:(t,s)=>{for(var r in s)e.o(s,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:s[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{DJClient:()=>r});class s{constructor(e={}){this._baseURL=e.baseURL||"",this._headers=e.headers||{}}async _fetchJSON(e,t={}){const s=await fetch(this._baseURL+e,{...t,headers:this._headers});if(!s.ok)throw new Error(s.statusText);if(!1!==t.parseResponse&&204!==s.status)return s.json()}setHeader(e,t){return this._headers[e]=t,this}getHeader(e){return this._headers[e]}setBasicAuth(e,t){return this._headers.Authorization=`Basic ${btoa(`${e}:${t}`)}`,this}setBearerAuth(e){return this._headers.Authorization=`Bearer ${e}`,this}async get(e,t={}){return this._fetchJSON(e,{...t,method:"GET"})}async post(e,t,s={}){return this._fetchJSON(e,{...s,body:t?JSON.stringify(t):void 0,method:"POST"})}async put(e,t,s={}){return this._fetchJSON(e,{...s,body:t?JSON.stringify(t):void 0,method:"PUT"})}async patch(e,t,s={}){return this._fetchJSON(e,{parseResponse:!1,...s,body:JSON.stringify(t),method:"PATCH"})}async delete(e,t={}){return this._fetchJSON(e,{parseResponse:!1,...t,method:"DELETE"})}}class r extends s{constructor(e){super({baseURL:e})}get catalogs(){return{get:()=>this.get("/catalogs/")}}get engines(){return{get:()=>this.get("/engines/")}}get namespaces(){return{get:()=>this.get("/namespaces/")}}get metrics(){return{get:()=>this.get("/metrics/")}}get nodes(){return{get:()=>this.get("/nodes/")}}get tags(){return{get:()=>this.get("/tags/")}}get attributes(){return{get:()=>this.get("/attributes/")}}}return t})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.datajunction=t():e.datajunction=t()}(this,(()=>(()=>{"use strict";var e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{DJClient:()=>n});class s{constructor(e={}){this._baseURL=e.baseURL||"",this._headers=e.headers||{}}async _fetchJSON(e,t={}){const s=await fetch(this._baseURL+e,{...t,headers:this._headers});if(!s.ok)throw new Error(s.statusText);if(!1!==t.parseResponse&&204!==s.status)return s.json()}setHeader(e,t){return this._headers[e]=t,this}getHeader(e){return this._headers[e]}setBasicAuth(e,t){return this._headers.Authorization=`Basic ${btoa(`${e}:${t}`)}`,this}setBearerAuth(e){return this._headers.Authorization=`Bearer ${e}`,this}async get(e,t={}){return this._fetchJSON(e,{...t,method:"GET"})}async post(e,t,s={}){return this._fetchJSON(e,{...s,body:t?JSON.stringify(t):void 0,method:"POST"})}async put(e,t,s={}){return this._fetchJSON(e,{...s,body:t?JSON.stringify(t):void 0,method:"PUT"})}async patch(e,t,s={}){return this._fetchJSON(e,{parseResponse:!1,...s,body:JSON.stringify(t),method:"PATCH"})}async delete(e,t={}){return this._fetchJSON(e,{parseResponse:!1,...t,method:"DELETE"})}}class n extends s{constructor(e,t,s=null,n=null){super({baseURL:e}),this.namespace=t,this.engineName=s,this.engineVersion=n}get healthcheck(){return{get:()=>this.get("/health/")}}get catalog(){return{list:()=>this.get("/catalogs/"),get:e=>this.get(`/catalogs/${e}/`),create:e=>this.setHeader("Content-Type","application/json").post("/catalogs/",e)}}get engines(){return{list:()=>this.get("/engines/"),get:(e,t)=>this.get(`/engines/${e}/${t}/`),create:e=>this.setHeader("Content-Type","application/json").post("/engines/",e)}}get addEngineToCatalog(){return{set:(e,t)=>this.setHeader("Content-Type","application/json").post(`/catalogs/${e}/engines/`,[t])}}get namespaces(){return{list:()=>this.get("/namespaces/"),nodes:e=>this.get(`/namespaces/${e}/`),create:e=>this.setHeader("Content-Type","application/json").post(`/namespaces/${e}/`)}}get commonDimensions(){return{list:e=>this.get(`/metrics/common/dimensions/?metric=${encodeURIComponent(JSON.stringify(e))}`)}}get nodes(){return{get:e=>this.get(`/nodes/${e}/`),validate:e=>this.setHeader("Content-Type","application/json").post("/nodes/validate/",e),update:(e,t)=>this.setHeader("Content-Type","application/json").patch(`/nodes/${e}/`,t),revisions:e=>this.get(`/nodes/${e}/revisions/`),downstream:e=>this.get(`/nodes/${e}/downstream/`),upstream:e=>this.get(`/nodes/${e}/upstream/`)}}get sources(){return{create:e=>this.setHeader("Content-Type","application/json").post("/nodes/source/",e),list:()=>this.get(`/namespaces/${this.namespace}/?type_=source`)}}get transforms(){return{create:e=>this.setHeader("Content-Type","application/json").post("/nodes/transform/",e),list:()=>this.get(`/namespaces/${this.namespace}/?type_=transform`)}}get dimensions(){return{create:e=>this.setHeader("Content-Type","application/json").post("/nodes/dimension/",e),list:()=>this.get(`/namespaces/${this.namespace}/?type_=dimension`),link:(e,t,s,n)=>this.post(`/nodes/${e}/columns/${t}/?dimension=${s}&dimension_column=${n}`)}}get metrics(){return{get:e=>this.get(`/metrics/${e}/`),create:e=>this.setHeader("Content-Type","application/json").post("/nodes/metric/",e),list:()=>this.get(`/namespaces/${this.namespace}/?type_=metric`),all:()=>this.get("/metrics/")}}get cubes(){return{get:e=>this.get(`/cubes/${e}/`),create:e=>this.setHeader("Content-Type","application/json").post("/nodes/cube/",e)}}get tags(){return{list:()=>this.get("/tags/"),get:e=>this.get(`/tags/${e}/`),create:e=>this.setHeader("Content-Type","application/json").post("/tags/",e),update:(e,t)=>this.setHeader("Content-Type","application/json").patch(`/tags/${e}/`,t),set:(e,t)=>this.post(`/nodes/${e}/tag/?tag_name=${t}`),listNodes:e=>this.get(`/tags/${e}/nodes/`)}}get attributes(){return{list:()=>this.get("/attributes/"),create:e=>this.setHeader("Content-Type","application/json").post("/attributes/",e)}}get materializationConfigs(){return{update:(e,t)=>this.setHeader("Content-Type","application/json").post(`/nodes/${e}/materialization/`,t)}}get columnAttributes(){return{set:(e,t)=>this.setHeader("Content-Type","application/json").post(`/nodes/${e}/attributes/`,[t])}}get availabilityState(){return{set:(e,t)=>this.setHeader("Content-Type","application/json").post(`/data/${e}/availability/`,t)}}get sql(){return{get:(e,t,s,n=!1,i=null,a=null)=>this.get(`/sql/?metrics=${e}&dimensions=${t}&filters=${s}&async_=${n}&engine_name=${i||this.engineName}&engine_version=${a||this.engineVersion}`)}}get data(){return{get:(e,t,s,n=!1,i=null,a=null)=>this.get(`/data/?metrics=${e}&dimensions=${t}&filters=${s}&async_=${n}&engine_name=${i||this.engineName}&engine_version=${a||this.engineVersion}`)}}}return t})()));
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
6
 
7
7
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
@@ -11,110 +11,110 @@ var _createClass = function () { function defineProperties(target, props) { for
11
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
12
 
13
13
  var HttpClient = function () {
14
- function HttpClient() {
15
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14
+ function HttpClient() {
15
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16
16
 
17
- _classCallCheck(this, HttpClient);
17
+ _classCallCheck(this, HttpClient);
18
18
 
19
- this._baseURL = options.baseURL || '';
20
- this._headers = options.headers || {};
21
- }
22
-
23
- _createClass(HttpClient, [{
24
- key: '_fetchJSON',
25
- value: async function _fetchJSON(endpoint) {
26
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
27
-
28
- var res = await fetch(this._baseURL + endpoint, _extends({}, options, {
29
- headers: this._headers
30
- }));
31
-
32
- if (!res.ok) throw new Error(res.statusText);
33
-
34
- if (options.parseResponse !== false && res.status !== 204) {
35
- return res.json();
36
- }
37
-
38
- return undefined;
39
- }
40
- }, {
41
- key: 'setHeader',
42
- value: function setHeader(key, value) {
43
- this._headers[key] = value;
44
- return this;
45
- }
46
- }, {
47
- key: 'getHeader',
48
- value: function getHeader(key) {
49
- return this._headers[key];
50
- }
51
- }, {
52
- key: 'setBasicAuth',
53
- value: function setBasicAuth(username, password) {
54
- this._headers.Authorization = 'Basic ' + btoa(username + ':' + password);
55
- return this;
56
- }
57
- }, {
58
- key: 'setBearerAuth',
59
- value: function setBearerAuth(token) {
60
- this._headers.Authorization = 'Bearer ' + token;
61
- return this;
62
- }
63
- }, {
64
- key: 'get',
65
- value: async function get(endpoint) {
66
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
67
-
68
- return this._fetchJSON(endpoint, _extends({}, options, {
69
- method: 'GET'
70
- }));
71
- }
72
- }, {
73
- key: 'post',
74
- value: async function post(endpoint, body) {
75
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
76
-
77
- return this._fetchJSON(endpoint, _extends({}, options, {
78
- body: body ? JSON.stringify(body) : undefined,
79
- method: 'POST'
80
- }));
81
- }
82
- }, {
83
- key: 'put',
84
- value: async function put(endpoint, body) {
85
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
86
-
87
- return this._fetchJSON(endpoint, _extends({}, options, {
88
- body: body ? JSON.stringify(body) : undefined,
89
- method: 'PUT'
90
- }));
91
- }
92
- }, {
93
- key: 'patch',
94
- value: async function patch(endpoint, operations) {
95
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
96
-
97
- return this._fetchJSON(endpoint, _extends({
98
- parseResponse: false
99
- }, options, {
100
- body: JSON.stringify(operations),
101
- method: 'PATCH'
102
- }));
103
- }
104
- }, {
105
- key: 'delete',
106
- value: async function _delete(endpoint) {
107
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
108
-
109
- return this._fetchJSON(endpoint, _extends({
110
- parseResponse: false
111
- }, options, {
112
- method: 'DELETE'
113
- }));
19
+ this._baseURL = options.baseURL || '';
20
+ this._headers = options.headers || {};
114
21
  }
115
- }]);
116
22
 
117
- return HttpClient;
23
+ _createClass(HttpClient, [{
24
+ key: '_fetchJSON',
25
+ value: async function _fetchJSON(endpoint) {
26
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
27
+
28
+ var res = await fetch(this._baseURL + endpoint, _extends({}, options, {
29
+ headers: this._headers
30
+ }));
31
+
32
+ if (!res.ok) throw new Error(res.statusText);
33
+
34
+ if (options.parseResponse !== false && res.status !== 204) {
35
+ return res.json();
36
+ }
37
+
38
+ return undefined;
39
+ }
40
+ }, {
41
+ key: 'setHeader',
42
+ value: function setHeader(key, value) {
43
+ this._headers[key] = value;
44
+ return this;
45
+ }
46
+ }, {
47
+ key: 'getHeader',
48
+ value: function getHeader(key) {
49
+ return this._headers[key];
50
+ }
51
+ }, {
52
+ key: 'setBasicAuth',
53
+ value: function setBasicAuth(username, password) {
54
+ this._headers.Authorization = 'Basic ' + btoa(username + ':' + password);
55
+ return this;
56
+ }
57
+ }, {
58
+ key: 'setBearerAuth',
59
+ value: function setBearerAuth(token) {
60
+ this._headers.Authorization = 'Bearer ' + token;
61
+ return this;
62
+ }
63
+ }, {
64
+ key: 'get',
65
+ value: async function get(endpoint) {
66
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
67
+
68
+ return this._fetchJSON(endpoint, _extends({}, options, {
69
+ method: 'GET'
70
+ }));
71
+ }
72
+ }, {
73
+ key: 'post',
74
+ value: async function post(endpoint, body) {
75
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
76
+
77
+ return this._fetchJSON(endpoint, _extends({}, options, {
78
+ body: body ? JSON.stringify(body) : undefined,
79
+ method: 'POST'
80
+ }));
81
+ }
82
+ }, {
83
+ key: 'put',
84
+ value: async function put(endpoint, body) {
85
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
86
+
87
+ return this._fetchJSON(endpoint, _extends({}, options, {
88
+ body: body ? JSON.stringify(body) : undefined,
89
+ method: 'PUT'
90
+ }));
91
+ }
92
+ }, {
93
+ key: 'patch',
94
+ value: async function patch(endpoint, operations) {
95
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
96
+
97
+ return this._fetchJSON(endpoint, _extends({
98
+ parseResponse: false
99
+ }, options, {
100
+ body: JSON.stringify(operations),
101
+ method: 'PATCH'
102
+ }));
103
+ }
104
+ }, {
105
+ key: 'delete',
106
+ value: async function _delete(endpoint) {
107
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
108
+
109
+ return this._fetchJSON(endpoint, _extends({
110
+ parseResponse: false
111
+ }, options, {
112
+ method: 'DELETE'
113
+ }));
114
+ }
115
+ }]);
116
+
117
+ return HttpClient;
118
118
  }();
119
119
 
120
120
  exports.default = HttpClient;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
6
  exports.DJClient = undefined;
7
7
 
@@ -20,94 +20,315 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
20
20
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
21
21
 
22
22
  var DJClient = exports.DJClient = function (_HttpClient) {
23
- _inherits(DJClient, _HttpClient);
23
+ _inherits(DJClient, _HttpClient);
24
24
 
25
- function DJClient(baseURL) {
26
- _classCallCheck(this, DJClient);
25
+ function DJClient(baseURL, namespace) {
26
+ var engineName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
27
+ var engineVersion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
27
28
 
28
- return _possibleConstructorReturn(this, (DJClient.__proto__ || Object.getPrototypeOf(DJClient)).call(this, {
29
- baseURL: baseURL
30
- }));
31
- }
29
+ _classCallCheck(this, DJClient);
32
30
 
33
- _createClass(DJClient, [{
34
- key: 'catalogs',
35
- get: function get() {
36
- var _this2 = this;
31
+ var _this = _possibleConstructorReturn(this, (DJClient.__proto__ || Object.getPrototypeOf(DJClient)).call(this, {
32
+ baseURL: baseURL
33
+ }));
37
34
 
38
- return {
35
+ _this.namespace = namespace;
36
+ _this.engineName = engineName;
37
+ _this.engineVersion = engineVersion;
38
+ return _this;
39
+ }
40
+
41
+ _createClass(DJClient, [{
42
+ key: 'healthcheck',
39
43
  get: function get() {
40
- return _this2.get('/catalogs/');
44
+ var _this2 = this;
45
+
46
+ return {
47
+ get: function get() {
48
+ return _this2.get('/health/');
49
+ }
50
+ };
41
51
  }
42
- };
43
- }
44
- }, {
45
- key: 'engines',
46
- get: function get() {
47
- var _this3 = this;
52
+ }, {
53
+ key: 'catalog',
54
+ get: function get() {
55
+ var _this3 = this;
48
56
 
49
- return {
57
+ return {
58
+ list: function list() {
59
+ return _this3.get('/catalogs/');
60
+ },
61
+ get: function get(catalog) {
62
+ return _this3.get('/catalogs/' + catalog + '/');
63
+ },
64
+ create: function create(engine) {
65
+ return _this3.setHeader('Content-Type', 'application/json').post('/catalogs/', engine);
66
+ }
67
+ };
68
+ }
69
+ }, {
70
+ key: 'engines',
50
71
  get: function get() {
51
- return _this3.get('/engines/');
72
+ var _this4 = this;
73
+
74
+ return {
75
+ list: function list() {
76
+ return _this4.get('/engines/');
77
+ },
78
+ get: function get(engineName, engineVersion) {
79
+ return _this4.get('/engines/' + engineName + '/' + engineVersion + '/');
80
+ },
81
+ create: function create(engine) {
82
+ return _this4.setHeader('Content-Type', 'application/json').post('/engines/', engine);
83
+ }
84
+ };
52
85
  }
53
- };
54
- }
55
- }, {
56
- key: 'namespaces',
57
- get: function get() {
58
- var _this4 = this;
86
+ }, {
87
+ key: 'addEngineToCatalog',
88
+ get: function get() {
89
+ var _this5 = this;
59
90
 
60
- return {
91
+ return {
92
+ set: function set(catalogName, engine) {
93
+ return _this5.setHeader('Content-Type', 'application/json').post('/catalogs/' + catalogName + '/engines/', [engine]);
94
+ }
95
+ };
96
+ }
97
+ }, {
98
+ key: 'namespaces',
61
99
  get: function get() {
62
- return _this4.get('/namespaces/');
100
+ var _this6 = this;
101
+
102
+ return {
103
+ list: function list() {
104
+ return _this6.get('/namespaces/');
105
+ },
106
+ nodes: function nodes(namespace) {
107
+ return _this6.get('/namespaces/' + namespace + '/');
108
+ },
109
+ create: function create(namespace) {
110
+ return _this6.setHeader('Content-Type', 'application/json').post('/namespaces/' + namespace + '/');
111
+ }
112
+ };
63
113
  }
64
- };
65
- }
66
- }, {
67
- key: 'metrics',
68
- get: function get() {
69
- var _this5 = this;
114
+ }, {
115
+ key: 'commonDimensions',
116
+ get: function get() {
117
+ var _this7 = this;
70
118
 
71
- return {
119
+ return {
120
+ list: function list(metrics) {
121
+ return _this7.get('/metrics/common/dimensions/?metric=' + encodeURIComponent(JSON.stringify(metrics)));
122
+ }
123
+ };
124
+ }
125
+ }, {
126
+ key: 'nodes',
72
127
  get: function get() {
73
- return _this5.get('/metrics/');
128
+ var _this8 = this;
129
+
130
+ return {
131
+ get: function get(nodeName) {
132
+ return _this8.get('/nodes/' + nodeName + '/');
133
+ },
134
+ validate: function validate(nodeDetails) {
135
+ return _this8.setHeader('Content-Type', 'application/json').post('/nodes/validate/', nodeDetails);
136
+ },
137
+ update: function update(nodeName, nodeDetails) {
138
+ return _this8.setHeader('Content-Type', 'application/json').patch('/nodes/' + nodeName + '/', nodeDetails);
139
+ },
140
+ revisions: function revisions(nodeName) {
141
+ return _this8.get('/nodes/' + nodeName + '/revisions/');
142
+ },
143
+ downstream: function downstream(nodeName) {
144
+ return _this8.get('/nodes/' + nodeName + '/downstream/');
145
+ },
146
+ upstream: function upstream(nodeName) {
147
+ return _this8.get('/nodes/' + nodeName + '/upstream/');
148
+ }
149
+ };
74
150
  }
75
- };
76
- }
77
- }, {
78
- key: 'nodes',
79
- get: function get() {
80
- var _this6 = this;
151
+ }, {
152
+ key: 'sources',
153
+ get: function get() {
154
+ var _this9 = this;
81
155
 
82
- return {
156
+ return {
157
+ create: function create(sourceDetails) {
158
+ return _this9.setHeader('Content-Type', 'application/json').post('/nodes/source/', sourceDetails);
159
+ },
160
+ list: function list() {
161
+ return _this9.get('/namespaces/' + _this9.namespace + '/?type_=source');
162
+ }
163
+ };
164
+ }
165
+ }, {
166
+ key: 'transforms',
83
167
  get: function get() {
84
- return _this6.get('/nodes/');
168
+ var _this10 = this;
169
+
170
+ return {
171
+ create: function create(transformDetails) {
172
+ return _this10.setHeader('Content-Type', 'application/json').post('/nodes/transform/', transformDetails);
173
+ },
174
+ list: function list() {
175
+ return _this10.get('/namespaces/' + _this10.namespace + '/?type_=transform');
176
+ }
177
+ };
85
178
  }
86
- };
87
- }
88
- }, {
89
- key: 'tags',
90
- get: function get() {
91
- var _this7 = this;
179
+ }, {
180
+ key: 'dimensions',
181
+ get: function get() {
182
+ var _this11 = this;
183
+
184
+ return {
185
+ create: function create(dimensionDetails) {
186
+ return _this11.setHeader('Content-Type', 'application/json').post('/nodes/dimension/', dimensionDetails);
187
+ },
188
+ list: function list() {
189
+ return _this11.get('/namespaces/' + _this11.namespace + '/?type_=dimension');
190
+ },
191
+ link: function link(nodeName, nodeColumn, dimension, dimensionColumn) {
192
+ return _this11.post('/nodes/' + nodeName + '/columns/' + nodeColumn + '/?dimension=' + dimension + '&dimension_column=' + dimensionColumn);
193
+ }
194
+ };
195
+ }
196
+ }, {
197
+ key: 'metrics',
198
+ get: function get() {
199
+ var _this12 = this;
92
200
 
93
- return {
201
+ return {
202
+ get: function get(metricName) {
203
+ return _this12.get('/metrics/' + metricName + '/');
204
+ },
205
+ create: function create(metricDetails) {
206
+ return _this12.setHeader('Content-Type', 'application/json').post('/nodes/metric/', metricDetails);
207
+ },
208
+ list: function list() {
209
+ return _this12.get('/namespaces/' + _this12.namespace + '/?type_=metric');
210
+ },
211
+ all: function all() {
212
+ return _this12.get('/metrics/');
213
+ }
214
+ };
215
+ }
216
+ }, {
217
+ key: 'cubes',
94
218
  get: function get() {
95
- return _this7.get('/tags/');
219
+ var _this13 = this;
220
+
221
+ return {
222
+ get: function get(cubeName) {
223
+ return _this13.get('/cubes/' + cubeName + '/');
224
+ },
225
+ create: function create(cubeDetails) {
226
+ return _this13.setHeader('Content-Type', 'application/json').post('/nodes/cube/', cubeDetails);
227
+ }
228
+ };
96
229
  }
97
- };
98
- }
99
- }, {
100
- key: 'attributes',
101
- get: function get() {
102
- var _this8 = this;
230
+ }, {
231
+ key: 'tags',
232
+ get: function get() {
233
+ var _this14 = this;
234
+
235
+ return {
236
+ list: function list() {
237
+ return _this14.get('/tags/');
238
+ },
239
+ get: function get(tagName) {
240
+ return _this14.get('/tags/' + tagName + '/');
241
+ },
242
+ create: function create(tagData) {
243
+ return _this14.setHeader('Content-Type', 'application/json').post('/tags/', tagData);
244
+ },
245
+ update: function update(tagName, tagData) {
246
+ return _this14.setHeader('Content-Type', 'application/json').patch('/tags/' + tagName + '/', tagData);
247
+ },
248
+ set: function set(nodeName, tagName) {
249
+ return _this14.post('/nodes/' + nodeName + '/tag/?tag_name=' + tagName);
250
+ },
251
+ listNodes: function listNodes(tagName) {
252
+ return _this14.get('/tags/' + tagName + '/nodes/');
253
+ }
254
+ };
255
+ }
256
+ }, {
257
+ key: 'attributes',
258
+ get: function get() {
259
+ var _this15 = this;
103
260
 
104
- return {
261
+ return {
262
+ list: function list() {
263
+ return _this15.get('/attributes/');
264
+ },
265
+ create: function create(attributeData) {
266
+ return _this15.setHeader('Content-Type', 'application/json').post('/attributes/', attributeData);
267
+ }
268
+ };
269
+ }
270
+ }, {
271
+ key: 'materializationConfigs',
105
272
  get: function get() {
106
- return _this8.get('/attributes/');
273
+ var _this16 = this;
274
+
275
+ return {
276
+ update: function update(nodeName, materializationDetails) {
277
+ return _this16.setHeader('Content-Type', 'application/json').post('/nodes/' + nodeName + '/materialization/', materializationDetails);
278
+ }
279
+ };
107
280
  }
108
- };
109
- }
110
- }]);
281
+ }, {
282
+ key: 'columnAttributes',
283
+ get: function get() {
284
+ var _this17 = this;
285
+
286
+ return {
287
+ set: function set(nodeName, columnAttribute) {
288
+ return _this17.setHeader('Content-Type', 'application/json').post('/nodes/' + nodeName + '/attributes/', [columnAttribute]);
289
+ }
290
+ };
291
+ }
292
+ }, {
293
+ key: 'availabilityState',
294
+ get: function get() {
295
+ var _this18 = this;
296
+
297
+ return {
298
+ set: function set(nodeName, availabilityState) {
299
+ return _this18.setHeader('Content-Type', 'application/json').post('/data/' + nodeName + '/availability/', availabilityState);
300
+ }
301
+ };
302
+ }
303
+ }, {
304
+ key: 'sql',
305
+ get: function get() {
306
+ var _this19 = this;
307
+
308
+ return {
309
+ get: function get(metrics, dimensions, filters) {
310
+ var async_ = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
311
+ var engineName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
312
+ var engineVersion = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
313
+ return _this19.get('/sql/?metrics=' + metrics + '&dimensions=' + dimensions + '&filters=' + filters + '&async_=' + async_ + '&engine_name=' + (engineName || _this19.engineName) + '&engine_version=' + (engineVersion || _this19.engineVersion));
314
+ }
315
+ };
316
+ }
317
+ }, {
318
+ key: 'data',
319
+ get: function get() {
320
+ var _this20 = this;
321
+
322
+ return {
323
+ get: function get(metrics, dimensions, filters) {
324
+ var async_ = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
325
+ var engineName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
326
+ var engineVersion = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
327
+ return _this20.get('/data/?metrics=' + metrics + '&dimensions=' + dimensions + '&filters=' + filters + '&async_=' + async_ + '&engine_name=' + (engineName || _this20.engineName) + '&engine_version=' + (engineVersion || _this20.engineVersion));
328
+ }
329
+ };
330
+ }
331
+ }]);
111
332
 
112
- return DJClient;
333
+ return DJClient;
113
334
  }(_httpclient2.default);
package/index.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist')
1
+ module.exports = require('./dist')
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "datajunction",
3
- "version": "0.0.1-rc.0",
3
+ "version": "0.0.1-rc.1",
4
4
  "description": "A Javascript client for interacting with a DataJunction server",
5
5
  "module": "src/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
8
  "build": "rm -rf dist/* && webpack && babel src -d dist",
9
- "lint": "eslint src --ext .js",
10
- "lint:fix": "npm run lint -- --fix"
9
+ "lint": "prettier \"src/**/*.{js,jsx}\"",
10
+ "format": "prettier --write \"src/**/*.{js,jsx}\""
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -34,6 +34,7 @@
34
34
  "eslint-plugin-import": "^2.27.5",
35
35
  "eslint-plugin-n": "^15.7.0",
36
36
  "eslint-plugin-promise": "^6.1.1",
37
+ "prettier": "^2.8.8",
37
38
  "webpack": "^5.81.0",
38
39
  "webpack-cli": "^5.0.2"
39
40
  }
package/src/httpclient.js CHANGED
@@ -1,78 +1,80 @@
1
1
  export default class HttpClient {
2
- constructor (options = {}) {
3
- this._baseURL = options.baseURL || ''
4
- this._headers = options.headers || {}
5
- }
2
+ constructor(options = {}) {
3
+ this._baseURL = options.baseURL || ''
4
+ this._headers = options.headers || {}
5
+ }
6
6
 
7
- async _fetchJSON (endpoint, options = {}) {
8
- const res = await fetch(this._baseURL + endpoint, {
9
- ...options,
10
- headers: this._headers
11
- })
7
+ async _fetchJSON(endpoint, options = {}) {
8
+ const res = await fetch(this._baseURL + endpoint, {
9
+ ...options,
10
+ headers: this._headers,
11
+ })
12
12
 
13
- if (!res.ok) throw new Error(res.statusText)
13
+ if (!res.ok) throw new Error(res.statusText)
14
14
 
15
- if (options.parseResponse !== false && res.status !== 204) { return res.json() }
15
+ if (options.parseResponse !== false && res.status !== 204) {
16
+ return res.json()
17
+ }
16
18
 
17
- return undefined
18
- }
19
+ return undefined
20
+ }
19
21
 
20
- setHeader (key, value) {
21
- this._headers[key] = value
22
- return this
23
- }
22
+ setHeader(key, value) {
23
+ this._headers[key] = value
24
+ return this
25
+ }
24
26
 
25
- getHeader (key) {
26
- return this._headers[key]
27
- }
27
+ getHeader(key) {
28
+ return this._headers[key]
29
+ }
28
30
 
29
- setBasicAuth (username, password) {
30
- this._headers.Authorization = `Basic ${btoa(`${username}:${password}`)}`
31
- return this
32
- }
31
+ setBasicAuth(username, password) {
32
+ this._headers.Authorization = `Basic ${btoa(`${username}:${password}`)}`
33
+ return this
34
+ }
33
35
 
34
- setBearerAuth (token) {
35
- this._headers.Authorization = `Bearer ${token}`
36
- return this
37
- }
36
+ setBearerAuth(token) {
37
+ this._headers.Authorization = `Bearer ${token}`
38
+ return this
39
+ }
38
40
 
39
- async get (endpoint, options = {}) {
40
- return this._fetchJSON(endpoint, {
41
- ...options,
42
- method: 'GET'
43
- })
44
- }
41
+ async get(endpoint, options = {}) {
42
+ return this._fetchJSON(endpoint, {
43
+ ...options,
44
+ method: 'GET',
45
+ })
46
+ }
45
47
 
46
- async post (endpoint, body, options = {}) {
47
- return this._fetchJSON(endpoint, {
48
- ...options,
49
- body: body ? JSON.stringify(body) : undefined,
50
- method: 'POST'
51
- })
52
- }
48
+ async post(endpoint, body, options = {}) {
49
+ return this._fetchJSON(endpoint, {
50
+ ...options,
51
+ body: body ? JSON.stringify(body) : undefined,
52
+ method: 'POST',
53
+ })
54
+ }
53
55
 
54
- async put (endpoint, body, options = {}) {
55
- return this._fetchJSON(endpoint, {
56
- ...options,
57
- body: body ? JSON.stringify(body) : undefined,
58
- method: 'PUT'
59
- })
60
- }
56
+ async put(endpoint, body, options = {}) {
57
+ return this._fetchJSON(endpoint, {
58
+ ...options,
59
+ body: body ? JSON.stringify(body) : undefined,
60
+ method: 'PUT',
61
+ })
62
+ }
61
63
 
62
- async patch (endpoint, operations, options = {}) {
63
- return this._fetchJSON(endpoint, {
64
- parseResponse: false,
65
- ...options,
66
- body: JSON.stringify(operations),
67
- method: 'PATCH'
68
- })
69
- }
64
+ async patch(endpoint, operations, options = {}) {
65
+ return this._fetchJSON(endpoint, {
66
+ parseResponse: false,
67
+ ...options,
68
+ body: JSON.stringify(operations),
69
+ method: 'PATCH',
70
+ })
71
+ }
70
72
 
71
- async delete (endpoint, options = {}) {
72
- return this._fetchJSON(endpoint, {
73
- parseResponse: false,
74
- ...options,
75
- method: 'DELETE'
76
- })
77
- }
73
+ async delete(endpoint, options = {}) {
74
+ return this._fetchJSON(endpoint, {
75
+ parseResponse: false,
76
+ ...options,
77
+ method: 'DELETE',
78
+ })
79
+ }
78
80
  }
package/src/index.js CHANGED
@@ -1,51 +1,255 @@
1
1
  import HttpClient from './httpclient.js'
2
2
 
3
3
  export class DJClient extends HttpClient {
4
- constructor (baseURL) {
5
- super({
6
- baseURL
7
- })
8
- }
4
+ constructor(baseURL, namespace, engineName = null, engineVersion = null) {
5
+ super({
6
+ baseURL,
7
+ })
8
+ this.namespace = namespace
9
+ this.engineName = engineName
10
+ this.engineVersion = engineVersion
11
+ }
12
+
13
+ get healthcheck() {
14
+ return {
15
+ get: () => this.get('/health/'),
16
+ }
17
+ }
18
+
19
+ get catalog() {
20
+ return {
21
+ list: () => this.get('/catalogs/'),
22
+ get: (catalog) => this.get(`/catalogs/${catalog}/`),
23
+ create: (engine) =>
24
+ this.setHeader('Content-Type', 'application/json').post(
25
+ '/catalogs/',
26
+ engine
27
+ ),
28
+ }
29
+ }
30
+
31
+ get engines() {
32
+ return {
33
+ list: () => this.get('/engines/'),
34
+ get: (engineName, engineVersion) =>
35
+ this.get(`/engines/${engineName}/${engineVersion}/`),
36
+ create: (engine) =>
37
+ this.setHeader('Content-Type', 'application/json').post(
38
+ '/engines/',
39
+ engine
40
+ ),
41
+ }
42
+ }
43
+
44
+ get addEngineToCatalog() {
45
+ return {
46
+ set: (catalogName, engine) =>
47
+ this.setHeader('Content-Type', 'application/json').post(
48
+ `/catalogs/${catalogName}/engines/`,
49
+ [engine]
50
+ ),
51
+ }
52
+ }
53
+
54
+ get namespaces() {
55
+ return {
56
+ list: () => this.get('/namespaces/'),
57
+ nodes: (namespace) => this.get(`/namespaces/${namespace}/`),
58
+ create: (namespace) =>
59
+ this.setHeader('Content-Type', 'application/json').post(
60
+ `/namespaces/${namespace}/`
61
+ ),
62
+ }
63
+ }
64
+
65
+ get commonDimensions() {
66
+ return {
67
+ list: (metrics) =>
68
+ this.get(
69
+ `/metrics/common/dimensions/?metric=${encodeURIComponent(
70
+ JSON.stringify(metrics)
71
+ )}`
72
+ ),
73
+ }
74
+ }
75
+
76
+ get nodes() {
77
+ return {
78
+ get: (nodeName) => this.get(`/nodes/${nodeName}/`),
79
+ validate: (nodeDetails) =>
80
+ this.setHeader('Content-Type', 'application/json').post(
81
+ '/nodes/validate/',
82
+ nodeDetails
83
+ ),
84
+ update: (nodeName, nodeDetails) =>
85
+ this.setHeader('Content-Type', 'application/json').patch(
86
+ `/nodes/${nodeName}/`,
87
+ nodeDetails
88
+ ),
89
+ revisions: (nodeName) => this.get(`/nodes/${nodeName}/revisions/`),
90
+ downstream: (nodeName) =>
91
+ this.get(`/nodes/${nodeName}/downstream/`),
92
+ upstream: (nodeName) => this.get(`/nodes/${nodeName}/upstream/`),
93
+ }
94
+ }
95
+
96
+ get sources() {
97
+ return {
98
+ create: (sourceDetails) =>
99
+ this.setHeader('Content-Type', 'application/json').post(
100
+ '/nodes/source/',
101
+ sourceDetails
102
+ ),
103
+ list: () => this.get(`/namespaces/${this.namespace}/?type_=source`),
104
+ }
105
+ }
106
+
107
+ get transforms() {
108
+ return {
109
+ create: (transformDetails) =>
110
+ this.setHeader('Content-Type', 'application/json').post(
111
+ '/nodes/transform/',
112
+ transformDetails
113
+ ),
114
+ list: () =>
115
+ this.get(`/namespaces/${this.namespace}/?type_=transform`),
116
+ }
117
+ }
118
+
119
+ get dimensions() {
120
+ return {
121
+ create: (dimensionDetails) =>
122
+ this.setHeader('Content-Type', 'application/json').post(
123
+ '/nodes/dimension/',
124
+ dimensionDetails
125
+ ),
126
+ list: () =>
127
+ this.get(`/namespaces/${this.namespace}/?type_=dimension`),
128
+ link: (nodeName, nodeColumn, dimension, dimensionColumn) =>
129
+ this.post(
130
+ `/nodes/${nodeName}/columns/${nodeColumn}/?dimension=${dimension}&dimension_column=${dimensionColumn}`
131
+ ),
132
+ }
133
+ }
134
+
135
+ get metrics() {
136
+ return {
137
+ get: (metricName) => this.get(`/metrics/${metricName}/`),
138
+ create: (metricDetails) =>
139
+ this.setHeader('Content-Type', 'application/json').post(
140
+ '/nodes/metric/',
141
+ metricDetails
142
+ ),
143
+ list: () => this.get(`/namespaces/${this.namespace}/?type_=metric`),
144
+ all: () => this.get(`/metrics/`),
145
+ }
146
+ }
147
+
148
+ get cubes() {
149
+ return {
150
+ get: (cubeName) => this.get(`/cubes/${cubeName}/`),
151
+ create: (cubeDetails) =>
152
+ this.setHeader('Content-Type', 'application/json').post(
153
+ '/nodes/cube/',
154
+ cubeDetails
155
+ ),
156
+ }
157
+ }
9
158
 
10
- get catalogs () {
11
- return {
12
- get: () => this.get('/catalogs/')
159
+ get tags() {
160
+ return {
161
+ list: () => this.get('/tags/'),
162
+ get: (tagName) => this.get(`/tags/${tagName}/`),
163
+ create: (tagData) =>
164
+ this.setHeader('Content-Type', 'application/json').post(
165
+ '/tags/',
166
+ tagData
167
+ ),
168
+ update: (tagName, tagData) =>
169
+ this.setHeader('Content-Type', 'application/json').patch(
170
+ `/tags/${tagName}/`,
171
+ tagData
172
+ ),
173
+ set: (nodeName, tagName) =>
174
+ this.post(`/nodes/${nodeName}/tag/?tag_name=${tagName}`),
175
+ listNodes: (tagName) => this.get(`/tags/${tagName}/nodes/`),
176
+ }
13
177
  }
14
- }
15
178
 
16
- get engines () {
17
- return {
18
- get: () => this.get('/engines/')
179
+ get attributes() {
180
+ return {
181
+ list: () => this.get('/attributes/'),
182
+ create: (attributeData) =>
183
+ this.setHeader('Content-Type', 'application/json').post(
184
+ '/attributes/',
185
+ attributeData
186
+ ),
187
+ }
19
188
  }
20
- }
21
189
 
22
- get namespaces () {
23
- return {
24
- get: () => this.get('/namespaces/')
190
+ get materializationConfigs() {
191
+ return {
192
+ update: (nodeName, materializationDetails) =>
193
+ this.setHeader('Content-Type', 'application/json').post(
194
+ `/nodes/${nodeName}/materialization/`,
195
+ materializationDetails
196
+ ),
197
+ }
25
198
  }
26
- }
27
199
 
28
- get metrics () {
29
- return {
30
- get: () => this.get('/metrics/')
200
+ get columnAttributes() {
201
+ return {
202
+ set: (nodeName, columnAttribute) =>
203
+ this.setHeader('Content-Type', 'application/json').post(
204
+ `/nodes/${nodeName}/attributes/`,
205
+ [columnAttribute]
206
+ ),
207
+ }
31
208
  }
32
- }
33
209
 
34
- get nodes () {
35
- return {
36
- get: () => this.get('/nodes/')
210
+ get availabilityState() {
211
+ return {
212
+ set: (nodeName, availabilityState) =>
213
+ this.setHeader('Content-Type', 'application/json').post(
214
+ `/data/${nodeName}/availability/`,
215
+ availabilityState
216
+ ),
217
+ }
37
218
  }
38
- }
39
219
 
40
- get tags () {
41
- return {
42
- get: () => this.get('/tags/')
220
+ get sql() {
221
+ return {
222
+ get: (
223
+ metrics,
224
+ dimensions,
225
+ filters,
226
+ async_ = false,
227
+ engineName = null,
228
+ engineVersion = null
229
+ ) =>
230
+ this.get(
231
+ `/sql/?metrics=${metrics}&dimensions=${dimensions}&filters=${filters}&async_=${async_}&engine_name=${
232
+ engineName || this.engineName
233
+ }&engine_version=${engineVersion || this.engineVersion}`
234
+ ),
235
+ }
43
236
  }
44
- }
45
237
 
46
- get attributes () {
47
- return {
48
- get: () => this.get('/attributes/')
238
+ get data() {
239
+ return {
240
+ get: (
241
+ metrics,
242
+ dimensions,
243
+ filters,
244
+ async_ = false,
245
+ engineName = null,
246
+ engineVersion = null
247
+ ) =>
248
+ this.get(
249
+ `/data/?metrics=${metrics}&dimensions=${dimensions}&filters=${filters}&async_=${async_}&engine_name=${
250
+ engineName || this.engineName
251
+ }&engine_version=${engineVersion || this.engineVersion}`
252
+ ),
253
+ }
49
254
  }
50
- }
51
255
  }
package/webpack.config.js CHANGED
@@ -1,8 +1,8 @@
1
- const path = require('path');
1
+ const path = require('path')
2
2
 
3
3
  module.exports = {
4
4
  entry: './src/index.js',
5
- mode: "production",
5
+ mode: 'production',
6
6
  output: {
7
7
  path: path.resolve(__dirname, 'dist'),
8
8
  filename: 'datajunction.js',
@@ -12,4 +12,4 @@ module.exports = {
12
12
  type: 'umd',
13
13
  },
14
14
  },
15
- };
15
+ }