datajunction 0.0.1-rc.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/.babelrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "presets": [
3
+ "es2015"
4
+ ],
5
+ "plugins": [
6
+ "transform-object-rest-spread"
7
+ ]
8
+ }
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ ./dist/*
package/.eslintrc.js ADDED
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es2021: true
5
+ },
6
+ extends: 'standard',
7
+ overrides: [
8
+ ],
9
+ parserOptions: {
10
+ ecmaVersion: 'latest',
11
+ sourceType: 'module'
12
+ },
13
+ rules: {
14
+ }
15
+ }
@@ -0,0 +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})()));
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
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; };
8
+
9
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
10
+
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+
13
+ var HttpClient = function () {
14
+ function HttpClient() {
15
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16
+
17
+ _classCallCheck(this, HttpClient);
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
+ }));
114
+ }
115
+ }]);
116
+
117
+ return HttpClient;
118
+ }();
119
+
120
+ exports.default = HttpClient;
package/dist/index.js ADDED
@@ -0,0 +1,113 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DJClient = undefined;
7
+
8
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
9
+
10
+ var _httpclient = require('./httpclient.js');
11
+
12
+ var _httpclient2 = _interopRequireDefault(_httpclient);
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
19
+
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
+
22
+ var DJClient = exports.DJClient = function (_HttpClient) {
23
+ _inherits(DJClient, _HttpClient);
24
+
25
+ function DJClient(baseURL) {
26
+ _classCallCheck(this, DJClient);
27
+
28
+ return _possibleConstructorReturn(this, (DJClient.__proto__ || Object.getPrototypeOf(DJClient)).call(this, {
29
+ baseURL: baseURL
30
+ }));
31
+ }
32
+
33
+ _createClass(DJClient, [{
34
+ key: 'catalogs',
35
+ get: function get() {
36
+ var _this2 = this;
37
+
38
+ return {
39
+ get: function get() {
40
+ return _this2.get('/catalogs/');
41
+ }
42
+ };
43
+ }
44
+ }, {
45
+ key: 'engines',
46
+ get: function get() {
47
+ var _this3 = this;
48
+
49
+ return {
50
+ get: function get() {
51
+ return _this3.get('/engines/');
52
+ }
53
+ };
54
+ }
55
+ }, {
56
+ key: 'namespaces',
57
+ get: function get() {
58
+ var _this4 = this;
59
+
60
+ return {
61
+ get: function get() {
62
+ return _this4.get('/namespaces/');
63
+ }
64
+ };
65
+ }
66
+ }, {
67
+ key: 'metrics',
68
+ get: function get() {
69
+ var _this5 = this;
70
+
71
+ return {
72
+ get: function get() {
73
+ return _this5.get('/metrics/');
74
+ }
75
+ };
76
+ }
77
+ }, {
78
+ key: 'nodes',
79
+ get: function get() {
80
+ var _this6 = this;
81
+
82
+ return {
83
+ get: function get() {
84
+ return _this6.get('/nodes/');
85
+ }
86
+ };
87
+ }
88
+ }, {
89
+ key: 'tags',
90
+ get: function get() {
91
+ var _this7 = this;
92
+
93
+ return {
94
+ get: function get() {
95
+ return _this7.get('/tags/');
96
+ }
97
+ };
98
+ }
99
+ }, {
100
+ key: 'attributes',
101
+ get: function get() {
102
+ var _this8 = this;
103
+
104
+ return {
105
+ get: function get() {
106
+ return _this8.get('/attributes/');
107
+ }
108
+ };
109
+ }
110
+ }]);
111
+
112
+ return DJClient;
113
+ }(_httpclient2.default);
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist')
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "datajunction",
3
+ "version": "0.0.1-rc.0",
4
+ "description": "A Javascript client for interacting with a DataJunction server",
5
+ "module": "src/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "rm -rf dist/* && webpack && babel src -d dist",
9
+ "lint": "eslint src --ext .js",
10
+ "lint:fix": "npm run lint -- --fix"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/DataJunction/dj.git"
15
+ },
16
+ "keywords": [
17
+ "datajunction",
18
+ "metrics",
19
+ "metrics-platform",
20
+ "semantic-layer"
21
+ ],
22
+ "author": "DataJunction Authors",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/DataJunction/dj/issues"
26
+ },
27
+ "homepage": "https://github.com/DataJunction/dj#readme",
28
+ "devDependencies": {
29
+ "babel-cli": "^6.26.0",
30
+ "babel-plugin-transform-object-rest-spread": "^6.26.0",
31
+ "babel-preset-es2015": "^6.24.1",
32
+ "eslint": "^8.39.0",
33
+ "eslint-config-standard": "^17.0.0",
34
+ "eslint-plugin-import": "^2.27.5",
35
+ "eslint-plugin-n": "^15.7.0",
36
+ "eslint-plugin-promise": "^6.1.1",
37
+ "webpack": "^5.81.0",
38
+ "webpack-cli": "^5.0.2"
39
+ }
40
+ }
@@ -0,0 +1,78 @@
1
+ export default class HttpClient {
2
+ constructor (options = {}) {
3
+ this._baseURL = options.baseURL || ''
4
+ this._headers = options.headers || {}
5
+ }
6
+
7
+ async _fetchJSON (endpoint, options = {}) {
8
+ const res = await fetch(this._baseURL + endpoint, {
9
+ ...options,
10
+ headers: this._headers
11
+ })
12
+
13
+ if (!res.ok) throw new Error(res.statusText)
14
+
15
+ if (options.parseResponse !== false && res.status !== 204) { return res.json() }
16
+
17
+ return undefined
18
+ }
19
+
20
+ setHeader (key, value) {
21
+ this._headers[key] = value
22
+ return this
23
+ }
24
+
25
+ getHeader (key) {
26
+ return this._headers[key]
27
+ }
28
+
29
+ setBasicAuth (username, password) {
30
+ this._headers.Authorization = `Basic ${btoa(`${username}:${password}`)}`
31
+ return this
32
+ }
33
+
34
+ setBearerAuth (token) {
35
+ this._headers.Authorization = `Bearer ${token}`
36
+ return this
37
+ }
38
+
39
+ async get (endpoint, options = {}) {
40
+ return this._fetchJSON(endpoint, {
41
+ ...options,
42
+ method: 'GET'
43
+ })
44
+ }
45
+
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
+ }
53
+
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
+ }
61
+
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
+ }
70
+
71
+ async delete (endpoint, options = {}) {
72
+ return this._fetchJSON(endpoint, {
73
+ parseResponse: false,
74
+ ...options,
75
+ method: 'DELETE'
76
+ })
77
+ }
78
+ }
package/src/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import HttpClient from './httpclient.js'
2
+
3
+ export class DJClient extends HttpClient {
4
+ constructor (baseURL) {
5
+ super({
6
+ baseURL
7
+ })
8
+ }
9
+
10
+ get catalogs () {
11
+ return {
12
+ get: () => this.get('/catalogs/')
13
+ }
14
+ }
15
+
16
+ get engines () {
17
+ return {
18
+ get: () => this.get('/engines/')
19
+ }
20
+ }
21
+
22
+ get namespaces () {
23
+ return {
24
+ get: () => this.get('/namespaces/')
25
+ }
26
+ }
27
+
28
+ get metrics () {
29
+ return {
30
+ get: () => this.get('/metrics/')
31
+ }
32
+ }
33
+
34
+ get nodes () {
35
+ return {
36
+ get: () => this.get('/nodes/')
37
+ }
38
+ }
39
+
40
+ get tags () {
41
+ return {
42
+ get: () => this.get('/tags/')
43
+ }
44
+ }
45
+
46
+ get attributes () {
47
+ return {
48
+ get: () => this.get('/attributes/')
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,15 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './src/index.js',
5
+ mode: "production",
6
+ output: {
7
+ path: path.resolve(__dirname, 'dist'),
8
+ filename: 'datajunction.js',
9
+ globalObject: 'this',
10
+ library: {
11
+ name: 'datajunction',
12
+ type: 'umd',
13
+ },
14
+ },
15
+ };