ng2-rest 11.0.42 → 13.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/README.md +1 -1
- package/app.js +2 -47
- package/app.js.map +1 -1
- package/browser/README.md +24 -0
- package/browser/esm2020/lib/cookie.mjs +27 -0
- package/browser/esm2020/lib/helpers.mjs +22 -0
- package/browser/esm2020/lib/index.mjs +10 -0
- package/browser/esm2020/lib/mapping.mjs +271 -0
- package/browser/esm2020/lib/models.mjs +135 -0
- package/browser/esm2020/lib/params.mjs +305 -0
- package/browser/esm2020/lib/request-cache.mjs +95 -0
- package/browser/esm2020/lib/resource.service.mjs +255 -0
- package/browser/esm2020/lib/rest-headers.mjs +129 -0
- package/browser/esm2020/lib/rest-request.mjs +310 -0
- package/browser/esm2020/lib/rest.class.mjs +114 -0
- package/browser/esm2020/lib/simple-resource.mjs +117 -0
- package/browser/esm2020/ng2-rest.mjs +5 -0
- package/browser/esm2020/public-api.mjs +2 -0
- package/browser/fesm2015/ng2-rest.mjs +1754 -0
- package/browser/fesm2015/ng2-rest.mjs.map +1 -0
- package/browser/fesm2020/ng2-rest.mjs +1751 -0
- package/browser/fesm2020/ng2-rest.mjs.map +1 -0
- package/browser/{cookie.d.ts → lib/cookie.d.ts} +0 -0
- package/browser/{helpers.d.ts → lib/helpers.d.ts} +0 -0
- package/browser/{index.d.ts → lib/index.d.ts} +0 -0
- package/browser/{mapping.d.ts → lib/mapping.d.ts} +0 -0
- package/{client → browser/lib}/models.d.ts +2 -3
- package/browser/{params.d.ts → lib/params.d.ts} +0 -0
- package/browser/{request-cache.d.ts → lib/request-cache.d.ts} +0 -0
- package/browser/{resource.service.d.ts → lib/resource.service.d.ts} +1 -5
- package/browser/{rest-headers.d.ts → lib/rest-headers.d.ts} +0 -0
- package/{rest-request.d.ts → browser/lib/rest-request.d.ts} +0 -3
- package/{rest.class.d.ts → browser/lib/rest.class.d.ts} +0 -1
- package/browser/{simple-resource.d.ts → lib/simple-resource.d.ts} +1 -5
- package/browser/ng2-rest.d.ts +5 -0
- package/browser/package.json +31 -0
- package/browser/public-api.d.ts +1 -0
- package/client/README.md +24 -0
- package/client/esm2020/lib/cookie.mjs +27 -0
- package/client/esm2020/lib/helpers.mjs +22 -0
- package/client/esm2020/lib/index.mjs +10 -0
- package/client/esm2020/lib/mapping.mjs +271 -0
- package/client/esm2020/lib/models.mjs +135 -0
- package/client/esm2020/lib/params.mjs +305 -0
- package/client/esm2020/lib/request-cache.mjs +95 -0
- package/client/esm2020/lib/resource.service.mjs +255 -0
- package/client/esm2020/lib/rest-headers.mjs +129 -0
- package/client/esm2020/lib/rest-request.mjs +310 -0
- package/client/esm2020/lib/rest.class.mjs +114 -0
- package/client/esm2020/lib/simple-resource.mjs +117 -0
- package/client/esm2020/ng2-rest.mjs +5 -0
- package/client/esm2020/public-api.mjs +2 -0
- package/client/fesm2015/ng2-rest.mjs +1754 -0
- package/client/fesm2015/ng2-rest.mjs.map +1 -0
- package/client/fesm2020/ng2-rest.mjs +1751 -0
- package/client/fesm2020/ng2-rest.mjs.map +1 -0
- package/client/{cookie.d.ts → lib/cookie.d.ts} +0 -0
- package/client/{helpers.d.ts → lib/helpers.d.ts} +0 -0
- package/client/{index.d.ts → lib/index.d.ts} +0 -0
- package/client/{mapping.d.ts → lib/mapping.d.ts} +0 -0
- package/{browser → client/lib}/models.d.ts +2 -3
- package/client/{params.d.ts → lib/params.d.ts} +0 -0
- package/client/{request-cache.d.ts → lib/request-cache.d.ts} +0 -0
- package/client/{resource.service.d.ts → lib/resource.service.d.ts} +1 -5
- package/client/{rest-headers.d.ts → lib/rest-headers.d.ts} +0 -0
- package/client/{rest-request.d.ts → lib/rest-request.d.ts} +0 -3
- package/client/{rest.class.d.ts → lib/rest.class.d.ts} +0 -1
- package/{simple-resource.d.ts → client/lib/simple-resource.d.ts} +1 -5
- package/client/ng2-rest.d.ts +5 -0
- package/client/package.json +25 -31
- package/client/public-api.d.ts +1 -0
- package/index.d.ts +1 -9
- package/index.js +3 -13
- package/index.js.map +1 -1
- package/{cookie.d.ts → lib/cookie.d.ts} +0 -0
- package/{cookie.js → lib/cookie.js} +2 -1
- package/lib/cookie.js.map +1 -0
- package/{helpers.d.ts → lib/helpers.d.ts} +0 -0
- package/{helpers.js → lib/helpers.js} +3 -2
- package/lib/helpers.js.map +1 -0
- package/{browser/index.js → lib/index.d.ts} +0 -1
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/{mapping.d.ts → lib/mapping.d.ts} +0 -0
- package/{mapping.js → lib/mapping.js} +5 -4
- package/lib/mapping.js.map +1 -0
- package/{models.d.ts → lib/models.d.ts} +2 -3
- package/{models.js → lib/models.js} +6 -6
- package/lib/models.js.map +1 -0
- package/{params.d.ts → lib/params.d.ts} +0 -0
- package/{params.js → lib/params.js} +17 -16
- package/lib/params.js.map +1 -0
- package/{request-cache.d.ts → lib/request-cache.d.ts} +0 -0
- package/{request-cache.js → lib/request-cache.js} +2 -1
- package/lib/request-cache.js.map +1 -0
- package/{resource.service.d.ts → lib/resource.service.d.ts} +1 -5
- package/{resource.service.js → lib/resource.service.js} +33 -26
- package/lib/resource.service.js.map +1 -0
- package/{rest-headers.d.ts → lib/rest-headers.d.ts} +0 -0
- package/{rest-headers.js → lib/rest-headers.js} +2 -1
- package/lib/rest-headers.js.map +1 -0
- package/{browser → lib}/rest-request.d.ts +0 -3
- package/{rest-request.js → lib/rest-request.js} +19 -20
- package/lib/rest-request.js.map +1 -0
- package/{browser → lib}/rest.class.d.ts +0 -1
- package/{rest.class.js → lib/rest.class.js} +4 -5
- package/lib/rest.class.js.map +1 -0
- package/{client → lib}/simple-resource.d.ts +1 -5
- package/{simple-resource.js → lib/simple-resource.js} +11 -14
- package/lib/simple-resource.js.map +1 -0
- package/package.json +10 -10
- package/package.json_tnp.json5 +39 -0
- package/tmp-environment.json +119 -123
- package/browser/app.d.ts +0 -0
- package/browser/app.js +0 -31
- package/browser/app.js.map +0 -1
- package/browser/cookie.js +0 -27
- package/browser/cookie.js.map +0 -1
- package/browser/es5/app.js +0 -32
- package/browser/es5/cookie.js +0 -50
- package/browser/es5/helpers.js +0 -58
- package/browser/es5/index.js +0 -107
- package/browser/es5/mapping.js +0 -287
- package/browser/es5/models.js +0 -249
- package/browser/es5/params.js +0 -310
- package/browser/es5/request-cache.js +0 -133
- package/browser/es5/resource.service.js +0 -288
- package/browser/es5/rest-headers.js +0 -200
- package/browser/es5/rest-request.js +0 -423
- package/browser/es5/rest.class.js +0 -191
- package/browser/es5/simple-resource.js +0 -175
- package/browser/helpers.js +0 -22
- package/browser/helpers.js.map +0 -1
- package/browser/index.js.map +0 -1
- package/browser/mapping.js +0 -271
- package/browser/mapping.js.map +0 -1
- package/browser/models.js +0 -136
- package/browser/models.js.map +0 -1
- package/browser/params.js +0 -305
- package/browser/params.js.map +0 -1
- package/browser/request-cache.js +0 -95
- package/browser/request-cache.js.map +0 -1
- package/browser/resource.service.js +0 -249
- package/browser/resource.service.js.map +0 -1
- package/browser/rest-headers.js +0 -129
- package/browser/rest-headers.js.map +0 -1
- package/browser/rest-request.js +0 -316
- package/browser/rest-request.js.map +0 -1
- package/browser/rest.class.js +0 -116
- package/browser/rest.class.js.map +0 -1
- package/browser/simple-resource.js +0 -121
- package/browser/simple-resource.js.map +0 -1
- package/client/app.d.ts +0 -0
- package/client/app.js +0 -31
- package/client/app.js.map +0 -1
- package/client/cookie.js +0 -27
- package/client/cookie.js.map +0 -1
- package/client/es5/app.js +0 -32
- package/client/es5/cookie.js +0 -50
- package/client/es5/helpers.js +0 -58
- package/client/es5/index.js +0 -107
- package/client/es5/mapping.js +0 -287
- package/client/es5/models.js +0 -249
- package/client/es5/params.js +0 -310
- package/client/es5/request-cache.js +0 -133
- package/client/es5/resource.service.js +0 -288
- package/client/es5/rest-headers.js +0 -200
- package/client/es5/rest-request.js +0 -423
- package/client/es5/rest.class.js +0 -191
- package/client/es5/simple-resource.js +0 -175
- package/client/helpers.js +0 -22
- package/client/helpers.js.map +0 -1
- package/client/index.js +0 -10
- package/client/index.js.map +0 -1
- package/client/mapping.js +0 -271
- package/client/mapping.js.map +0 -1
- package/client/models.js +0 -136
- package/client/models.js.map +0 -1
- package/client/params.js +0 -305
- package/client/params.js.map +0 -1
- package/client/request-cache.js +0 -95
- package/client/request-cache.js.map +0 -1
- package/client/resource.service.js +0 -249
- package/client/resource.service.js.map +0 -1
- package/client/rest-headers.js +0 -129
- package/client/rest-headers.js.map +0 -1
- package/client/rest-request.js +0 -316
- package/client/rest-request.js.map +0 -1
- package/client/rest.class.js +0 -116
- package/client/rest.class.js.map +0 -1
- package/client/simple-resource.js +0 -121
- package/client/simple-resource.js.map +0 -1
- package/cookie.js.map +0 -1
- package/helpers.js.map +0 -1
- package/mapping.js.map +0 -1
- package/models.js.map +0 -1
- package/package.json_tnp.json +0 -47
- package/params.js.map +0 -1
- package/request-cache.js.map +0 -1
- package/resource.service.js.map +0 -1
- package/rest-headers.js.map +0 -1
- package/rest-request.js.map +0 -1
- package/rest.class.js.map +0 -1
- package/simple-resource.js.map +0 -1
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Resource = 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 _Subject = require('rxjs/Subject');
|
|
11
|
-
|
|
12
|
-
require('rxjs/add/operator/map');
|
|
13
|
-
|
|
14
|
-
require('rxjs/add/operator/takeUntil');
|
|
15
|
-
|
|
16
|
-
require('rxjs/add/operator/take');
|
|
17
|
-
|
|
18
|
-
require('rxjs/add/operator/toPromise');
|
|
19
|
-
|
|
20
|
-
var _browser = require('ng2-logger/browser');
|
|
21
|
-
|
|
22
|
-
var _rest = require('./rest.class');
|
|
23
|
-
|
|
24
|
-
var _restRequest = require('./rest-request');
|
|
25
|
-
|
|
26
|
-
var _restHeaders = require('./rest-headers');
|
|
27
|
-
|
|
28
|
-
var _cookie = require('./cookie');
|
|
29
|
-
|
|
30
|
-
var _params = require('./params');
|
|
31
|
-
|
|
32
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
33
|
-
|
|
34
|
-
var log = _browser.Log.create('resouce-service', _browser.Level.__NOTHING);
|
|
35
|
-
|
|
36
|
-
var Resource = exports.Resource = function () {
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region constructor
|
|
39
|
-
function Resource() {
|
|
40
|
-
var _this = this;
|
|
41
|
-
|
|
42
|
-
_classCallCheck(this, Resource);
|
|
43
|
-
|
|
44
|
-
setTimeout(function () {
|
|
45
|
-
var zone = _this.getZone();
|
|
46
|
-
if (!_restRequest.RestRequest.zone) _restRequest.RestRequest.zone = zone;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_createClass(Resource, [{
|
|
51
|
-
key: 'getZone',
|
|
52
|
-
|
|
53
|
-
//#region private mthods and fields
|
|
54
|
-
value: function getZone() {
|
|
55
|
-
var isNode = typeof window === 'undefined';
|
|
56
|
-
if (isNode) return;
|
|
57
|
-
var ng = window['ng'];
|
|
58
|
-
var getAllAngularRootElements = window['getAllAngularRootElements'];
|
|
59
|
-
if (!ng || !getAllAngularRootElements) return;
|
|
60
|
-
var probe = ng.probe;
|
|
61
|
-
var coreTokens = ng.coreTokens;
|
|
62
|
-
if (!coreTokens.NgZone) return;
|
|
63
|
-
var zoneClass = coreTokens.NgZone;
|
|
64
|
-
if (!probe || typeof probe !== 'function' || !getAllAngularRootElements) return;
|
|
65
|
-
var angularElements = getAllAngularRootElements();
|
|
66
|
-
if (!Array.isArray(angularElements) || angularElements.length === 0) return;
|
|
67
|
-
var rootElement = ng.probe(angularElements[0]);
|
|
68
|
-
if (!rootElement) return;
|
|
69
|
-
var injector = rootElement.injector;
|
|
70
|
-
if (!injector || !injector.get || typeof injector.get !== 'function') return;
|
|
71
|
-
var zone = injector.get(zoneClass);
|
|
72
|
-
return zone;
|
|
73
|
-
}
|
|
74
|
-
}, {
|
|
75
|
-
key: 'checkNestedModels',
|
|
76
|
-
value: function checkNestedModels(model, allModels) {
|
|
77
|
-
// if (model.indexOf('/') !== -1) { //TODO make this better, becouse now I unecesary checking shit
|
|
78
|
-
for (var p in allModels) {
|
|
79
|
-
if (allModels.hasOwnProperty(p)) {
|
|
80
|
-
var m = allModels[p];
|
|
81
|
-
if ((0, _params.isValid)(p)) {
|
|
82
|
-
var urlModels = (0, _params.getModels)(p);
|
|
83
|
-
if ((0, _params.containsModels)(model, urlModels)) {
|
|
84
|
-
model = p;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// }
|
|
91
|
-
return model;
|
|
92
|
-
}
|
|
93
|
-
}, {
|
|
94
|
-
key: 'add',
|
|
95
|
-
|
|
96
|
-
//#region add
|
|
97
|
-
/**
|
|
98
|
-
* And enipoint to application
|
|
99
|
-
*
|
|
100
|
-
* @param {E} endpoint
|
|
101
|
-
* @param {string} model
|
|
102
|
-
* @returns {boolean}
|
|
103
|
-
*/
|
|
104
|
-
value: function add(endpoint, model, entity, circular) {
|
|
105
|
-
log.i('I am maping ' + model + ' on ' + endpoint);
|
|
106
|
-
model = Resource.prepareModel(model);
|
|
107
|
-
var e = void 0;
|
|
108
|
-
e = endpoint.toString();
|
|
109
|
-
if (Resource.endpoints[e] === void 0) {
|
|
110
|
-
console.error('Endpoint is not mapped ! Cannot add model ' + model);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (Resource.endpoints[e].models[model] !== void 0) {
|
|
114
|
-
if (Resource.enableWarnings) console.warn('Model \'' + model + '\' is already defined in endpoint: ' + Resource.endpoints[e].url);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
Resource.endpoints[e].models[model] = new _rest.Rest(Resource.endpoints[e].url + '/' + model, Resource.request, {
|
|
118
|
-
endpoint: e,
|
|
119
|
-
path: model,
|
|
120
|
-
entity: entity,
|
|
121
|
-
circular: circular
|
|
122
|
-
});
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region api
|
|
127
|
-
/**
|
|
128
|
-
* Access api throught endpoint
|
|
129
|
-
*
|
|
130
|
-
* @param {E} endpoint
|
|
131
|
-
* @param {string} model
|
|
132
|
-
* @returns {Rest<T, TA>}
|
|
133
|
-
*/
|
|
134
|
-
|
|
135
|
-
}, {
|
|
136
|
-
key: 'api',
|
|
137
|
-
value: function api(endpoint, model) {
|
|
138
|
-
// log.i(`[api]
|
|
139
|
-
// creating for endpoint: "${endpoint}"
|
|
140
|
-
// model: "${model}"
|
|
141
|
-
// `)
|
|
142
|
-
if (model.charAt(0) === '/') model = model.slice(1, model.length);
|
|
143
|
-
var e = endpoint.toString();
|
|
144
|
-
if (Resource.endpoints[e] === void 0) {
|
|
145
|
-
throw 'Endpoint: ' + endpoint + ' is not mapped ! Cannot add model: ' + model;
|
|
146
|
-
}
|
|
147
|
-
var allModels = Resource.endpoints[e].models;
|
|
148
|
-
var orgModel = model;
|
|
149
|
-
model = this.checkNestedModels(model, allModels);
|
|
150
|
-
if (Resource.endpoints[e].models[model] === void 0) {
|
|
151
|
-
// log.d('Resource.endpoints', Resource.endpoints);
|
|
152
|
-
throw 'Model \'' + model + '\' is undefined in endpoint: ' + Resource.endpoints[e].url + ' ';
|
|
153
|
-
}
|
|
154
|
-
var res = Resource.endpoints[endpoint.toString()].models[model];
|
|
155
|
-
// log.d(`
|
|
156
|
-
// orgModel: ${orgModel}
|
|
157
|
-
// model: ${model}
|
|
158
|
-
// `)
|
|
159
|
-
if (orgModel !== model) {
|
|
160
|
-
var baseUrl = Resource.endpoints[endpoint.toString()].url;
|
|
161
|
-
// log.d('base', Resource.endpoints[<string>(endpoint).toString()])
|
|
162
|
-
// log.d('baseUrl', baseUrl)
|
|
163
|
-
// log.d('orgModel', orgModel)
|
|
164
|
-
res.__rest_endpoint = baseUrl + '/' + orgModel;
|
|
165
|
-
} else {
|
|
166
|
-
res.__rest_endpoint = void 0;
|
|
167
|
-
}
|
|
168
|
-
;
|
|
169
|
-
// log.i(`Resource.endpoints`, Resource.endpoints)
|
|
170
|
-
return res;
|
|
171
|
-
}
|
|
172
|
-
}], [{
|
|
173
|
-
key: 'initAngularNgZone',
|
|
174
|
-
value: function initAngularNgZone(zone) {
|
|
175
|
-
_restRequest.RestRequest.zone = zone;
|
|
176
|
-
}
|
|
177
|
-
}, {
|
|
178
|
-
key: 'getModel',
|
|
179
|
-
value: function getModel(endpoint, model) {
|
|
180
|
-
model = Resource.prepareModel(model);
|
|
181
|
-
var e = Resource.endpoints[endpoint];
|
|
182
|
-
if (!e) {
|
|
183
|
-
return void 0;
|
|
184
|
-
}
|
|
185
|
-
var r = Resource.endpoints[endpoint].models[model];
|
|
186
|
-
return Resource.endpoints[endpoint].models[model];
|
|
187
|
-
}
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region create
|
|
190
|
-
|
|
191
|
-
}, {
|
|
192
|
-
key: 'create',
|
|
193
|
-
value: function create(e, _model, entityMapping, circular) {
|
|
194
|
-
var badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
|
|
195
|
-
var matchArr = _model.match(badRestRegEX) || [];
|
|
196
|
-
var badModelsNextToEachOther = matchArr.join();
|
|
197
|
-
var atleas2DoubleDots = (badModelsNextToEachOther.match(new RegExp(':', 'g')) || []).length >= 2;
|
|
198
|
-
if (atleas2DoubleDots && _model.search(badModelsNextToEachOther) !== -1) {
|
|
199
|
-
throw new Error('\n\nBad rest model: ' + _model + '\n\nDo not create rest models like this: /book/author/:bookid/:authorid\nInstead use nested approach: /book/:bookid/author/:authorid\n ');
|
|
200
|
-
}
|
|
201
|
-
;
|
|
202
|
-
Resource.map(e, e);
|
|
203
|
-
Resource.instance.add(e, _model ? _model : '', entityMapping, circular);
|
|
204
|
-
// if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
|
|
205
|
-
return {
|
|
206
|
-
model: function model(params) {
|
|
207
|
-
return Resource.instance.api(e, (0, _params.interpolateParamsToUrl)(params, _model));
|
|
208
|
-
},
|
|
209
|
-
replay: function replay(method) {
|
|
210
|
-
Resource.getModel(e, _model).replay(method);
|
|
211
|
-
},
|
|
212
|
-
get headers() {
|
|
213
|
-
return Resource.getModel(e, _model).headers;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region reset
|
|
219
|
-
|
|
220
|
-
}, {
|
|
221
|
-
key: 'reset',
|
|
222
|
-
value: function reset() {
|
|
223
|
-
Resource.endpoints = {};
|
|
224
|
-
}
|
|
225
|
-
//#region map
|
|
226
|
-
|
|
227
|
-
}, {
|
|
228
|
-
key: 'map',
|
|
229
|
-
value: function map(endpoint, url) {
|
|
230
|
-
log.i('url', url);
|
|
231
|
-
var regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
|
|
232
|
-
var e = endpoint;
|
|
233
|
-
if (!regex.test(url)) {
|
|
234
|
-
throw 'Url address is not correct: ' + url;
|
|
235
|
-
}
|
|
236
|
-
if (url.charAt(url.length - 1) === '/') url = url.slice(0, url.length - 1);
|
|
237
|
-
log.i('url after', url);
|
|
238
|
-
if (Resource.endpoints[e] !== void 0) {
|
|
239
|
-
!global.hideLog && console.warn('Cannot use map function at the same API endpoint again (' + Resource.endpoints[e].url + ')');
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
Resource.endpoints[e] = {
|
|
243
|
-
url: url,
|
|
244
|
-
models: {},
|
|
245
|
-
entity: null
|
|
246
|
-
};
|
|
247
|
-
log.i('enpoints', Resource.endpoints);
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
//#endregion
|
|
251
|
-
|
|
252
|
-
}, {
|
|
253
|
-
key: 'prepareModel',
|
|
254
|
-
value: function prepareModel(model) {
|
|
255
|
-
if (model.charAt(model.length - 1) === '/') model = model.slice(0, model.length - 1);
|
|
256
|
-
if (model.charAt(0) === '/') model = model.slice(1, model.length);
|
|
257
|
-
return model;
|
|
258
|
-
}
|
|
259
|
-
}, {
|
|
260
|
-
key: 'listenErrors',
|
|
261
|
-
get: function get() {
|
|
262
|
-
return this._listenErrors.asObservable();
|
|
263
|
-
}
|
|
264
|
-
}]);
|
|
265
|
-
|
|
266
|
-
return Resource;
|
|
267
|
-
}();
|
|
268
|
-
|
|
269
|
-
Resource.DEFAULT_HEADERS = _restHeaders.RestHeaders.from({
|
|
270
|
-
'Content-Type': 'application/json',
|
|
271
|
-
'Accept': 'application/json'
|
|
272
|
-
});
|
|
273
|
-
Resource._listenErrors = new _Subject.Subject();
|
|
274
|
-
Resource.enableWarnings = true;
|
|
275
|
-
Resource.instance = new Resource();
|
|
276
|
-
Resource.endpoints = {};
|
|
277
|
-
Resource.request = new _restRequest.RestRequest();
|
|
278
|
-
//#endregion
|
|
279
|
-
Resource.Cookies = _cookie.Cookie.Instance;
|
|
280
|
-
// const res = Resource.create('')
|
|
281
|
-
// res.model()
|
|
282
|
-
// .mock({
|
|
283
|
-
// code: 500,
|
|
284
|
-
// data: {},
|
|
285
|
-
// isArray: true
|
|
286
|
-
// })
|
|
287
|
-
// .array.
|
|
288
|
-
//# sourceMappingURL=resource.service.js.map
|
|
@@ -1,200 +0,0 @@
|
|
|
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 _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
10
|
-
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
13
|
-
var RestHeaders = exports.RestHeaders = function () {
|
|
14
|
-
function RestHeaders(headers) {
|
|
15
|
-
var _this = this;
|
|
16
|
-
|
|
17
|
-
_classCallCheck(this, RestHeaders);
|
|
18
|
-
|
|
19
|
-
/** @internal header names are lower case */
|
|
20
|
-
this._headers = new Map();
|
|
21
|
-
/** @internal map lower case names to actual names */
|
|
22
|
-
this._normalizedNames = new Map();
|
|
23
|
-
if (headers instanceof RestHeaders) {
|
|
24
|
-
headers.forEach(function (values, name) {
|
|
25
|
-
values.forEach(function (value) {
|
|
26
|
-
return _this.set(name, value);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
30
|
-
Object.keys(headers).forEach(function (name) {
|
|
31
|
-
var values = Array.isArray(headers[name]) ? headers[name] : [headers[name]];
|
|
32
|
-
_this.delete(name);
|
|
33
|
-
values.forEach(function (value) {
|
|
34
|
-
return _this.set(name, value);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
_createClass(RestHeaders, [{
|
|
41
|
-
key: 'append',
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Appends a header to existing list of header values for a given header name.
|
|
45
|
-
*/
|
|
46
|
-
value: function append(name, value) {
|
|
47
|
-
var values = this.getAll(name);
|
|
48
|
-
if (values === null) {
|
|
49
|
-
this.set(name, value);
|
|
50
|
-
} else {
|
|
51
|
-
values.push(value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Deletes all header values for the given name.
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
}, {
|
|
59
|
-
key: 'delete',
|
|
60
|
-
value: function _delete(name) {
|
|
61
|
-
var lcName = name.toLowerCase();
|
|
62
|
-
this._normalizedNames.delete(lcName);
|
|
63
|
-
this._headers.delete(lcName);
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
key: 'forEach',
|
|
67
|
-
value: function forEach(fn) {
|
|
68
|
-
var _this2 = this;
|
|
69
|
-
|
|
70
|
-
this._headers.forEach(function (values, lcName) {
|
|
71
|
-
return fn(values, _this2._normalizedNames.get(lcName), _this2._headers);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns first header that matches given name.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
}, {
|
|
79
|
-
key: 'get',
|
|
80
|
-
value: function get(name) {
|
|
81
|
-
var values = this.getAll(name);
|
|
82
|
-
if (values === null) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
return values.length > 0 ? values[0] : null;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Checks for existence of header by given name.
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
}, {
|
|
92
|
-
key: 'has',
|
|
93
|
-
value: function has(name) {
|
|
94
|
-
return this._headers.has(name.toLowerCase());
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Returns the names of the headers
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
}, {
|
|
101
|
-
key: 'keys',
|
|
102
|
-
value: function keys() {
|
|
103
|
-
return Array.from(this._normalizedNames.values());
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Sets or overrides header value for given name.
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
}, {
|
|
110
|
-
key: 'set',
|
|
111
|
-
value: function set(name, value) {
|
|
112
|
-
if (Array.isArray(value)) {
|
|
113
|
-
if (value.length) {
|
|
114
|
-
this._headers.set(name.toLowerCase(), [value.join(',')]);
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
this._headers.set(name.toLowerCase(), [value]);
|
|
118
|
-
}
|
|
119
|
-
this.mayBeSetNormalizedName(name);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns values of all headers.
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
}, {
|
|
126
|
-
key: 'values',
|
|
127
|
-
value: function values() {
|
|
128
|
-
return Array.from(this._headers.values());
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Returns string of all headers.
|
|
132
|
-
*/
|
|
133
|
-
// TODO(vicb): returns {[name: string]: string[]}
|
|
134
|
-
|
|
135
|
-
}, {
|
|
136
|
-
key: 'toJSON',
|
|
137
|
-
value: function toJSON() {
|
|
138
|
-
var _this3 = this;
|
|
139
|
-
|
|
140
|
-
var serialized = {};
|
|
141
|
-
if (!this._headers) {
|
|
142
|
-
debugger;
|
|
143
|
-
}
|
|
144
|
-
this._headers.forEach(function (values, name) {
|
|
145
|
-
var split = [];
|
|
146
|
-
values.forEach(function (v) {
|
|
147
|
-
return split.push.apply(split, _toConsumableArray(v.split(',')));
|
|
148
|
-
});
|
|
149
|
-
serialized[_this3._normalizedNames.get(name)] = split;
|
|
150
|
-
});
|
|
151
|
-
return serialized;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Returns list of header values for a given name.
|
|
155
|
-
*/
|
|
156
|
-
|
|
157
|
-
}, {
|
|
158
|
-
key: 'getAll',
|
|
159
|
-
value: function getAll(name) {
|
|
160
|
-
return this.has(name) ? this._headers.get(name.toLowerCase()) : null;
|
|
161
|
-
}
|
|
162
|
-
}, {
|
|
163
|
-
key: 'mayBeSetNormalizedName',
|
|
164
|
-
value: function mayBeSetNormalizedName(name) {
|
|
165
|
-
var lcName = name.toLowerCase();
|
|
166
|
-
if (!this._normalizedNames.has(lcName)) {
|
|
167
|
-
this._normalizedNames.set(lcName, name);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}], [{
|
|
171
|
-
key: 'from',
|
|
172
|
-
value: function from(headers) {
|
|
173
|
-
if (!headers) {
|
|
174
|
-
return void 0;
|
|
175
|
-
}
|
|
176
|
-
return new RestHeaders(headers);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Returns a new RestHeaders instance from the given DOMString of Response RestHeaders
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
}, {
|
|
183
|
-
key: 'fromResponseHeaderString',
|
|
184
|
-
value: function fromResponseHeaderString(headersString) {
|
|
185
|
-
var headers = new RestHeaders();
|
|
186
|
-
headersString.split('\n').forEach(function (line) {
|
|
187
|
-
var index = line.indexOf(':');
|
|
188
|
-
if (index > 0) {
|
|
189
|
-
var name = line.slice(0, index);
|
|
190
|
-
var value = line.slice(index + 1).trim();
|
|
191
|
-
headers.set(name, value);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
return headers;
|
|
195
|
-
}
|
|
196
|
-
}]);
|
|
197
|
-
|
|
198
|
-
return RestHeaders;
|
|
199
|
-
}();
|
|
200
|
-
//# sourceMappingURL=rest-headers.js.map
|