Skip to content

Commit 517d3b6

Browse files
committed
Build step.
1 parent d9f9d01 commit 517d3b6

14 files changed

Lines changed: 3662 additions & 30 deletions

File tree

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"presets": ["@babel/preset-env"],
2+
"presets": ["es2015"],
33
"plugins": [
4-
["@babel/transform-runtime"]
54
]
65
}

dist/Dto/Config.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
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; }; }();
8+
9+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10+
11+
var Config = function () {
12+
function Config(config) {
13+
_classCallCheck(this, Config);
14+
15+
this.setConfig(config);
16+
}
17+
18+
_createClass(Config, [{
19+
key: "setConfig",
20+
value: function setConfig(config) {
21+
this.config = config;
22+
23+
return this;
24+
}
25+
}, {
26+
key: "uri",
27+
value: function uri() {
28+
var suffix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
29+
30+
var base = this.config.domain + "/" + this.config.base;
31+
32+
if (suffix) {
33+
return base + "/" + suffix;
34+
}
35+
36+
return base;
37+
}
38+
}, {
39+
key: "baseUri",
40+
value: function baseUri() {
41+
var suffix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
42+
43+
var base = "" + this.config.domain;
44+
45+
if (suffix) {
46+
return base + "/" + suffix;
47+
}
48+
49+
return base;
50+
}
51+
}], [{
52+
key: "make",
53+
value: function make(config) {
54+
return new this(config);
55+
}
56+
}]);
57+
58+
return Config;
59+
}();
60+
61+
exports.default = Config;

dist/Repository/Repository.js

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
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+
var _helpers = require('../Support/helpers');
12+
13+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14+
15+
var Repository = function () {
16+
function Repository(definition) {
17+
_classCallCheck(this, Repository);
18+
19+
this.$sort = [];
20+
this.$search = [];
21+
this.$match = [];
22+
this.$related = [];
23+
this.$actions = [];
24+
25+
if (typeof definition === 'string') {
26+
return this.uriKey = definition;
27+
}
28+
29+
if ((typeof definition === 'undefined' ? 'undefined' : _typeof(definition)) === 'object') {
30+
if (!definition.hasOwnProperty('uriKey')) {
31+
throw new Error('Invalid repository definition.');
32+
}
33+
34+
return this.setUriKey(definition.uriKey).setName(definition.name).setSorts(definition.sort).setMatches(definition.match).setRelated(definition.related).setSearcheables(definition.searchables).setActions(definition.actions);
35+
}
36+
}
37+
38+
_createClass(Repository, [{
39+
key: 'setUriKey',
40+
value: function setUriKey(uriKey) {
41+
this.uriKey = uriKey;
42+
43+
return this;
44+
}
45+
}, {
46+
key: 'setName',
47+
value: function setName(name) {
48+
this.name = name;
49+
50+
return this;
51+
}
52+
}, {
53+
key: 'setConfig',
54+
value: function setConfig(config) {
55+
this.config = config;
56+
57+
return this;
58+
}
59+
}, {
60+
key: 'setRequest',
61+
value: function setRequest(request) {
62+
this.request = request;
63+
64+
return this;
65+
}
66+
}, {
67+
key: 'sorts',
68+
value: function sorts() {
69+
return this.$sort || [];
70+
}
71+
}, {
72+
key: 'matches',
73+
value: function matches() {
74+
return this.$match || [];
75+
}
76+
}, {
77+
key: 'searchables',
78+
value: function searchables() {
79+
return this.$search || [];
80+
}
81+
}, {
82+
key: 'related',
83+
value: function related() {
84+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
85+
86+
return this.$related || [];
87+
}
88+
}, {
89+
key: 'setSorts',
90+
value: function setSorts(sort) {
91+
this.$sort = sort;
92+
93+
return this;
94+
}
95+
}, {
96+
key: 'setMatches',
97+
value: function setMatches(match) {
98+
this.$match = match;
99+
100+
return this;
101+
}
102+
}, {
103+
key: 'setSearcheables',
104+
value: function setSearcheables(search) {
105+
this.$search = search;
106+
107+
return this;
108+
}
109+
}, {
110+
key: 'setActions',
111+
value: function setActions(actions) {
112+
this.$actions = actions;
113+
114+
return this;
115+
}
116+
}, {
117+
key: 'setRelated',
118+
value: function setRelated(related) {
119+
this.$related = related;
120+
121+
return this;
122+
}
123+
}, {
124+
key: 'uri',
125+
value: function uri() {
126+
var suffix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
127+
128+
return this.config.uri(suffix ? this.uriKey + '/' + suffix : this.uriKey);
129+
}
130+
}, {
131+
key: 'get',
132+
value: function get() {
133+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
134+
135+
return Restify.request().get(this.uri(), {
136+
params: query
137+
});
138+
}
139+
}, {
140+
key: 'show',
141+
value: function show(key) {
142+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
143+
144+
return Restify.request().get(this.uri(key), {
145+
params: query
146+
});
147+
}
148+
}, {
149+
key: 'store',
150+
value: function store(data) {
151+
return Restify.request().post(this.uri(), data);
152+
}
153+
}, {
154+
key: 'update',
155+
value: function update(key, data) {
156+
return Restify.request().post(this.uri(key), data);
157+
}
158+
}, {
159+
key: 'delete',
160+
value: function _delete(key) {
161+
return Restify.request().delete(this.uri(key));
162+
}
163+
}, {
164+
key: 'itemAction',
165+
value: function itemAction(id, key, data) {
166+
return Restify.request().post(this.uri(id + '/actions?action=' + key), data);
167+
}
168+
}, {
169+
key: 'action',
170+
value: function action(key, data) {
171+
var action = this.getAction(key);
172+
173+
if (!action) {
174+
throw new Error('Action ' + key + ' is not defined.');
175+
}
176+
177+
return Restify.request().post(this.uri('actions?action=' + key), data);
178+
}
179+
}, {
180+
key: 'getAction',
181+
value: function getAction(key) {
182+
if (key) {
183+
return (0, _helpers.collect)(this.$actions).firstWhere('uriKey', key);
184+
}
185+
186+
return this.$actions;
187+
}
188+
}], [{
189+
key: 'make',
190+
value: function make(item) {
191+
return new this(item);
192+
}
193+
}]);
194+
195+
return Repository;
196+
}();
197+
198+
exports.default = Repository;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var _Repository2 = require('./Repository');
4+
5+
var _Repository3 = _interopRequireDefault(_Repository2);
6+
7+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8+
9+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10+
11+
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; }
12+
13+
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; }
14+
15+
var ResourceRepository = function (_Repository) {
16+
_inherits(ResourceRepository, _Repository);
17+
18+
function ResourceRepository() {
19+
_classCallCheck(this, ResourceRepository);
20+
21+
return _possibleConstructorReturn(this, (ResourceRepository.__proto__ || Object.getPrototypeOf(ResourceRepository)).apply(this, arguments));
22+
}
23+
24+
return ResourceRepository;
25+
}(_Repository3.default);

0 commit comments

Comments
 (0)