@zthun/webigail-rest 4.0.2 → 4.0.4
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/dist/index.cjs +431 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +428 -99
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/service/restful-service.spec.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const webigailHttp = require('@zthun/webigail-http');
|
|
6
|
+
const webigailUrl = require('@zthun/webigail-url');
|
|
7
|
+
const helpfulQuery = require('@zthun/helpful-query');
|
|
8
|
+
|
|
9
|
+
function _class_call_check$1(instance, Constructor) {
|
|
10
|
+
if (!(instance instanceof Constructor)) {
|
|
11
|
+
throw new TypeError("Cannot call a class as a function");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function _defineProperties$1(target, props) {
|
|
15
|
+
for(var i = 0; i < props.length; i++){
|
|
16
|
+
var descriptor = props[i];
|
|
17
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
18
|
+
descriptor.configurable = true;
|
|
19
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
20
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
24
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
25
|
+
return Constructor;
|
|
26
|
+
}
|
|
27
|
+
function _define_property$1(obj, key, value) {
|
|
28
|
+
if (key in obj) {
|
|
29
|
+
Object.defineProperty(obj, key, {
|
|
30
|
+
value: value,
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
obj[key] = value;
|
|
37
|
+
}
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a decorator that can build a url for a restful endpoint
|
|
42
|
+
* given an existing base url.
|
|
43
|
+
*/ var ZRestfulUrlBuilder = /*#__PURE__*/ function() {
|
|
44
|
+
function ZRestfulUrlBuilder(baseUrl) {
|
|
45
|
+
_class_call_check$1(this, ZRestfulUrlBuilder);
|
|
46
|
+
_define_property$1(this, "_url", void 0);
|
|
47
|
+
this._url = new webigailUrl.ZUrlBuilder().parse(baseUrl);
|
|
48
|
+
}
|
|
49
|
+
_create_class$1(ZRestfulUrlBuilder, [
|
|
50
|
+
{
|
|
51
|
+
key: "from",
|
|
52
|
+
value: /**
|
|
14
53
|
* Adds the request parameters to the url.
|
|
15
54
|
*
|
|
16
55
|
* This will add the page, size, search, filter, and sort parameters to the url if they are defined.
|
|
@@ -19,54 +58,215 @@ class ZRestfulUrlBuilder {
|
|
|
19
58
|
* The request to add to the url.
|
|
20
59
|
* @returns
|
|
21
60
|
* This object.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
61
|
+
*/ function from(request) {
|
|
62
|
+
this._url = this._url.page(request.page).size(request.size).search(request.search).filter(new helpfulQuery.ZFilterSerialize().serialize(request.filter)).sort(new helpfulQuery.ZSortSerialize().serialize(request.sort));
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: "count",
|
|
68
|
+
value: /**
|
|
28
69
|
* Updates the url to optimize to retrieve a count.
|
|
29
70
|
*
|
|
30
71
|
* This will add the size and page parameters to the url and remove the sort parameter.
|
|
31
72
|
*
|
|
32
73
|
* @returns
|
|
33
74
|
* This object.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
75
|
+
*/ function count() {
|
|
76
|
+
this._url = this._url.size(1).page(1).sort(null);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: "build",
|
|
82
|
+
value: /**
|
|
40
83
|
* Returns the built url.
|
|
41
84
|
*
|
|
42
85
|
* @returns
|
|
43
86
|
* The built url.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
87
|
+
*/ function build() {
|
|
88
|
+
return this._url.build();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
]);
|
|
92
|
+
return ZRestfulUrlBuilder;
|
|
93
|
+
}();
|
|
94
|
+
|
|
95
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
96
|
+
try {
|
|
97
|
+
var info = gen[key](arg);
|
|
98
|
+
var value = info.value;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
reject(error);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (info.done) {
|
|
104
|
+
resolve(value);
|
|
105
|
+
} else {
|
|
106
|
+
Promise.resolve(value).then(_next, _throw);
|
|
107
|
+
}
|
|
48
108
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
109
|
+
function _async_to_generator(fn) {
|
|
110
|
+
return function() {
|
|
111
|
+
var self = this, args = arguments;
|
|
112
|
+
return new Promise(function(resolve, reject) {
|
|
113
|
+
var gen = fn.apply(self, args);
|
|
114
|
+
function _next(value) {
|
|
115
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
116
|
+
}
|
|
117
|
+
function _throw(err) {
|
|
118
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
119
|
+
}
|
|
120
|
+
_next(undefined);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function _class_call_check(instance, Constructor) {
|
|
125
|
+
if (!(instance instanceof Constructor)) {
|
|
126
|
+
throw new TypeError("Cannot call a class as a function");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function _defineProperties(target, props) {
|
|
130
|
+
for(var i = 0; i < props.length; i++){
|
|
131
|
+
var descriptor = props[i];
|
|
132
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
133
|
+
descriptor.configurable = true;
|
|
134
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
135
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
139
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
140
|
+
return Constructor;
|
|
141
|
+
}
|
|
142
|
+
function _define_property(obj, key, value) {
|
|
143
|
+
if (key in obj) {
|
|
144
|
+
Object.defineProperty(obj, key, {
|
|
145
|
+
value: value,
|
|
146
|
+
enumerable: true,
|
|
147
|
+
configurable: true,
|
|
148
|
+
writable: true
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
obj[key] = value;
|
|
152
|
+
}
|
|
153
|
+
return obj;
|
|
154
|
+
}
|
|
155
|
+
function _ts_generator(thisArg, body) {
|
|
156
|
+
var f, y, t, _ = {
|
|
157
|
+
label: 0,
|
|
158
|
+
sent: function() {
|
|
159
|
+
if (t[0] & 1) throw t[1];
|
|
160
|
+
return t[1];
|
|
161
|
+
},
|
|
162
|
+
trys: [],
|
|
163
|
+
ops: []
|
|
164
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
165
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
166
|
+
return this;
|
|
167
|
+
}), g;
|
|
168
|
+
function verb(n) {
|
|
169
|
+
return function(v) {
|
|
170
|
+
return step([
|
|
171
|
+
n,
|
|
172
|
+
v
|
|
173
|
+
]);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function step(op) {
|
|
177
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
178
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
179
|
+
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;
|
|
180
|
+
if (y = 0, t) op = [
|
|
181
|
+
op[0] & 2,
|
|
182
|
+
t.value
|
|
183
|
+
];
|
|
184
|
+
switch(op[0]){
|
|
185
|
+
case 0:
|
|
186
|
+
case 1:
|
|
187
|
+
t = op;
|
|
188
|
+
break;
|
|
189
|
+
case 4:
|
|
190
|
+
_.label++;
|
|
191
|
+
return {
|
|
192
|
+
value: op[1],
|
|
193
|
+
done: false
|
|
194
|
+
};
|
|
195
|
+
case 5:
|
|
196
|
+
_.label++;
|
|
197
|
+
y = op[1];
|
|
198
|
+
op = [
|
|
199
|
+
0
|
|
200
|
+
];
|
|
201
|
+
continue;
|
|
202
|
+
case 7:
|
|
203
|
+
op = _.ops.pop();
|
|
204
|
+
_.trys.pop();
|
|
205
|
+
continue;
|
|
206
|
+
default:
|
|
207
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
208
|
+
_ = 0;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
212
|
+
_.label = op[1];
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
216
|
+
_.label = t[1];
|
|
217
|
+
t = op;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
if (t && _.label < t[2]) {
|
|
221
|
+
_.label = t[2];
|
|
222
|
+
_.ops.push(op);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
if (t[2]) _.ops.pop();
|
|
226
|
+
_.trys.pop();
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
op = body.call(thisArg, _);
|
|
230
|
+
} catch (e) {
|
|
231
|
+
op = [
|
|
232
|
+
6,
|
|
233
|
+
e
|
|
234
|
+
];
|
|
235
|
+
y = 0;
|
|
236
|
+
} finally{
|
|
237
|
+
f = t = 0;
|
|
238
|
+
}
|
|
239
|
+
if (op[0] & 5) throw op[1];
|
|
240
|
+
return {
|
|
241
|
+
value: op[0] ? op[1] : void 0,
|
|
242
|
+
done: true
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A generic implementation of a restful service that assumes all verbs are implemented.
|
|
248
|
+
*
|
|
249
|
+
* This can be used to invoke a service that is only partially implemented. If your service,
|
|
250
|
+
* for example, is read only, then create, upsert, update, and delete should all return
|
|
251
|
+
* not found or forbidden errors.
|
|
252
|
+
*
|
|
253
|
+
* @param T -
|
|
254
|
+
* The type of resource being retrieved or mutated.
|
|
255
|
+
*/ var ZRestfulService = /*#__PURE__*/ function() {
|
|
256
|
+
function ZRestfulService(_http, _endpointUrl) {
|
|
257
|
+
var _request = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : new webigailHttp.ZHttpRequestBuilder().build();
|
|
258
|
+
_class_call_check(this, ZRestfulService);
|
|
259
|
+
_define_property(this, "_http", void 0);
|
|
260
|
+
_define_property(this, "_endpointUrl", void 0);
|
|
261
|
+
_define_property(this, "_request", void 0);
|
|
262
|
+
this._http = _http;
|
|
263
|
+
this._endpointUrl = _endpointUrl;
|
|
264
|
+
this._request = _request;
|
|
265
|
+
}
|
|
266
|
+
_create_class(ZRestfulService, [
|
|
267
|
+
{
|
|
268
|
+
key: "endpoint",
|
|
269
|
+
value: /**
|
|
70
270
|
* Gets the final endpoint for a resource.
|
|
71
271
|
*
|
|
72
272
|
* @param identification -
|
|
@@ -75,53 +275,187 @@ class ZRestfulService {
|
|
|
75
275
|
*
|
|
76
276
|
* @returns
|
|
77
277
|
* A url builder that points to the target resource endpoint.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
278
|
+
*/ function endpoint(identification) {
|
|
279
|
+
var url = new webigailUrl.ZUrlBuilder().parse(this._endpointUrl);
|
|
280
|
+
return identification ? url.append("".concat(identification)) : url;
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
key: "count",
|
|
285
|
+
value: function count(req) {
|
|
286
|
+
return _async_to_generator(function() {
|
|
287
|
+
var r, _ref, page;
|
|
288
|
+
return _ts_generator(this, function(_state) {
|
|
289
|
+
switch(_state.label){
|
|
290
|
+
case 0:
|
|
291
|
+
r = new webigailHttp.ZHttpRequestBuilder().copy(this._request).get().url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).count().build()).build();
|
|
292
|
+
return [
|
|
293
|
+
4,
|
|
294
|
+
this._http.request(r)
|
|
295
|
+
];
|
|
296
|
+
case 1:
|
|
297
|
+
_ref = _state.sent(), page = _ref.data;
|
|
298
|
+
return [
|
|
299
|
+
2,
|
|
300
|
+
page.count
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}).call(this);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
key: "retrieve",
|
|
309
|
+
value: function retrieve(req) {
|
|
310
|
+
return _async_to_generator(function() {
|
|
311
|
+
var r, _ref, page, _page_data;
|
|
312
|
+
return _ts_generator(this, function(_state) {
|
|
313
|
+
switch(_state.label){
|
|
314
|
+
case 0:
|
|
315
|
+
r = new webigailHttp.ZHttpRequestBuilder().copy(this._request).get().url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).build()).build();
|
|
316
|
+
return [
|
|
317
|
+
4,
|
|
318
|
+
this._http.request(r)
|
|
319
|
+
];
|
|
320
|
+
case 1:
|
|
321
|
+
_ref = _state.sent(), page = _ref.data;
|
|
322
|
+
return [
|
|
323
|
+
2,
|
|
324
|
+
(_page_data = page.data) !== null && _page_data !== void 0 ? _page_data : page.result
|
|
325
|
+
];
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}).call(this);
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
key: "get",
|
|
333
|
+
value: function get(identification) {
|
|
334
|
+
return _async_to_generator(function() {
|
|
335
|
+
var url, r, data;
|
|
336
|
+
return _ts_generator(this, function(_state) {
|
|
337
|
+
switch(_state.label){
|
|
338
|
+
case 0:
|
|
339
|
+
url = this.endpoint(identification).build();
|
|
340
|
+
r = new webigailHttp.ZHttpRequestBuilder().copy(this._request).get().url(url).build();
|
|
341
|
+
return [
|
|
342
|
+
4,
|
|
343
|
+
this._http.request(r)
|
|
344
|
+
];
|
|
345
|
+
case 1:
|
|
346
|
+
data = _state.sent().data;
|
|
347
|
+
return [
|
|
348
|
+
2,
|
|
349
|
+
data
|
|
350
|
+
];
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}).call(this);
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
key: "create",
|
|
358
|
+
value: function create(body) {
|
|
359
|
+
return _async_to_generator(function() {
|
|
360
|
+
var url, r, data;
|
|
361
|
+
return _ts_generator(this, function(_state) {
|
|
362
|
+
switch(_state.label){
|
|
363
|
+
case 0:
|
|
364
|
+
url = this.endpoint().build();
|
|
365
|
+
r = new webigailHttp.ZHttpRequestBuilder().copy(this._request).post(body).url(url).build();
|
|
366
|
+
return [
|
|
367
|
+
4,
|
|
368
|
+
this._http.request(r)
|
|
369
|
+
];
|
|
370
|
+
case 1:
|
|
371
|
+
data = _state.sent().data;
|
|
372
|
+
return [
|
|
373
|
+
2,
|
|
374
|
+
data
|
|
375
|
+
];
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}).call(this);
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
key: "upsert",
|
|
383
|
+
value: function upsert(body) {
|
|
384
|
+
return _async_to_generator(function() {
|
|
385
|
+
var url, r, data;
|
|
386
|
+
return _ts_generator(this, function(_state) {
|
|
387
|
+
switch(_state.label){
|
|
388
|
+
case 0:
|
|
389
|
+
url = this.endpoint().build();
|
|
390
|
+
r = new webigailHttp.ZHttpRequestBuilder().copy(this._request).put(body).url(url).build();
|
|
391
|
+
return [
|
|
392
|
+
4,
|
|
393
|
+
this._http.request(r)
|
|
394
|
+
];
|
|
395
|
+
case 1:
|
|
396
|
+
data = _state.sent().data;
|
|
397
|
+
return [
|
|
398
|
+
2,
|
|
399
|
+
data
|
|
400
|
+
];
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}).call(this);
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
key: "update",
|
|
408
|
+
value: function update(identification, fields) {
|
|
409
|
+
return _async_to_generator(function() {
|
|
410
|
+
var url, r, data;
|
|
411
|
+
return _ts_generator(this, function(_state) {
|
|
412
|
+
switch(_state.label){
|
|
413
|
+
case 0:
|
|
414
|
+
url = this.endpoint(identification).build();
|
|
415
|
+
r = new webigailHttp.ZHttpRequestBuilder().copy(this._request).patch(fields).url(url).build();
|
|
416
|
+
return [
|
|
417
|
+
4,
|
|
418
|
+
this._http.request(r)
|
|
419
|
+
];
|
|
420
|
+
case 1:
|
|
421
|
+
data = _state.sent().data;
|
|
422
|
+
return [
|
|
423
|
+
2,
|
|
424
|
+
data
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}).call(this);
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
key: "delete",
|
|
433
|
+
value: function _delete(identification) {
|
|
434
|
+
return _async_to_generator(function() {
|
|
435
|
+
var url, r;
|
|
436
|
+
return _ts_generator(this, function(_state) {
|
|
437
|
+
switch(_state.label){
|
|
438
|
+
case 0:
|
|
439
|
+
url = this.endpoint(identification).build();
|
|
440
|
+
r = new webigailHttp.ZHttpRequestBuilder().copy(this._request).delete().url(url).build();
|
|
441
|
+
return [
|
|
442
|
+
4,
|
|
443
|
+
this._http.request(r)
|
|
444
|
+
];
|
|
445
|
+
case 1:
|
|
446
|
+
_state.sent();
|
|
447
|
+
return [
|
|
448
|
+
2
|
|
449
|
+
];
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}).call(this);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
]);
|
|
456
|
+
return ZRestfulService;
|
|
457
|
+
}();
|
|
458
|
+
|
|
125
459
|
exports.ZRestfulService = ZRestfulService;
|
|
126
460
|
exports.ZRestfulUrlBuilder = ZRestfulUrlBuilder;
|
|
127
461
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/url/restful-url.mts","../src/service/restful-service.mts"],"sourcesContent":["import type { IZDataRequest } from \"@zthun/helpful-query\";\nimport { ZFilterSerialize, ZSortSerialize } from \"@zthun/helpful-query\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\n\n/**\n * Represents a decorator that can build a url for a restful endpoint\n * given an existing base url.\n */\nexport class ZRestfulUrlBuilder {\n private _url: ZUrlBuilder;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor(baseUrl: string) {\n this._url = new ZUrlBuilder().parse(baseUrl);\n }\n\n /**\n * Adds the request parameters to the url.\n *\n * This will add the page, size, search, filter, and sort parameters to the url if they are defined.\n *\n * @param request -\n * The request to add to the url.\n * @returns\n * This object.\n */\n public from(request: IZDataRequest): this {\n this._url = this._url\n .page(request.page)\n .size(request.size)\n .search(request.search)\n .filter(new ZFilterSerialize().serialize(request.filter))\n .sort(new ZSortSerialize().serialize(request.sort));\n return this;\n }\n\n /**\n * Updates the url to optimize to retrieve a count.\n *\n * This will add the size and page parameters to the url and remove the sort parameter.\n *\n * @returns\n * This object.\n */\n public count(): this {\n this._url = this._url.size(1).page(1).sort(null);\n return this;\n }\n\n /**\n * Returns the built url.\n *\n * @returns\n * The built url.\n */\n public build(): string {\n return this._url.build();\n }\n}\n","import type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport type { IZHttpService } from \"@zthun/webigail-http\";\nimport { ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { ZRestfulUrlBuilder } from \"../url/restful-url.mjs\";\nimport type { IZRestfulCreate } from \"./restful-create.mjs\";\nimport type { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport type { IZRestfulGet } from \"./restful-get.mjs\";\nimport type { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport type { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(\n new ZRestfulUrlBuilder(this.endpoint().build())\n .from(req)\n .count()\n .build(),\n )\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).build())\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":["ZUrlBuilder","ZFilterSerialize","ZSortSerialize","ZHttpRequestBuilder"],"mappings":";;;;;AAQO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAMvB,YAAY,SAAiB;AAClC,SAAK,OAAO,IAAIA,YAAY,YAAA,EAAE,MAAM,OAAO;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAatC,KAAK,SAA8B;AACxC,SAAK,OAAO,KAAK,KACd,KAAK,QAAQ,IAAI,EACjB,KAAK,QAAQ,IAAI,EACjB,OAAO,QAAQ,MAAM,EACrB,OAAO,IAAIC,aAAiB,iBAAA,EAAE,UAAU,QAAQ,MAAM,CAAC,EAC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vC,WAAA;AAAA,EAAA;AAAA,EAGT,MAAa,OAAO,gBAAgD;AAClE,UAAM,MAAM,KAAK,SAAS,cAAc,EAAE,MAAM;AAChD,UAAM,IAAI,IAAIA,iCAA+B,EAC1C,KAAK,KAAK,QAAQ,EAClB,OAAO,EACP,IAAI,GAAG,EACP,MAAM;AACH,UAAA,KAAK,MAAM,QAAQ,CAAC;AAAA,EAAA;AAE9B;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/url/restful-url.mts","../src/service/restful-service.mts"],"sourcesContent":["import type { IZDataRequest } from \"@zthun/helpful-query\";\nimport { ZFilterSerialize, ZSortSerialize } from \"@zthun/helpful-query\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\n\n/**\n * Represents a decorator that can build a url for a restful endpoint\n * given an existing base url.\n */\nexport class ZRestfulUrlBuilder {\n private _url: ZUrlBuilder;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor(baseUrl: string) {\n this._url = new ZUrlBuilder().parse(baseUrl);\n }\n\n /**\n * Adds the request parameters to the url.\n *\n * This will add the page, size, search, filter, and sort parameters to the url if they are defined.\n *\n * @param request -\n * The request to add to the url.\n * @returns\n * This object.\n */\n public from(request: IZDataRequest): this {\n this._url = this._url\n .page(request.page)\n .size(request.size)\n .search(request.search)\n .filter(new ZFilterSerialize().serialize(request.filter))\n .sort(new ZSortSerialize().serialize(request.sort));\n return this;\n }\n\n /**\n * Updates the url to optimize to retrieve a count.\n *\n * This will add the size and page parameters to the url and remove the sort parameter.\n *\n * @returns\n * This object.\n */\n public count(): this {\n this._url = this._url.size(1).page(1).sort(null);\n return this;\n }\n\n /**\n * Returns the built url.\n *\n * @returns\n * The built url.\n */\n public build(): string {\n return this._url.build();\n }\n}\n","import type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport type { IZHttpService } from \"@zthun/webigail-http\";\nimport { ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { ZRestfulUrlBuilder } from \"../url/restful-url.mjs\";\nimport type { IZRestfulCreate } from \"./restful-create.mjs\";\nimport type { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport type { IZRestfulGet } from \"./restful-get.mjs\";\nimport type { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport type { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(\n new ZRestfulUrlBuilder(this.endpoint().build())\n .from(req)\n .count()\n .build(),\n )\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).build())\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":["ZRestfulUrlBuilder","baseUrl","_define_property","_url","ZUrlBuilder","parse","from","request","page","size","search","filter","ZFilterSerialize","serialize","sort","ZSortSerialize","count","build","ZRestfulService","_endpointUrl","_request","ZHttpRequestBuilder","_http","endpoint","identification","url","append","req","r","copy","get","data","retrieve","result","create","body","post","upsert","put","update","fields","patch","delete"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;IAIO,IAAMA,k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AA,IAAA,CAAA;;;;YAEaW,GAAAA,EAAAA,QAAAA;AAAb,YAAA,KAAA,EAAA,SAAaA,QAAOlB,cAA+B,EAAA;;wBAC3CC,GACAG,EAAAA,CAAAA;;;;AADAH,gCAAAA,GAAAA,GAAM,IAAI,CAACF,QAAQ,CAACC,gBAAgBP,KAAK,EAAA;AACzCW,gCAAAA,CAAAA,GAAI,IAAIP,gCAAAA,EAAAA,CACXQ,IAAI,CAAC,IAAI,CAACT,QAAQ,CAAA,CAClBsB,MAAM,EAAA,CACNjB,GAAG,CAACA,KACJR,KAAK,EAAA;AACR,gCAAA,OAAA;;AAAM,oCAAA,IAAI,CAACK,KAAK,CAACf,OAAO,CAACqB,CAAAA;;;AAAzB,gCAAA,MAAA,CAAA,IAAA,EAAA;;;;;;AACF,iBAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA;;;;AApHWV,IAAAA,OAAAA,eAAAA;AAqHZ,CAAA;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,51 @@
|
|
|
1
|
-
import { ZHttpRequestBuilder } from
|
|
2
|
-
import { ZUrlBuilder } from
|
|
3
|
-
import { ZFilterSerialize, ZSortSerialize } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { ZHttpRequestBuilder } from '@zthun/webigail-http';
|
|
2
|
+
import { ZUrlBuilder } from '@zthun/webigail-url';
|
|
3
|
+
import { ZFilterSerialize, ZSortSerialize } from '@zthun/helpful-query';
|
|
4
|
+
|
|
5
|
+
function _class_call_check$1(instance, Constructor) {
|
|
6
|
+
if (!(instance instanceof Constructor)) {
|
|
7
|
+
throw new TypeError("Cannot call a class as a function");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function _defineProperties$1(target, props) {
|
|
11
|
+
for(var i = 0; i < props.length; i++){
|
|
12
|
+
var descriptor = props[i];
|
|
13
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
14
|
+
descriptor.configurable = true;
|
|
15
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
16
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
20
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
21
|
+
return Constructor;
|
|
22
|
+
}
|
|
23
|
+
function _define_property$1(obj, key, value) {
|
|
24
|
+
if (key in obj) {
|
|
25
|
+
Object.defineProperty(obj, key, {
|
|
26
|
+
value: value,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
obj[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Represents a decorator that can build a url for a restful endpoint
|
|
38
|
+
* given an existing base url.
|
|
39
|
+
*/ var ZRestfulUrlBuilder = /*#__PURE__*/ function() {
|
|
40
|
+
function ZRestfulUrlBuilder(baseUrl) {
|
|
41
|
+
_class_call_check$1(this, ZRestfulUrlBuilder);
|
|
42
|
+
_define_property$1(this, "_url", void 0);
|
|
43
|
+
this._url = new ZUrlBuilder().parse(baseUrl);
|
|
44
|
+
}
|
|
45
|
+
_create_class$1(ZRestfulUrlBuilder, [
|
|
46
|
+
{
|
|
47
|
+
key: "from",
|
|
48
|
+
value: /**
|
|
12
49
|
* Adds the request parameters to the url.
|
|
13
50
|
*
|
|
14
51
|
* This will add the page, size, search, filter, and sort parameters to the url if they are defined.
|
|
@@ -17,54 +54,215 @@ class ZRestfulUrlBuilder {
|
|
|
17
54
|
* The request to add to the url.
|
|
18
55
|
* @returns
|
|
19
56
|
* This object.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
57
|
+
*/ function from(request) {
|
|
58
|
+
this._url = this._url.page(request.page).size(request.size).search(request.search).filter(new ZFilterSerialize().serialize(request.filter)).sort(new ZSortSerialize().serialize(request.sort));
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "count",
|
|
64
|
+
value: /**
|
|
26
65
|
* Updates the url to optimize to retrieve a count.
|
|
27
66
|
*
|
|
28
67
|
* This will add the size and page parameters to the url and remove the sort parameter.
|
|
29
68
|
*
|
|
30
69
|
* @returns
|
|
31
70
|
* This object.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
71
|
+
*/ function count() {
|
|
72
|
+
this._url = this._url.size(1).page(1).sort(null);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "build",
|
|
78
|
+
value: /**
|
|
38
79
|
* Returns the built url.
|
|
39
80
|
*
|
|
40
81
|
* @returns
|
|
41
82
|
* The built url.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
*/ function build() {
|
|
84
|
+
return this._url.build();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
]);
|
|
88
|
+
return ZRestfulUrlBuilder;
|
|
89
|
+
}();
|
|
90
|
+
|
|
91
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
92
|
+
try {
|
|
93
|
+
var info = gen[key](arg);
|
|
94
|
+
var value = info.value;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
reject(error);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (info.done) {
|
|
100
|
+
resolve(value);
|
|
101
|
+
} else {
|
|
102
|
+
Promise.resolve(value).then(_next, _throw);
|
|
103
|
+
}
|
|
46
104
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
105
|
+
function _async_to_generator(fn) {
|
|
106
|
+
return function() {
|
|
107
|
+
var self = this, args = arguments;
|
|
108
|
+
return new Promise(function(resolve, reject) {
|
|
109
|
+
var gen = fn.apply(self, args);
|
|
110
|
+
function _next(value) {
|
|
111
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
112
|
+
}
|
|
113
|
+
function _throw(err) {
|
|
114
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
115
|
+
}
|
|
116
|
+
_next(undefined);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function _class_call_check(instance, Constructor) {
|
|
121
|
+
if (!(instance instanceof Constructor)) {
|
|
122
|
+
throw new TypeError("Cannot call a class as a function");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function _defineProperties(target, props) {
|
|
126
|
+
for(var i = 0; i < props.length; i++){
|
|
127
|
+
var descriptor = props[i];
|
|
128
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
129
|
+
descriptor.configurable = true;
|
|
130
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
131
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
135
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
136
|
+
return Constructor;
|
|
137
|
+
}
|
|
138
|
+
function _define_property(obj, key, value) {
|
|
139
|
+
if (key in obj) {
|
|
140
|
+
Object.defineProperty(obj, key, {
|
|
141
|
+
value: value,
|
|
142
|
+
enumerable: true,
|
|
143
|
+
configurable: true,
|
|
144
|
+
writable: true
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
obj[key] = value;
|
|
148
|
+
}
|
|
149
|
+
return obj;
|
|
150
|
+
}
|
|
151
|
+
function _ts_generator(thisArg, body) {
|
|
152
|
+
var f, y, t, _ = {
|
|
153
|
+
label: 0,
|
|
154
|
+
sent: function() {
|
|
155
|
+
if (t[0] & 1) throw t[1];
|
|
156
|
+
return t[1];
|
|
157
|
+
},
|
|
158
|
+
trys: [],
|
|
159
|
+
ops: []
|
|
160
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
161
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
162
|
+
return this;
|
|
163
|
+
}), g;
|
|
164
|
+
function verb(n) {
|
|
165
|
+
return function(v) {
|
|
166
|
+
return step([
|
|
167
|
+
n,
|
|
168
|
+
v
|
|
169
|
+
]);
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function step(op) {
|
|
173
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
174
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
175
|
+
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;
|
|
176
|
+
if (y = 0, t) op = [
|
|
177
|
+
op[0] & 2,
|
|
178
|
+
t.value
|
|
179
|
+
];
|
|
180
|
+
switch(op[0]){
|
|
181
|
+
case 0:
|
|
182
|
+
case 1:
|
|
183
|
+
t = op;
|
|
184
|
+
break;
|
|
185
|
+
case 4:
|
|
186
|
+
_.label++;
|
|
187
|
+
return {
|
|
188
|
+
value: op[1],
|
|
189
|
+
done: false
|
|
190
|
+
};
|
|
191
|
+
case 5:
|
|
192
|
+
_.label++;
|
|
193
|
+
y = op[1];
|
|
194
|
+
op = [
|
|
195
|
+
0
|
|
196
|
+
];
|
|
197
|
+
continue;
|
|
198
|
+
case 7:
|
|
199
|
+
op = _.ops.pop();
|
|
200
|
+
_.trys.pop();
|
|
201
|
+
continue;
|
|
202
|
+
default:
|
|
203
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
204
|
+
_ = 0;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
208
|
+
_.label = op[1];
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
212
|
+
_.label = t[1];
|
|
213
|
+
t = op;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
if (t && _.label < t[2]) {
|
|
217
|
+
_.label = t[2];
|
|
218
|
+
_.ops.push(op);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
if (t[2]) _.ops.pop();
|
|
222
|
+
_.trys.pop();
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
op = body.call(thisArg, _);
|
|
226
|
+
} catch (e) {
|
|
227
|
+
op = [
|
|
228
|
+
6,
|
|
229
|
+
e
|
|
230
|
+
];
|
|
231
|
+
y = 0;
|
|
232
|
+
} finally{
|
|
233
|
+
f = t = 0;
|
|
234
|
+
}
|
|
235
|
+
if (op[0] & 5) throw op[1];
|
|
236
|
+
return {
|
|
237
|
+
value: op[0] ? op[1] : void 0,
|
|
238
|
+
done: true
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* A generic implementation of a restful service that assumes all verbs are implemented.
|
|
244
|
+
*
|
|
245
|
+
* This can be used to invoke a service that is only partially implemented. If your service,
|
|
246
|
+
* for example, is read only, then create, upsert, update, and delete should all return
|
|
247
|
+
* not found or forbidden errors.
|
|
248
|
+
*
|
|
249
|
+
* @param T -
|
|
250
|
+
* The type of resource being retrieved or mutated.
|
|
251
|
+
*/ var ZRestfulService = /*#__PURE__*/ function() {
|
|
252
|
+
function ZRestfulService(_http, _endpointUrl) {
|
|
253
|
+
var _request = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : new ZHttpRequestBuilder().build();
|
|
254
|
+
_class_call_check(this, ZRestfulService);
|
|
255
|
+
_define_property(this, "_http", void 0);
|
|
256
|
+
_define_property(this, "_endpointUrl", void 0);
|
|
257
|
+
_define_property(this, "_request", void 0);
|
|
258
|
+
this._http = _http;
|
|
259
|
+
this._endpointUrl = _endpointUrl;
|
|
260
|
+
this._request = _request;
|
|
261
|
+
}
|
|
262
|
+
_create_class(ZRestfulService, [
|
|
263
|
+
{
|
|
264
|
+
key: "endpoint",
|
|
265
|
+
value: /**
|
|
68
266
|
* Gets the final endpoint for a resource.
|
|
69
267
|
*
|
|
70
268
|
* @param identification -
|
|
@@ -73,55 +271,186 @@ class ZRestfulService {
|
|
|
73
271
|
*
|
|
74
272
|
* @returns
|
|
75
273
|
* A url builder that points to the target resource endpoint.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
};
|
|
274
|
+
*/ function endpoint(identification) {
|
|
275
|
+
var url = new ZUrlBuilder().parse(this._endpointUrl);
|
|
276
|
+
return identification ? url.append("".concat(identification)) : url;
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
key: "count",
|
|
281
|
+
value: function count(req) {
|
|
282
|
+
return _async_to_generator(function() {
|
|
283
|
+
var r, _ref, page;
|
|
284
|
+
return _ts_generator(this, function(_state) {
|
|
285
|
+
switch(_state.label){
|
|
286
|
+
case 0:
|
|
287
|
+
r = new ZHttpRequestBuilder().copy(this._request).get().url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).count().build()).build();
|
|
288
|
+
return [
|
|
289
|
+
4,
|
|
290
|
+
this._http.request(r)
|
|
291
|
+
];
|
|
292
|
+
case 1:
|
|
293
|
+
_ref = _state.sent(), page = _ref.data;
|
|
294
|
+
return [
|
|
295
|
+
2,
|
|
296
|
+
page.count
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}).call(this);
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
key: "retrieve",
|
|
305
|
+
value: function retrieve(req) {
|
|
306
|
+
return _async_to_generator(function() {
|
|
307
|
+
var r, _ref, page, _page_data;
|
|
308
|
+
return _ts_generator(this, function(_state) {
|
|
309
|
+
switch(_state.label){
|
|
310
|
+
case 0:
|
|
311
|
+
r = new ZHttpRequestBuilder().copy(this._request).get().url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).build()).build();
|
|
312
|
+
return [
|
|
313
|
+
4,
|
|
314
|
+
this._http.request(r)
|
|
315
|
+
];
|
|
316
|
+
case 1:
|
|
317
|
+
_ref = _state.sent(), page = _ref.data;
|
|
318
|
+
return [
|
|
319
|
+
2,
|
|
320
|
+
(_page_data = page.data) !== null && _page_data !== void 0 ? _page_data : page.result
|
|
321
|
+
];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}).call(this);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
key: "get",
|
|
329
|
+
value: function get(identification) {
|
|
330
|
+
return _async_to_generator(function() {
|
|
331
|
+
var url, r, data;
|
|
332
|
+
return _ts_generator(this, function(_state) {
|
|
333
|
+
switch(_state.label){
|
|
334
|
+
case 0:
|
|
335
|
+
url = this.endpoint(identification).build();
|
|
336
|
+
r = new ZHttpRequestBuilder().copy(this._request).get().url(url).build();
|
|
337
|
+
return [
|
|
338
|
+
4,
|
|
339
|
+
this._http.request(r)
|
|
340
|
+
];
|
|
341
|
+
case 1:
|
|
342
|
+
data = _state.sent().data;
|
|
343
|
+
return [
|
|
344
|
+
2,
|
|
345
|
+
data
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}).call(this);
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
key: "create",
|
|
354
|
+
value: function create(body) {
|
|
355
|
+
return _async_to_generator(function() {
|
|
356
|
+
var url, r, data;
|
|
357
|
+
return _ts_generator(this, function(_state) {
|
|
358
|
+
switch(_state.label){
|
|
359
|
+
case 0:
|
|
360
|
+
url = this.endpoint().build();
|
|
361
|
+
r = new ZHttpRequestBuilder().copy(this._request).post(body).url(url).build();
|
|
362
|
+
return [
|
|
363
|
+
4,
|
|
364
|
+
this._http.request(r)
|
|
365
|
+
];
|
|
366
|
+
case 1:
|
|
367
|
+
data = _state.sent().data;
|
|
368
|
+
return [
|
|
369
|
+
2,
|
|
370
|
+
data
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}).call(this);
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
key: "upsert",
|
|
379
|
+
value: function upsert(body) {
|
|
380
|
+
return _async_to_generator(function() {
|
|
381
|
+
var url, r, data;
|
|
382
|
+
return _ts_generator(this, function(_state) {
|
|
383
|
+
switch(_state.label){
|
|
384
|
+
case 0:
|
|
385
|
+
url = this.endpoint().build();
|
|
386
|
+
r = new ZHttpRequestBuilder().copy(this._request).put(body).url(url).build();
|
|
387
|
+
return [
|
|
388
|
+
4,
|
|
389
|
+
this._http.request(r)
|
|
390
|
+
];
|
|
391
|
+
case 1:
|
|
392
|
+
data = _state.sent().data;
|
|
393
|
+
return [
|
|
394
|
+
2,
|
|
395
|
+
data
|
|
396
|
+
];
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}).call(this);
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
key: "update",
|
|
404
|
+
value: function update(identification, fields) {
|
|
405
|
+
return _async_to_generator(function() {
|
|
406
|
+
var url, r, data;
|
|
407
|
+
return _ts_generator(this, function(_state) {
|
|
408
|
+
switch(_state.label){
|
|
409
|
+
case 0:
|
|
410
|
+
url = this.endpoint(identification).build();
|
|
411
|
+
r = new ZHttpRequestBuilder().copy(this._request).patch(fields).url(url).build();
|
|
412
|
+
return [
|
|
413
|
+
4,
|
|
414
|
+
this._http.request(r)
|
|
415
|
+
];
|
|
416
|
+
case 1:
|
|
417
|
+
data = _state.sent().data;
|
|
418
|
+
return [
|
|
419
|
+
2,
|
|
420
|
+
data
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}).call(this);
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
key: "delete",
|
|
429
|
+
value: function _delete(identification) {
|
|
430
|
+
return _async_to_generator(function() {
|
|
431
|
+
var url, r;
|
|
432
|
+
return _ts_generator(this, function(_state) {
|
|
433
|
+
switch(_state.label){
|
|
434
|
+
case 0:
|
|
435
|
+
url = this.endpoint(identification).build();
|
|
436
|
+
r = new ZHttpRequestBuilder().copy(this._request).delete().url(url).build();
|
|
437
|
+
return [
|
|
438
|
+
4,
|
|
439
|
+
this._http.request(r)
|
|
440
|
+
];
|
|
441
|
+
case 1:
|
|
442
|
+
_state.sent();
|
|
443
|
+
return [
|
|
444
|
+
2
|
|
445
|
+
];
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}).call(this);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
]);
|
|
452
|
+
return ZRestfulService;
|
|
453
|
+
}();
|
|
454
|
+
|
|
455
|
+
export { ZRestfulService, ZRestfulUrlBuilder };
|
|
127
456
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/url/restful-url.mts","../src/service/restful-service.mts"],"sourcesContent":["import type { IZDataRequest } from \"@zthun/helpful-query\";\nimport { ZFilterSerialize, ZSortSerialize } from \"@zthun/helpful-query\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\n\n/**\n * Represents a decorator that can build a url for a restful endpoint\n * given an existing base url.\n */\nexport class ZRestfulUrlBuilder {\n private _url: ZUrlBuilder;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor(baseUrl: string) {\n this._url = new ZUrlBuilder().parse(baseUrl);\n }\n\n /**\n * Adds the request parameters to the url.\n *\n * This will add the page, size, search, filter, and sort parameters to the url if they are defined.\n *\n * @param request -\n * The request to add to the url.\n * @returns\n * This object.\n */\n public from(request: IZDataRequest): this {\n this._url = this._url\n .page(request.page)\n .size(request.size)\n .search(request.search)\n .filter(new ZFilterSerialize().serialize(request.filter))\n .sort(new ZSortSerialize().serialize(request.sort));\n return this;\n }\n\n /**\n * Updates the url to optimize to retrieve a count.\n *\n * This will add the size and page parameters to the url and remove the sort parameter.\n *\n * @returns\n * This object.\n */\n public count(): this {\n this._url = this._url.size(1).page(1).sort(null);\n return this;\n }\n\n /**\n * Returns the built url.\n *\n * @returns\n * The built url.\n */\n public build(): string {\n return this._url.build();\n }\n}\n","import type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport type { IZHttpService } from \"@zthun/webigail-http\";\nimport { ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { ZRestfulUrlBuilder } from \"../url/restful-url.mjs\";\nimport type { IZRestfulCreate } from \"./restful-create.mjs\";\nimport type { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport type { IZRestfulGet } from \"./restful-get.mjs\";\nimport type { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport type { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(\n new ZRestfulUrlBuilder(this.endpoint().build())\n .from(req)\n .count()\n .build(),\n )\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).build())\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":[],"mappings":";;;AAQO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAMvB,YAAY,SAAiB;AAClC,SAAK,OAAO,IAAI,YAAY,EAAE,MAAM,OAAO;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAatC,KAAK,SAA8B;AACxC,SAA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IAAI,GAAG,EACP,MAAM;AACT,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,MAAM,QAAW,CAAC;AACvC,WAAA;AAAA,EAAA;AAAA,EAGT,MAAa,OAAO,gBAAgD;AAClE,UAAM,MAAM,KAAK,SAAS,cAAc,EAAE,MAAM;AAChD,UAAM,IAAI,IAAI,oBAA+B,EAC1C,KAAK,KAAK,QAAQ,EAClB,OAAO,EACP,IAAI,GAAG,EACP,MAAM;AACH,UAAA,KAAK,MAAM,QAAQ,CAAC;AAAA,EAAA;AAE9B;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/url/restful-url.mts","../src/service/restful-service.mts"],"sourcesContent":["import type { IZDataRequest } from \"@zthun/helpful-query\";\nimport { ZFilterSerialize, ZSortSerialize } from \"@zthun/helpful-query\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\n\n/**\n * Represents a decorator that can build a url for a restful endpoint\n * given an existing base url.\n */\nexport class ZRestfulUrlBuilder {\n private _url: ZUrlBuilder;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor(baseUrl: string) {\n this._url = new ZUrlBuilder().parse(baseUrl);\n }\n\n /**\n * Adds the request parameters to the url.\n *\n * This will add the page, size, search, filter, and sort parameters to the url if they are defined.\n *\n * @param request -\n * The request to add to the url.\n * @returns\n * This object.\n */\n public from(request: IZDataRequest): this {\n this._url = this._url\n .page(request.page)\n .size(request.size)\n .search(request.search)\n .filter(new ZFilterSerialize().serialize(request.filter))\n .sort(new ZSortSerialize().serialize(request.sort));\n return this;\n }\n\n /**\n * Updates the url to optimize to retrieve a count.\n *\n * This will add the size and page parameters to the url and remove the sort parameter.\n *\n * @returns\n * This object.\n */\n public count(): this {\n this._url = this._url.size(1).page(1).sort(null);\n return this;\n }\n\n /**\n * Returns the built url.\n *\n * @returns\n * The built url.\n */\n public build(): string {\n return this._url.build();\n }\n}\n","import type { IZDataRequest, IZDataSource } from \"@zthun/helpful-query\";\nimport type { IZHttpService } from \"@zthun/webigail-http\";\nimport { ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { ZRestfulUrlBuilder } from \"../url/restful-url.mjs\";\nimport type { IZRestfulCreate } from \"./restful-create.mjs\";\nimport type { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport type { IZRestfulGet } from \"./restful-get.mjs\";\nimport type { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport type { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(\n new ZRestfulUrlBuilder(this.endpoint().build())\n .from(req)\n .count()\n .build(),\n )\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(new ZRestfulUrlBuilder(this.endpoint().build()).from(req).build())\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":["ZRestfulUrlBuilder","baseUrl","_define_property","_url","ZUrlBuilder","parse","from","request","page","size","search","filter","ZFilterSerialize","serialize","sort","ZSortSerialize","count","build","ZRestfulService","_endpointUrl","_request","ZHttpRequestBuilder","_http","endpoint","identification","url","append","req","r","copy","get","data","retrieve","result","create","body","post","upsert","put","update","fields","patch","delete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AACR,gCAAA,OAAA;;AAAOA,oCAAAA;;;;AACT,iBAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA;;;;YAEaW,GAAAA,EAAAA,QAAAA;AAAb,YAAA,KAAA,EAAA,SAAaA,QAAOlB,cAA+B,EAAA;;wBAC3CC,GACAG,EAAAA,CAAAA;;;;AADAH,gCAAAA,GAAAA,GAAM,IAAI,CAACF,QAAQ,CAACC,gBAAgBP,KAAK,EAAA;AACzCW,gCAAAA,CAAAA,GAAI,IAAIP,mBAAAA,EAAAA,CACXQ,IAAI,CAAC,IAAI,CAACT,QAAQ,CAAA,CAClBsB,MAAM,EAAA,CACNjB,GAAG,CAACA,KACJR,KAAK,EAAA;AACR,gCAAA,OAAA;;AAAM,oCAAA,IAAI,CAACK,KAAK,CAACf,OAAO,CAACqB,CAAAA;;;AAAzB,gCAAA,MAAA,CAAA,IAAA,EAAA;;;;;;AACF,iBAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA;;;;AApHWV,IAAAA,OAAAA,eAAAA;AAqHZ,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zthun/webigail-rest",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Helpful services for querying rest services based on specific standards.",
|
|
5
5
|
"author": "Anthony Bonta",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@zthun/helpful-fn": "^9.
|
|
29
|
-
"@zthun/helpful-query": "^9.
|
|
30
|
-
"@zthun/webigail-http": "^4.0.
|
|
31
|
-
"@zthun/webigail-url": "^4.0.
|
|
28
|
+
"@zthun/helpful-fn": "^9.4.0",
|
|
29
|
+
"@zthun/helpful-query": "^9.4.0",
|
|
30
|
+
"@zthun/webigail-http": "^4.0.4",
|
|
31
|
+
"@zthun/webigail-url": "^4.0.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@zthun/janitor-build-config": "^19.2.
|
|
34
|
+
"@zthun/janitor-build-config": "^19.2.4",
|
|
35
35
|
"vite": "^6.3.5",
|
|
36
36
|
"vitest": "^3.2.4"
|
|
37
37
|
},
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"sideEffects": false,
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2d68c2a2b7856b5331992a7c2ad441159dc6faeb"
|
|
43
43
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|