@rxap/remote-method 21.0.1 → 22.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/compodoc/changelog.html +5 -0
- package/compodoc/dependencies.html +4 -4
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +130 -130
- package/docs/html/classes/BaseRemoteMethod.html +10 -10
- package/docs/html/classes/ProxyRemoteMethod.html +10 -10
- package/docs/html/classes/RemoteMethodLoader.html +2 -2
- package/docs/html/classes/RxapRemoteMethodError.html +5 -5
- package/docs/html/functions/RxapRemoteMethod.html +1 -1
- package/docs/html/hierarchy.html +1 -1
- package/docs/html/index.html +2 -2
- package/docs/html/interfaces/BaseRemoteMethodMetadata.html +2 -2
- package/docs/html/modules.html +1 -1
- package/docs/html/variables/REMOTE_METHOD_META_DATA.html +1 -1
- package/docs/html/variables/RXAP_PROXY_REMOTE_METHOD_TARGET.html +1 -1
- package/docs/markdown/README.md +1 -1
- package/docs/markdown/classes/BaseRemoteMethod.md +31 -31
- package/docs/markdown/classes/ProxyRemoteMethod.md +32 -32
- package/docs/markdown/classes/RemoteMethodLoader.md +4 -4
- package/docs/markdown/classes/RxapRemoteMethodError.md +16 -16
- package/docs/markdown/functions/RxapRemoteMethod.md +2 -2
- package/docs/markdown/globals.md +2 -2
- package/docs/markdown/interfaces/BaseRemoteMethodMetadata.md +4 -4
- package/docs/markdown/variables/REMOTE_METHOD_META_DATA.md +2 -2
- package/docs/markdown/variables/RXAP_PROXY_REMOTE_METHOD_TARGET.md +2 -2
- package/docs/wiki/Class.BaseRemoteMethod.md +30 -30
- package/docs/wiki/Class.ProxyRemoteMethod.md +31 -31
- package/docs/wiki/Class.RemoteMethodLoader.md +3 -3
- package/docs/wiki/Class.RxapRemoteMethodError.md +15 -15
- package/docs/wiki/Function.RxapRemoteMethod.md +1 -1
- package/docs/wiki/Interface.BaseRemoteMethodMetadata.md +3 -3
- package/docs/wiki/Variable.REMOTE_METHOD_META_DATA.md +1 -1
- package/docs/wiki/Variable.RXAP_PROXY_REMOTE_METHOD_TARGET.md +1 -1
- package/docs/wiki/globals.md +1 -1
- package/fesm2022/rxap-remote-method-directive.mjs +804 -522
- package/fesm2022/rxap-remote-method-directive.mjs.map +1 -1
- package/fesm2022/rxap-remote-method-http-directive.mjs +352 -99
- package/fesm2022/rxap-remote-method-http-directive.mjs.map +1 -1
- package/fesm2022/rxap-remote-method-http.mjs +206 -162
- package/fesm2022/rxap-remote-method-http.mjs.map +1 -1
- package/fesm2022/rxap-remote-method-testing.mjs +37 -54
- package/fesm2022/rxap-remote-method-testing.mjs.map +1 -1
- package/fesm2022/rxap-remote-method.mjs +199 -134
- package/fesm2022/rxap-remote-method.mjs.map +1 -1
- package/package.json +8 -8
- package/types/rxap-remote-method-directive.d.ts +295 -203
- package/types/rxap-remote-method-http-directive.d.ts +104 -39
- package/types/rxap-remote-method-http.d.ts +63 -64
- package/types/rxap-remote-method-testing.d.ts +15 -16
- package/types/rxap-remote-method.d.ts +47 -48
|
@@ -1,163 +1,207 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import * as i1 from
|
|
4
|
-
import { HttpClient,
|
|
5
|
-
import { BaseRemoteMethod,
|
|
6
|
-
import { hasIndexSignature } from
|
|
7
|
-
import {
|
|
8
|
-
import { firstValueFrom } from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
i0.ɵɵ
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Inject, Injectable, Injector, Optional, inject } from "@angular/core";
|
|
3
|
+
import * as i1 from "@angular/common/http";
|
|
4
|
+
import { HttpClient, HttpEventType, HttpRequest, HttpResponse } from "@angular/common/http";
|
|
5
|
+
import { BaseRemoteMethod, REMOTE_METHOD_META_DATA, RemoteMethodLoader, RxapRemoteMethodError } from "@rxap/remote-method";
|
|
6
|
+
import { hasIndexSignature } from "@rxap/utilities";
|
|
7
|
+
import { filter, map, retry, tap, timeout } from "rxjs/operators";
|
|
8
|
+
import { firstValueFrom } from "rxjs";
|
|
9
|
+
var BaseHttpRemoteMethod = class BaseHttpRemoteMethod extends BaseRemoteMethod {
|
|
10
|
+
constructor(http, injector, metaData = null) {
|
|
11
|
+
super(injector, metaData);
|
|
12
|
+
this.http = http;
|
|
13
|
+
this.timeout = 6e4;
|
|
14
|
+
this.timeout = this.metadata.timeout ?? this.timeout;
|
|
15
|
+
if (http === void 0) throw new RxapRemoteMethodError("HttpClient is undefined. Ensure that the HttpClient is added to the deps property!", "", this.constructor.name);
|
|
16
|
+
if (!(http instanceof HttpClient)) throw new RxapRemoteMethodError("The property http is not an instance of HttpClinent. Check the deps property!", "", this.constructor.name);
|
|
17
|
+
}
|
|
18
|
+
init() {
|
|
19
|
+
super.init();
|
|
20
|
+
this._httpRequest = new HttpRequest(this.metadata.method, this.getRequestUrl(), null, {
|
|
21
|
+
headers: this.metadata.headers,
|
|
22
|
+
reportProgress: this.metadata.reportProgress,
|
|
23
|
+
params: this.metadata.params,
|
|
24
|
+
responseType: this.metadata.responseType || "json",
|
|
25
|
+
withCredentials: this.metadata.withCredentials
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
updateRequest(parameters) {
|
|
29
|
+
let url = this._httpRequest.url;
|
|
30
|
+
if (parameters && parameters["pathParams"]) url = this.buildUrlWithParams(url, parameters.pathParams);
|
|
31
|
+
return this._httpRequest.clone({
|
|
32
|
+
withCredentials: this.metadata.withCredentials,
|
|
33
|
+
context: this.metadata.context,
|
|
34
|
+
...parameters,
|
|
35
|
+
url
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
buildUrlWithParams(url, pathParams) {
|
|
39
|
+
if (pathParams) {
|
|
40
|
+
if (!hasIndexSignature(pathParams)) throw new RxapRemoteMethodError(`Path params for remote method '${this.id}' has not an index signature`, "", this.constructor.name);
|
|
41
|
+
const matches = url.match(/\{[^}]+\}/g);
|
|
42
|
+
if (matches) for (const match of matches) {
|
|
43
|
+
const param = match.substr(1, match.length - 2);
|
|
44
|
+
if (pathParams[param] === void 0) throw new RxapRemoteMethodError(`Path params for remote method '${this.id}' has not a defined value for '${param}'`, "", this.constructor.name);
|
|
45
|
+
url = url.replace(match, encodeURIComponent(pathParams[param]));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return url;
|
|
49
|
+
}
|
|
50
|
+
getRequestUrl() {
|
|
51
|
+
if (typeof this.metadata.url === "function") return this.metadata.url();
|
|
52
|
+
return this.metadata.url;
|
|
53
|
+
}
|
|
54
|
+
static {
|
|
55
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
56
|
+
minVersion: "12.0.0",
|
|
57
|
+
version: "22.3.0",
|
|
58
|
+
ngImport: i0,
|
|
59
|
+
type: BaseHttpRemoteMethod,
|
|
60
|
+
deps: [
|
|
61
|
+
{ token: HttpClient },
|
|
62
|
+
{ token: Injector },
|
|
63
|
+
{
|
|
64
|
+
token: REMOTE_METHOD_META_DATA,
|
|
65
|
+
optional: true
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
static {
|
|
72
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
73
|
+
minVersion: "12.0.0",
|
|
74
|
+
version: "22.3.0",
|
|
75
|
+
ngImport: i0,
|
|
76
|
+
type: BaseHttpRemoteMethod
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
81
|
+
minVersion: "12.0.0",
|
|
82
|
+
version: "22.3.0",
|
|
83
|
+
ngImport: i0,
|
|
84
|
+
type: BaseHttpRemoteMethod,
|
|
85
|
+
decorators: [{ type: Injectable }],
|
|
86
|
+
ctorParameters: () => [
|
|
87
|
+
{
|
|
88
|
+
type: i1.HttpClient,
|
|
89
|
+
decorators: [{
|
|
90
|
+
type: Inject,
|
|
91
|
+
args: [HttpClient]
|
|
92
|
+
}]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
type: i0.Injector,
|
|
96
|
+
decorators: [{
|
|
97
|
+
type: Inject,
|
|
98
|
+
args: [Injector]
|
|
99
|
+
}]
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: void 0,
|
|
103
|
+
decorators: [{ type: Optional }, {
|
|
104
|
+
type: Inject,
|
|
105
|
+
args: [REMOTE_METHOD_META_DATA]
|
|
106
|
+
}]
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
var HttpRemoteMethod = class HttpRemoteMethod extends BaseHttpRemoteMethod {
|
|
111
|
+
onSentEvent(event) {}
|
|
112
|
+
onHeaderResponse(event) {}
|
|
113
|
+
onResponse(event) {}
|
|
114
|
+
onProgressEvent(event) {}
|
|
115
|
+
createHttpRequestParameters(parameters) {
|
|
116
|
+
return parameters ?? {};
|
|
117
|
+
}
|
|
118
|
+
transformer(response) {
|
|
119
|
+
return response;
|
|
120
|
+
}
|
|
121
|
+
_call(parameters) {
|
|
122
|
+
return firstValueFrom(this.http.request(this.updateRequest(this.createHttpRequestParameters(parameters))).pipe(retry(this.metadata.retry ?? 0), tap((event) => {
|
|
123
|
+
switch (event.type) {
|
|
124
|
+
case HttpEventType.Sent:
|
|
125
|
+
this.onSentEvent(event);
|
|
126
|
+
break;
|
|
127
|
+
case HttpEventType.Response:
|
|
128
|
+
this.onResponse(event);
|
|
129
|
+
break;
|
|
130
|
+
case HttpEventType.DownloadProgress:
|
|
131
|
+
this.onProgressEvent(event);
|
|
132
|
+
break;
|
|
133
|
+
case HttpEventType.UploadProgress:
|
|
134
|
+
this.onProgressEvent(event);
|
|
135
|
+
break;
|
|
136
|
+
case HttpEventType.ResponseHeader: this.onHeaderResponse(event);
|
|
137
|
+
}
|
|
138
|
+
}), filter((event) => event instanceof HttpResponse), map((event) => event.body), map((body) => this.transformer(body)), timeout(this.timeout)));
|
|
139
|
+
}
|
|
140
|
+
static {
|
|
141
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
142
|
+
minVersion: "12.0.0",
|
|
143
|
+
version: "22.3.0",
|
|
144
|
+
ngImport: i0,
|
|
145
|
+
type: HttpRemoteMethod,
|
|
146
|
+
deps: null,
|
|
147
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
static {
|
|
151
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
152
|
+
minVersion: "12.0.0",
|
|
153
|
+
version: "22.3.0",
|
|
154
|
+
ngImport: i0,
|
|
155
|
+
type: HttpRemoteMethod
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
160
|
+
minVersion: "12.0.0",
|
|
161
|
+
version: "22.3.0",
|
|
162
|
+
ngImport: i0,
|
|
163
|
+
type: HttpRemoteMethod,
|
|
164
|
+
decorators: [{ type: Injectable }]
|
|
165
|
+
});
|
|
166
|
+
var HttpRemoteMethodLoader = class HttpRemoteMethodLoader {
|
|
167
|
+
constructor() {
|
|
168
|
+
this.remoteMethodLoader = inject(RemoteMethodLoader);
|
|
169
|
+
}
|
|
170
|
+
request$(remoteMethodIdOrInstanceOrToken, parameters, metadata, injector, notFoundValue, flags) {
|
|
171
|
+
const remoteMethod = this.remoteMethodLoader.load(remoteMethodIdOrInstanceOrToken, metadata, injector, notFoundValue, flags);
|
|
172
|
+
if (!(remoteMethod instanceof HttpRemoteMethod)) throw new RxapRemoteMethodError(`The remote method is not a HttpRemoteMethod`, "", "HttpRemoteMethodLoader");
|
|
173
|
+
return remoteMethod.call(parameters);
|
|
174
|
+
}
|
|
175
|
+
static {
|
|
176
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
177
|
+
minVersion: "12.0.0",
|
|
178
|
+
version: "22.3.0",
|
|
179
|
+
ngImport: i0,
|
|
180
|
+
type: HttpRemoteMethodLoader,
|
|
181
|
+
deps: [],
|
|
182
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
static {
|
|
186
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
187
|
+
minVersion: "12.0.0",
|
|
188
|
+
version: "22.3.0",
|
|
189
|
+
ngImport: i0,
|
|
190
|
+
type: HttpRemoteMethodLoader,
|
|
191
|
+
providedIn: "root"
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
196
|
+
minVersion: "12.0.0",
|
|
197
|
+
version: "22.3.0",
|
|
198
|
+
ngImport: i0,
|
|
199
|
+
type: HttpRemoteMethodLoader,
|
|
200
|
+
decorators: [{
|
|
201
|
+
type: Injectable,
|
|
202
|
+
args: [{ providedIn: "root" }]
|
|
203
|
+
}]
|
|
204
|
+
});
|
|
162
205
|
export { BaseHttpRemoteMethod, HttpRemoteMethod, HttpRemoteMethodLoader };
|
|
163
|
-
|
|
206
|
+
|
|
207
|
+
//# sourceMappingURL=rxap-remote-method-http.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rxap-remote-method-http.mjs","sources":["../../../../../packages/angular/remote-method/http/src/lib/base-http.remote-method.ts","../../../../../packages/angular/remote-method/http/src/lib/http.remote-method.ts","../../../../../packages/angular/remote-method/http/src/lib/http-remote-method.loader.ts","../../../../../packages/angular/remote-method/http/src/index.ts","../../../../../packages/angular/remote-method/http/src/rxap-remote-method-http.ts"],"sourcesContent":["import {\n Inject,\n Injectable,\n Injector,\n Optional,\n} from '@angular/core';\nimport {\n HttpClient,\n HttpContext,\n HttpHeaders,\n HttpParams,\n HttpRequest,\n} from '@angular/common/http';\nimport {\n BaseRemoteMethod,\n BaseRemoteMethodMetadata,\n REMOTE_METHOD_META_DATA,\n RxapRemoteMethodError,\n} from '@rxap/remote-method';\nimport { hasIndexSignature } from '@rxap/utilities';\n\nexport interface HttpRemoteMethodMetadata extends BaseRemoteMethodMetadata {\n url: string | (() => string);\n method: 'DELETE' | 'GET' | 'HEAD' | 'JSONP' | 'OPTIONS' | 'POST' | 'PUT' | 'PATCH';\n headers?: HttpHeaders;\n reportProgress?: boolean;\n params?: HttpParams;\n responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';\n withCredentials?: boolean;\n timeout?: number;\n retry?: number;\n context?: HttpContext;\n}\n\nexport interface HttpRemoteMethodParameter<PathParams = any> {\n headers?: HttpHeaders;\n reportProgress?: boolean;\n params?: HttpParams;\n responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';\n withCredentials?: boolean;\n body?: any | null;\n setHeaders?: {\n [name: string]: string | string[];\n };\n setParams?: {\n [param: string]: string;\n };\n pathParams?: PathParams;\n context?: HttpContext;\n}\n\n@Injectable()\nexport abstract class BaseHttpRemoteMethod<ReturnType = any,\n PathParams = any,\n Parameter extends object = HttpRemoteMethodParameter<PathParams>,\n MetaData extends HttpRemoteMethodMetadata = HttpRemoteMethodMetadata>\n extends BaseRemoteMethod<ReturnType, Parameter, MetaData> {\n\n public timeout = 60 * 1000;\n protected _httpRequest!: HttpRequest<ReturnType>;\n\n constructor(\n @Inject(HttpClient) public readonly http: HttpClient,\n @Inject(Injector) injector: Injector,\n @Optional() @Inject(REMOTE_METHOD_META_DATA) metaData: any | null = null,\n ) {\n super(injector, metaData);\n this.timeout = this.metadata.timeout ?? this.timeout;\n if (http === undefined) {\n throw new RxapRemoteMethodError(\n 'HttpClient is undefined. Ensure that the HttpClient is added to the deps property!',\n '',\n this.constructor.name,\n );\n }\n if (!(http instanceof HttpClient)) {\n throw new RxapRemoteMethodError(\n 'The property http is not an instance of HttpClinent. Check the deps property!',\n '',\n this.constructor.name,\n );\n }\n }\n\n public override init() {\n super.init();\n this._httpRequest = new HttpRequest<ReturnType>(\n this.metadata.method,\n this.getRequestUrl(),\n null,\n {\n headers: this.metadata.headers,\n reportProgress: this.metadata.reportProgress,\n params: this.metadata.params,\n responseType: this.metadata.responseType || 'json',\n withCredentials: this.metadata.withCredentials,\n },\n );\n }\n\n public updateRequest(parameters: Partial<HttpRemoteMethodParameter>): HttpRequest<ReturnType> {\n let url = this._httpRequest.url;\n\n if (parameters && parameters['pathParams']) {\n url = this.buildUrlWithParams(url, (parameters as any).pathParams);\n }\n\n return this._httpRequest.clone({\n withCredentials: this.metadata.withCredentials,\n context: this.metadata.context,\n ...parameters,\n url,\n });\n }\n\n public buildUrlWithParams(url: string, pathParams?: PathParams): string {\n if (pathParams) {\n\n if (!hasIndexSignature(pathParams)) {\n throw new RxapRemoteMethodError(\n `Path params for remote method '${ this.id }' has not an index signature`,\n '',\n this.constructor.name,\n );\n }\n\n const matches = url.match(/\\{[^}]+\\}/g);\n\n if (matches) {\n for (const match of matches) {\n const param = match.substr(1, match.length - 2);\n if (pathParams[param] === undefined) {\n throw new RxapRemoteMethodError(\n `Path params for remote method '${ this.id }' has not a defined value for '${ param }'`,\n '',\n this.constructor.name,\n );\n }\n url = url.replace(match, encodeURIComponent(pathParams[param]));\n }\n }\n }\n\n return url;\n }\n\n protected getRequestUrl(): string {\n if (typeof this.metadata.url === 'function') {\n return this.metadata.url();\n }\n return this.metadata.url;\n }\n\n}\n","import { Injectable } from '@angular/core';\nimport { HttpEventType, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpSentEvent } from '@angular/common/http';\nimport {\n filter,\n map,\n retry,\n tap,\n timeout,\n} from 'rxjs/operators';\nimport {\n BaseHttpRemoteMethod,\n HttpRemoteMethodMetadata,\n HttpRemoteMethodParameter,\n} from './base-http.remote-method';\nimport { firstValueFrom } from 'rxjs';\n\n@Injectable()\nexport class HttpRemoteMethod<ReturnType = any,\n PathParams = any,\n Parameter extends object = HttpRemoteMethodParameter<PathParams>,\n MetaData extends HttpRemoteMethodMetadata = HttpRemoteMethodMetadata>\n extends BaseHttpRemoteMethod<ReturnType, PathParams, Parameter, MetaData> {\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onSentEvent(event: HttpSentEvent): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onHeaderResponse(event: HttpHeaderResponse): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onResponse(event: HttpResponse<ReturnType>): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onProgressEvent(event: HttpProgressEvent): void {\n }\n\n // TODO : make abstract to force implementation to handel parameter transformation\n public createHttpRequestParameters(parameters?: Parameter): Partial<HttpRemoteMethodParameter> {\n return parameters ?? {} as any;\n }\n\n public transformer(response: any): ReturnType {\n return response;\n }\n\n protected _call(parameters?: Parameter): Promise<ReturnType> {\n return firstValueFrom(this.http.request<ReturnType>(this.updateRequest(this.createHttpRequestParameters(parameters)))\n .pipe(\n retry(this.metadata.retry ?? 0),\n tap(event => {\n switch (event.type) {\n\n case HttpEventType.Sent:\n this.onSentEvent(event);\n break;\n\n case HttpEventType.Response:\n this.onResponse(event);\n break;\n\n case HttpEventType.DownloadProgress:\n this.onProgressEvent(event);\n break;\n\n case HttpEventType.UploadProgress:\n this.onProgressEvent(event);\n break;\n\n case HttpEventType.ResponseHeader:\n this.onHeaderResponse(event);\n break;\n\n }\n }),\n filter((event: any) => event instanceof HttpResponse),\n map((event: HttpResponse<ReturnType>) => event.body),\n map(body => this.transformer(body)),\n timeout(this.timeout),\n ));\n }\n\n}\n","import {\n BaseRemoteMethod,\n BaseRemoteMethodMetadata,\n RemoteMethodLoader,\n RxapRemoteMethodError,\n} from '@rxap/remote-method';\nimport { HttpRemoteMethod } from './http.remote-method';\nimport { Injectable, InjectOptions, Injector, inject } from '@angular/core';\nimport { IdOrInstanceOrToken } from '@rxap/definition';\n\n@Injectable({ providedIn: 'root' })\nexport class HttpRemoteMethodLoader {\n private readonly remoteMethodLoader = inject<RemoteMethodLoader>(RemoteMethodLoader);\n\n\n public request$<ReturnType = any, Parameters = any, Metadata extends BaseRemoteMethodMetadata = BaseRemoteMethodMetadata>(\n remoteMethodIdOrInstanceOrToken: IdOrInstanceOrToken<BaseRemoteMethod<ReturnType, Parameters, Metadata>>,\n parameters: Parameters,\n metadata?: Partial<BaseRemoteMethodMetadata>,\n injector?: Injector,\n notFoundValue?: BaseRemoteMethod<ReturnType, Parameters, Metadata>,\n flags?: InjectOptions,\n ) {\n\n const remoteMethod = this.remoteMethodLoader.load(\n remoteMethodIdOrInstanceOrToken,\n metadata,\n injector,\n notFoundValue,\n flags,\n );\n\n if (!(remoteMethod instanceof HttpRemoteMethod)) {\n throw new RxapRemoteMethodError(`The remote method is not a HttpRemoteMethod`, '', 'HttpRemoteMethodLoader');\n }\n\n return remoteMethod.call(parameters);\n }\n\n}\n","// region \nexport * from './lib/base-http.remote-method';\nexport * from './lib/http-remote-method.loader';\nexport * from './lib/http.remote-method';\n// endregion\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAoDM,MAAgB,oBAIpB,SAAQ,gBAAi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AAA,CAAA,kBAAkB,GAAG,MAAM,CAAqB,kBAAkB,CAAC;AA2BrF,IAAA;IAxBQ,QAAQ,CACb,+BAAwG,EACxG,UAAsB,EACtB,QAA4C,EAC5C,QAAmB,EACnB,aAAkE,EAClE,KAAqB,EAAA;AAGrB,QAAA,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAC/C,+BAA+B,EAC/B,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,KAAK,CACN;AAED,QAAA,IAAI,EAAE,YAAY,YAAY,gBAAgB,CAAC,EAAE;YAC/C,MAAM,IAAI,qBAAqB,CAAC,CAAA,2CAAA,CAA6C,EAAE,EAAE,EAAE,wBAAwB,CAAC;QAC9G;AAEA,QAAA,OAAO,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;IACtC;8GA1BW,sBAAsB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAtB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,sBAAsB,cADT,MAAM,EAAA,CAAA,CAAA;;2FACnB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBADlC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACVlC;AAIA;;ACJA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"rxap-remote-method-http.mjs","names":[],"sources":["../../../../../packages/angular/remote-method/http/src/lib/base-http.remote-method.ts","../../../../../packages/angular/remote-method/http/src/lib/http.remote-method.ts","../../../../../packages/angular/remote-method/http/src/lib/http-remote-method.loader.ts"],"sourcesContent":["import {\n Inject,\n Injectable,\n Injector,\n Optional,\n} from '@angular/core';\nimport {\n HttpClient,\n HttpContext,\n HttpHeaders,\n HttpParams,\n HttpRequest,\n} from '@angular/common/http';\nimport {\n BaseRemoteMethod,\n BaseRemoteMethodMetadata,\n REMOTE_METHOD_META_DATA,\n RxapRemoteMethodError,\n} from '@rxap/remote-method';\nimport { hasIndexSignature } from '@rxap/utilities';\n\nexport interface HttpRemoteMethodMetadata extends BaseRemoteMethodMetadata {\n url: string | (() => string);\n method: 'DELETE' | 'GET' | 'HEAD' | 'JSONP' | 'OPTIONS' | 'POST' | 'PUT' | 'PATCH';\n headers?: HttpHeaders;\n reportProgress?: boolean;\n params?: HttpParams;\n responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';\n withCredentials?: boolean;\n timeout?: number;\n retry?: number;\n context?: HttpContext;\n}\n\nexport interface HttpRemoteMethodParameter<PathParams = any> {\n headers?: HttpHeaders;\n reportProgress?: boolean;\n params?: HttpParams;\n responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';\n withCredentials?: boolean;\n body?: any | null;\n setHeaders?: {\n [name: string]: string | string[];\n };\n setParams?: {\n [param: string]: string;\n };\n pathParams?: PathParams;\n context?: HttpContext;\n}\n\n@Injectable()\nexport abstract class BaseHttpRemoteMethod<ReturnType = any,\n PathParams = any,\n Parameter extends object = HttpRemoteMethodParameter<PathParams>,\n MetaData extends HttpRemoteMethodMetadata = HttpRemoteMethodMetadata>\n extends BaseRemoteMethod<ReturnType, Parameter, MetaData> {\n\n public timeout = 60 * 1000;\n protected _httpRequest!: HttpRequest<ReturnType>;\n\n constructor(\n @Inject(HttpClient) public readonly http: HttpClient,\n @Inject(Injector) injector: Injector,\n @Optional() @Inject(REMOTE_METHOD_META_DATA) metaData: any | null = null,\n ) {\n super(injector, metaData);\n this.timeout = this.metadata.timeout ?? this.timeout;\n if (http === undefined) {\n throw new RxapRemoteMethodError(\n 'HttpClient is undefined. Ensure that the HttpClient is added to the deps property!',\n '',\n this.constructor.name,\n );\n }\n if (!(http instanceof HttpClient)) {\n throw new RxapRemoteMethodError(\n 'The property http is not an instance of HttpClinent. Check the deps property!',\n '',\n this.constructor.name,\n );\n }\n }\n\n public override init() {\n super.init();\n this._httpRequest = new HttpRequest<ReturnType>(\n this.metadata.method,\n this.getRequestUrl(),\n null,\n {\n headers: this.metadata.headers,\n reportProgress: this.metadata.reportProgress,\n params: this.metadata.params,\n responseType: this.metadata.responseType || 'json',\n withCredentials: this.metadata.withCredentials,\n },\n );\n }\n\n public updateRequest(parameters: Partial<HttpRemoteMethodParameter>): HttpRequest<ReturnType> {\n let url = this._httpRequest.url;\n\n if (parameters && parameters['pathParams']) {\n url = this.buildUrlWithParams(url, (parameters as any).pathParams);\n }\n\n return this._httpRequest.clone({\n withCredentials: this.metadata.withCredentials,\n context: this.metadata.context,\n ...parameters,\n url,\n });\n }\n\n public buildUrlWithParams(url: string, pathParams?: PathParams): string {\n if (pathParams) {\n\n if (!hasIndexSignature(pathParams)) {\n throw new RxapRemoteMethodError(\n `Path params for remote method '${ this.id }' has not an index signature`,\n '',\n this.constructor.name,\n );\n }\n\n const matches = url.match(/\\{[^}]+\\}/g);\n\n if (matches) {\n for (const match of matches) {\n const param = match.substr(1, match.length - 2);\n if (pathParams[param] === undefined) {\n throw new RxapRemoteMethodError(\n `Path params for remote method '${ this.id }' has not a defined value for '${ param }'`,\n '',\n this.constructor.name,\n );\n }\n url = url.replace(match, encodeURIComponent(pathParams[param]));\n }\n }\n }\n\n return url;\n }\n\n protected getRequestUrl(): string {\n if (typeof this.metadata.url === 'function') {\n return this.metadata.url();\n }\n return this.metadata.url;\n }\n\n}\n","import { Injectable } from '@angular/core';\nimport { HttpEventType, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpSentEvent } from '@angular/common/http';\nimport {\n filter,\n map,\n retry,\n tap,\n timeout,\n} from 'rxjs/operators';\nimport {\n BaseHttpRemoteMethod,\n HttpRemoteMethodMetadata,\n HttpRemoteMethodParameter,\n} from './base-http.remote-method';\nimport { firstValueFrom } from 'rxjs';\n\n@Injectable()\nexport class HttpRemoteMethod<ReturnType = any,\n PathParams = any,\n Parameter extends object = HttpRemoteMethodParameter<PathParams>,\n MetaData extends HttpRemoteMethodMetadata = HttpRemoteMethodMetadata>\n extends BaseHttpRemoteMethod<ReturnType, PathParams, Parameter, MetaData> {\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onSentEvent(event: HttpSentEvent): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onHeaderResponse(event: HttpHeaderResponse): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onResponse(event: HttpResponse<ReturnType>): void {\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public onProgressEvent(event: HttpProgressEvent): void {\n }\n\n // TODO : make abstract to force implementation to handel parameter transformation\n public createHttpRequestParameters(parameters?: Parameter): Partial<HttpRemoteMethodParameter> {\n return parameters ?? {} as any;\n }\n\n public transformer(response: any): ReturnType {\n return response;\n }\n\n protected _call(parameters?: Parameter): Promise<ReturnType> {\n return firstValueFrom(this.http.request<ReturnType>(this.updateRequest(this.createHttpRequestParameters(parameters)))\n .pipe(\n retry(this.metadata.retry ?? 0),\n tap(event => {\n switch (event.type) {\n\n case HttpEventType.Sent:\n this.onSentEvent(event);\n break;\n\n case HttpEventType.Response:\n this.onResponse(event);\n break;\n\n case HttpEventType.DownloadProgress:\n this.onProgressEvent(event);\n break;\n\n case HttpEventType.UploadProgress:\n this.onProgressEvent(event);\n break;\n\n case HttpEventType.ResponseHeader:\n this.onHeaderResponse(event);\n break;\n\n }\n }),\n filter((event: any) => event instanceof HttpResponse),\n map((event: HttpResponse<ReturnType>) => event.body),\n map(body => this.transformer(body)),\n timeout(this.timeout),\n ));\n }\n\n}\n","import {\n BaseRemoteMethod,\n BaseRemoteMethodMetadata,\n RemoteMethodLoader,\n RxapRemoteMethodError,\n} from '@rxap/remote-method';\nimport { HttpRemoteMethod } from './http.remote-method';\nimport { Injectable, InjectOptions, Injector, inject } from '@angular/core';\nimport { IdOrInstanceOrToken } from '@rxap/definition';\n\n@Injectable({ providedIn: 'root' })\nexport class HttpRemoteMethodLoader {\n private readonly remoteMethodLoader = inject<RemoteMethodLoader>(RemoteMethodLoader);\n\n\n public request$<ReturnType = any, Parameters = any, Metadata extends BaseRemoteMethodMetadata = BaseRemoteMethodMetadata>(\n remoteMethodIdOrInstanceOrToken: IdOrInstanceOrToken<BaseRemoteMethod<ReturnType, Parameters, Metadata>>,\n parameters: Parameters,\n metadata?: Partial<BaseRemoteMethodMetadata>,\n injector?: Injector,\n notFoundValue?: BaseRemoteMethod<ReturnType, Parameters, Metadata>,\n flags?: InjectOptions,\n ) {\n\n const remoteMethod = this.remoteMethodLoader.load(\n remoteMethodIdOrInstanceOrToken,\n metadata,\n injector,\n notFoundValue,\n flags,\n );\n\n if (!(remoteMethod instanceof HttpRemoteMethod)) {\n throw new RxapRemoteMethodError(`The remote method is not a HttpRemoteMethod`, '', 'HttpRemoteMethodLoader');\n }\n\n return remoteMethod.call(parameters);\n }\n\n}\n"],"mappings":";;;;;;;;AAoDA,IAAsB,uBAAtB,MAAsB,6BAIZ,iBAAiD;CAKzD,YACsC,MAClB,UAC2B,WAAuB,MAAI;EAExE,MAAM,UAAU,QAAQ;EAJY,KAAA,OAAA;EAJ/B,KAAA,UAAU;EASf,KAAK,UAAU,KAAK,SAAS,WAAW,KAAK;EAC7C,IAAI,SAAS,QACX,MAAM,IAAI,sBACR,sFACA,IACA,KAAK,YAAY,IAAI;EAGzB,IAAI,EAAE,gBAAgB,aACpB,MAAM,IAAI,sBACR,iFACA,IACA,KAAK,YAAY,IAAI;CAG3B;CAEgB,OAAI;EAClB,MAAM,KAAI;EACV,KAAK,eAAe,IAAI,YACtB,KAAK,SAAS,QACd,KAAK,cAAa,GAClB,MACA;GACE,SAAS,KAAK,SAAS;GACvB,gBAAgB,KAAK,SAAS;GAC9B,QAAQ,KAAK,SAAS;GACtB,cAAc,KAAK,SAAS,gBAAgB;GAC5C,iBAAiB,KAAK,SAAS;EAChC,CAAA;CAEL;CAEO,cAAc,YAA8C;EACjE,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26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (typeof remoteMethodOrIdOrToken === 'string') {
|
|
35
|
-
if (this.hasMock(remoteMethodOrIdOrToken)) {
|
|
36
|
-
const resultFunction = this.getMock(remoteMethodOrIdOrToken);
|
|
37
|
-
return await resultFunction(parameters, metadata);
|
|
38
|
-
}
|
|
39
|
-
return super.call$(remoteMethodOrIdOrToken, parameters, metadata);
|
|
40
|
-
}
|
|
41
|
-
return super.call$(remoteMethodOrIdOrToken, parameters, metadata);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
import { RemoteMethodLoader } from "@rxap/remote-method";
|
|
2
|
+
var RemoteMethodTestingLoader = class extends RemoteMethodLoader {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.mockedRemoteMethods = /* @__PURE__ */ new Map();
|
|
6
|
+
}
|
|
7
|
+
mock(remoteMethodId, resultOrFunction) {
|
|
8
|
+
let resultFunction;
|
|
9
|
+
if (typeof resultOrFunction !== "function") resultFunction = () => resultOrFunction;
|
|
10
|
+
else resultFunction = resultOrFunction;
|
|
11
|
+
this.mockedRemoteMethods.set(remoteMethodId, resultFunction);
|
|
12
|
+
}
|
|
13
|
+
clearMocks() {
|
|
14
|
+
this.mockedRemoteMethods.clear();
|
|
15
|
+
}
|
|
16
|
+
deleteMock(remoteMethodId) {
|
|
17
|
+
return this.mockedRemoteMethods.delete(remoteMethodId);
|
|
18
|
+
}
|
|
19
|
+
hasMock(remoteMethodId) {
|
|
20
|
+
return this.mockedRemoteMethods.has(remoteMethodId);
|
|
21
|
+
}
|
|
22
|
+
getMock(remoteMethodId) {
|
|
23
|
+
if (!this.hasMock(remoteMethodId)) throw new Error(`A remote method mock with the id '${remoteMethodId}' is not registered`);
|
|
24
|
+
return this.mockedRemoteMethods.get(remoteMethodId);
|
|
25
|
+
}
|
|
26
|
+
async call$(remoteMethodOrIdOrToken, parameters, metadata) {
|
|
27
|
+
if (typeof remoteMethodOrIdOrToken === "string") {
|
|
28
|
+
if (this.hasMock(remoteMethodOrIdOrToken)) return await this.getMock(remoteMethodOrIdOrToken)(parameters, metadata);
|
|
29
|
+
return super.call$(remoteMethodOrIdOrToken, parameters, metadata);
|
|
30
|
+
}
|
|
31
|
+
return super.call$(remoteMethodOrIdOrToken, parameters, metadata);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
44
34
|
const REMOTE_METHOD_TESTING_LOADER_PROVIDER = {
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
provide: RemoteMethodLoader,
|
|
36
|
+
useClass: RemoteMethodTestingLoader
|
|
47
37
|
};
|
|
48
|
-
|
|
49
|
-
// region
|
|
50
|
-
// endregion
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Generated bundle index. Do not edit.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
38
|
export { REMOTE_METHOD_TESTING_LOADER_PROVIDER, RemoteMethodTestingLoader };
|
|
57
|
-
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=rxap-remote-method-testing.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rxap-remote-method-testing.mjs","sources":["../../../../../packages/angular/remote-method/testing/src/lib/remote-method-testing-loader.ts"
|
|
1
|
+
{"version":3,"file":"rxap-remote-method-testing.mjs","names":[],"sources":["../../../../../packages/angular/remote-method/testing/src/lib/remote-method-testing-loader.ts"],"sourcesContent":["import {\n BaseRemoteMethod,\n BaseRemoteMethodMetadata,\n RemoteMethodLoader,\n} from '@rxap/remote-method';\nimport {\n AbstractType,\n InjectionToken,\n Provider,\n Type,\n} from '@angular/core';\n\nexport type MockRemoteMethod = (parameters?: any, metadata?: any) => any;\n\nexport class RemoteMethodTestingLoader extends RemoteMethodLoader {\n\n private mockedRemoteMethods = new Map<string, MockRemoteMethod>();\n\n public mock(remoteMethodId: string, resultOrFunction: any | MockRemoteMethod): void {\n let resultFunction: MockRemoteMethod;\n if (typeof resultOrFunction !== 'function') {\n resultFunction = () => resultOrFunction;\n } else {\n resultFunction = resultOrFunction;\n }\n this.mockedRemoteMethods.set(remoteMethodId, resultFunction);\n }\n\n public clearMocks(): void {\n this.mockedRemoteMethods.clear();\n }\n\n public deleteMock(remoteMethodId: string): boolean {\n return this.mockedRemoteMethods.delete(remoteMethodId);\n }\n\n public hasMock(remoteMethodId: string): boolean {\n return this.mockedRemoteMethods.has(remoteMethodId);\n }\n\n public getMock(remoteMethodId: string): MockRemoteMethod {\n if (!this.hasMock(remoteMethodId)) {\n throw new Error(`A remote method mock with the id '${ remoteMethodId }' is not registered`);\n }\n return this.mockedRemoteMethods.get(remoteMethodId)!;\n }\n\n public override async call$<ReturnType = any, Parameters = any, Metadata extends BaseRemoteMethodMetadata = BaseRemoteMethodMetadata>(\n remoteMethodOrIdOrToken: string | BaseRemoteMethod<ReturnType, Parameters, Metadata> | Type<BaseRemoteMethod<ReturnType, Parameters, Metadata>> | InjectionToken<BaseRemoteMethod<ReturnType, Parameters, Metadata>> | AbstractType<BaseRemoteMethod<ReturnType, Parameters, Metadata>>,\n parameters?: Parameters,\n metadata?: Metadata,\n ): Promise<ReturnType> {\n\n if (typeof remoteMethodOrIdOrToken === 'string') {\n\n if (this.hasMock(remoteMethodOrIdOrToken)) {\n const resultFunction = this.getMock(remoteMethodOrIdOrToken)!;\n return await resultFunction(parameters, metadata);\n }\n return super.call$(remoteMethodOrIdOrToken, parameters, metadata);\n\n }\n\n return super.call$(remoteMethodOrIdOrToken, parameters, metadata);\n }\n\n}\n\nexport const REMOTE_METHOD_TESTING_LOADER_PROVIDER: Provider = {\n provide: RemoteMethodLoader,\n useClass: RemoteMethodTestingLoader,\n};\n"],"mappings":";AAcA,IAAa,4BAAb,cAA+C,mBAAkB;CAAjE,cAAA;;EAEU,KAAA,sCAAsB,IAAI,IAAG;CAkDvC;CAhDS,KAAK,gBAAwB,kBAAwC;EAC1E,IAAI;EACJ,IAAI,OAAO,qBAAqB,YAC9B,uBAAuB;OAEvB,iBAAiB;EAEnB,KAAK,oBAAoB,IAAI,gBAAgB,cAAc;CAC7D;CAEO,aAAU;EACf,KAAK,oBAAoB,MAAK;CAChC;CAEO,WAAW,gBAAsB;EACtC,OAAO,KAAK,oBAAoB,OAAO,cAAc;CACvD;CAEO,QAAQ,gBAAsB;EACnC,OAAO,KAAK,oBAAoB,IAAI,cAAc;CACpD;CAEO,QAAQ,gBAAsB;EACnC,IAAI,CAAC,KAAK,QAAQ,cAAc,GAC9B,MAAM,IAAI,MAAM,qCAAsC,eAAe,oBAAqB;EAE5F,OAAO,KAAK,oBAAoB,IAAI,cAAc;CACpD;CAEgB,MAAM,MACpB,yBACA,YACA,UAAmB;EAGnB,IAAI,OAAO,4BAA4B,UAAU;GAE/C,IAAI,KAAK,QAAQ,uBAAuB,GAEtC,OAAO,MADgB,KAAK,QAAQ,uBACvB,CAAA,CAAe,YAAY,QAAQ;GAElD,OAAO,MAAM,MAAM,yBAAyB,YAAY,QAAQ;EAElE;EAEA,OAAO,MAAM,MAAM,yBAAyB,YAAY,QAAQ;CAClE;AAED;AAED,MAAa,wCAAkD;CAC7D,SAAS;CACT,UAAU;AACX"}
|