breeze-client 2.2.2 → 3.0.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/LICENSE +1 -1
- package/README.md +83 -63
- package/adapters/abstract-data-service-adapter.d.ts +120 -0
- package/adapters/abstract-data-service-adapter.js +395 -0
- package/adapters/abstract-data-service-adapter.js.map +1 -0
- package/adapters/adapter-ajax-fetch.d.ts +12 -0
- package/adapters/adapter-ajax-fetch.js +13 -0
- package/adapters/adapter-ajax-fetch.js.map +1 -0
- package/{adapter-ajax-post → adapters}/adapter-ajax-post.d.ts +40 -36
- package/{fesm2022/breeze-client-adapter-ajax-post.mjs → adapters/adapter-ajax-post.js} +80 -82
- package/adapters/adapter-ajax-post.js.map +1 -0
- package/{adapter-ajax-fetch → adapters}/adapter-core.d.ts +4 -4
- package/{fesm2022/breeze-client-adapter-uri-builder-json.mjs → adapters/adapter-core.js} +48 -91
- package/adapters/adapter-core.js.map +1 -0
- package/adapters/adapter-data-service-webapi.d.ts +9 -0
- package/{fesm2022/breeze-client-adapter-data-service-webapi.mjs → adapters/adapter-data-service-webapi.js} +105 -107
- package/adapters/adapter-data-service-webapi.js.map +1 -0
- package/adapters/adapter-model-library-backing-store.d.ts +32 -0
- package/adapters/adapter-model-library-backing-store.js +321 -0
- package/adapters/adapter-model-library-backing-store.js.map +1 -0
- package/adapters/adapter-uri-builder-json.d.ts +11 -0
- package/adapters/adapter-uri-builder-json.js +40 -0
- package/adapters/adapter-uri-builder-json.js.map +1 -0
- package/adapters/http.d.ts +52 -0
- package/adapters/http.js +202 -0
- package/adapters/http.js.map +1 -0
- package/angular/adapter-angular-httpclient.d.ts +21 -0
- package/angular/adapter-angular-httpclient.js +70 -0
- package/angular/adapter-angular-httpclient.js.map +1 -0
- package/breeze.d.ts +215 -0
- package/breeze.js +141 -0
- package/breeze.js.map +1 -0
- package/config/config.d.ts +212 -0
- package/config/config.js +392 -0
- package/config/config.js.map +1 -0
- package/config/configure.d.ts +66 -0
- package/config/configure.js +46 -0
- package/config/configure.js.map +1 -0
- package/config/default-adapters.d.ts +1 -0
- package/config/default-adapters.js +40 -0
- package/config/default-adapters.js.map +1 -0
- package/config/interface-registry.d.ts +191 -0
- package/config/interface-registry.js +5 -0
- package/config/interface-registry.js.map +1 -0
- package/{src → core}/assert-param.d.ts +52 -60
- package/core/assert-param.js +390 -0
- package/core/assert-param.js.map +1 -0
- package/core/core.d.ts +285 -0
- package/core/core.js +772 -0
- package/core/core.js.map +1 -0
- package/core/enum.d.ts +116 -0
- package/core/enum.js +167 -0
- package/core/enum.js.map +1 -0
- package/core/event.d.ts +169 -0
- package/core/event.js +338 -0
- package/core/event.js.map +1 -0
- package/entity/array.d.ts +3 -0
- package/entity/array.js +4 -0
- package/entity/array.js.map +1 -0
- package/entity/complex-array.d.ts +17 -0
- package/entity/complex-array.js +104 -0
- package/entity/complex-array.js.map +1 -0
- package/entity/default-property-interceptor.d.ts +1 -0
- package/entity/default-property-interceptor.js +496 -0
- package/entity/default-property-interceptor.js.map +1 -0
- package/{src → entity}/entity-action.d.ts +36 -42
- package/entity/entity-action.js +45 -0
- package/entity/entity-action.js.map +1 -0
- package/entity/entity-aspect.d.ts +457 -0
- package/entity/entity-aspect.js +1262 -0
- package/entity/entity-aspect.js.map +1 -0
- package/entity/entity-base.d.ts +55 -0
- package/entity/entity-base.js +41 -0
- package/entity/entity-base.js.map +1 -0
- package/entity/entity-group.d.ts +1 -0
- package/entity/entity-group.js +224 -0
- package/entity/entity-group.js.map +1 -0
- package/entity/entity-key.d.ts +95 -0
- package/entity/entity-key.js +189 -0
- package/entity/entity-key.js.map +1 -0
- package/{src → entity}/entity-state.d.ts +112 -84
- package/entity/entity-state.js +135 -0
- package/entity/entity-state.js.map +1 -0
- package/entity/key-generator.d.ts +57 -0
- package/entity/key-generator.js +155 -0
- package/entity/key-generator.js.map +1 -0
- package/entity/observable-array.d.ts +25 -0
- package/entity/observable-array.js +230 -0
- package/entity/observable-array.js.map +1 -0
- package/entity/primitive-array.d.ts +12 -0
- package/entity/primitive-array.js +71 -0
- package/entity/primitive-array.js.map +1 -0
- package/entity/relation-array.d.ts +24 -0
- package/entity/relation-array.js +176 -0
- package/entity/relation-array.js.map +1 -0
- package/entity/unattached-children-map.d.ts +1 -0
- package/entity/unattached-children-map.js +105 -0
- package/entity/unattached-children-map.js.map +1 -0
- package/generate-entity-classes.js +1176 -0
- package/manager/entity-manager.d.ts +801 -0
- package/manager/entity-manager.js +2395 -0
- package/manager/entity-manager.js.map +1 -0
- package/{src → manager}/save-options.d.ts +48 -42
- package/manager/save-options.js +51 -0
- package/manager/save-options.js.map +1 -0
- package/{src → metadata}/data-service.d.ts +229 -184
- package/metadata/data-service.js +246 -0
- package/metadata/data-service.js.map +1 -0
- package/metadata/data-type.d.ts +122 -0
- package/metadata/data-type.js +465 -0
- package/metadata/data-type.js.map +1 -0
- package/metadata/entity-metadata.d.ts +1193 -0
- package/metadata/entity-metadata.js +2502 -0
- package/metadata/entity-metadata.js.map +1 -0
- package/{src → metadata}/local-query-comparison-options.d.ts +65 -59
- package/metadata/local-query-comparison-options.js +69 -0
- package/metadata/local-query-comparison-options.js.map +1 -0
- package/{src → metadata}/naming-convention.d.ts +75 -72
- package/metadata/naming-convention.js +97 -0
- package/metadata/naming-convention.js.map +1 -0
- package/mixins/mixin-get-entity-graph.d.ts +63 -0
- package/{fesm2022/breeze-client-mixin-get-entity-graph.mjs → mixins/mixin-get-entity-graph.js} +331 -253
- package/mixins/mixin-get-entity-graph.js.map +1 -0
- package/mixins/mixin-save-queuing.d.ts +98 -0
- package/{fesm2022/breeze-client-mixin-save-queuing.mjs → mixins/mixin-save-queuing.js} +493 -365
- package/mixins/mixin-save-queuing.js.map +1 -0
- package/package.json +63 -94
- package/query/entity-query.d.ts +521 -0
- package/query/entity-query.js +1149 -0
- package/query/entity-query.js.map +1 -0
- package/{src → query}/mapping-context.d.ts +44 -46
- package/query/mapping-context.js +412 -0
- package/query/mapping-context.js.map +1 -0
- package/query/predicate.d.ts +394 -0
- package/query/predicate.js +1294 -0
- package/query/predicate.js.map +1 -0
- package/query/property-path.d.ts +252 -0
- package/query/property-path.js +2 -0
- package/query/property-path.js.map +1 -0
- package/{src → query}/query-options.d.ts +143 -119
- package/query/query-options.js +180 -0
- package/query/query-options.js.map +1 -0
- package/rxjs/breeze-rxjs.d.ts +72 -0
- package/rxjs/breeze-rxjs.js +117 -0
- package/rxjs/breeze-rxjs.js.map +1 -0
- package/validation/validate.d.ts +583 -0
- package/validation/validate.js +961 -0
- package/validation/validate.js.map +1 -0
- package/{src → validation}/validation-options.d.ts +67 -63
- package/validation/validation-options.js +70 -0
- package/validation/validation-options.js.map +1 -0
- package/adapter-ajax-angularjs/adapter-ajax-angularjs.d.ts +0 -17
- package/adapter-ajax-angularjs/adapter-core.d.ts +0 -4
- package/adapter-ajax-angularjs/index.d.ts +0 -5
- package/adapter-ajax-fetch/adapter-ajax-fetch.d.ts +0 -18
- package/adapter-ajax-fetch/index.d.ts +0 -5
- package/adapter-ajax-httpclient/adapter-ajax-httpclient.d.ts +0 -13
- package/adapter-ajax-httpclient/adapter-core.d.ts +0 -4
- package/adapter-ajax-httpclient/index.d.ts +0 -5
- package/adapter-ajax-jquery/adapter-ajax-jquery.d.ts +0 -15
- package/adapter-ajax-jquery/index.d.ts +0 -5
- package/adapter-ajax-post/index.d.ts +0 -5
- package/adapter-data-service-odata/adapter-core.d.ts +0 -4
- package/adapter-data-service-odata/adapter-data-service-odata.d.ts +0 -17
- package/adapter-data-service-odata/index.d.ts +0 -5
- package/adapter-data-service-webapi/adapter-data-service-webapi.d.ts +0 -15
- package/adapter-data-service-webapi/index.d.ts +0 -5
- package/adapter-model-library-backing-store/adapter-model-library-backing-store.d.ts +0 -10
- package/adapter-model-library-backing-store/index.d.ts +0 -5
- package/adapter-model-library-ko/adapter-model-library-ko.d.ts +0 -10
- package/adapter-model-library-ko/index.d.ts +0 -5
- package/adapter-uri-builder-json/adapter-core.d.ts +0 -4
- package/adapter-uri-builder-json/adapter-uri-builder-json.d.ts +0 -8
- package/adapter-uri-builder-json/index.d.ts +0 -5
- package/adapter-uri-builder-odata/adapter-core.d.ts +0 -4
- package/adapter-uri-builder-odata/adapter-uri-builder-odata.d.ts +0 -8
- package/adapter-uri-builder-odata/index.d.ts +0 -5
- package/esm2022/adapter-ajax-angularjs/adapter-ajax-angularjs.mjs +0 -135
- package/esm2022/adapter-ajax-angularjs/adapter-core.mjs +0 -49
- package/esm2022/adapter-ajax-angularjs/breeze-client-adapter-ajax-angularjs.mjs +0 -5
- package/esm2022/adapter-ajax-fetch/adapter-ajax-fetch.mjs +0 -135
- package/esm2022/adapter-ajax-fetch/adapter-core.mjs +0 -49
- package/esm2022/adapter-ajax-fetch/breeze-client-adapter-ajax-fetch.mjs +0 -5
- package/esm2022/adapter-ajax-httpclient/adapter-ajax-httpclient.mjs +0 -139
- package/esm2022/adapter-ajax-httpclient/adapter-core.mjs +0 -49
- package/esm2022/adapter-ajax-httpclient/breeze-client-adapter-ajax-httpclient.mjs +0 -5
- package/esm2022/adapter-ajax-jquery/adapter-ajax-jquery.mjs +0 -107
- package/esm2022/adapter-ajax-jquery/breeze-client-adapter-ajax-jquery.mjs +0 -5
- package/esm2022/adapter-ajax-post/adapter-ajax-post.mjs +0 -77
- package/esm2022/adapter-ajax-post/breeze-client-adapter-ajax-post.mjs +0 -5
- package/esm2022/adapter-data-service-odata/adapter-core.mjs +0 -49
- package/esm2022/adapter-data-service-odata/adapter-data-service-odata.mjs +0 -461
- package/esm2022/adapter-data-service-odata/breeze-client-adapter-data-service-odata.mjs +0 -5
- package/esm2022/adapter-data-service-webapi/adapter-data-service-webapi.mjs +0 -100
- package/esm2022/adapter-data-service-webapi/breeze-client-adapter-data-service-webapi.mjs +0 -5
- package/esm2022/adapter-model-library-backing-store/adapter-model-library-backing-store.mjs +0 -269
- package/esm2022/adapter-model-library-backing-store/breeze-client-adapter-model-library-backing-store.mjs +0 -5
- package/esm2022/adapter-model-library-ko/adapter-model-library-ko.mjs +0 -241
- package/esm2022/adapter-model-library-ko/breeze-client-adapter-model-library-ko.mjs +0 -5
- package/esm2022/adapter-uri-builder-json/adapter-core.mjs +0 -49
- package/esm2022/adapter-uri-builder-json/adapter-uri-builder-json.mjs +0 -37
- package/esm2022/adapter-uri-builder-json/breeze-client-adapter-uri-builder-json.mjs +0 -5
- package/esm2022/adapter-uri-builder-odata/adapter-core.mjs +0 -49
- package/esm2022/adapter-uri-builder-odata/adapter-uri-builder-odata.mjs +0 -191
- package/esm2022/adapter-uri-builder-odata/breeze-client-adapter-uri-builder-odata.mjs +0 -5
- package/esm2022/breeze-client.mjs +0 -5
- package/esm2022/index.mjs +0 -2
- package/esm2022/mixin-get-entity-graph/breeze-client-mixin-get-entity-graph.mjs +0 -5
- package/esm2022/mixin-get-entity-graph/mixin-get-entity-graph.mjs +0 -269
- package/esm2022/mixin-save-queuing/breeze-client-mixin-save-queuing.mjs +0 -5
- package/esm2022/mixin-save-queuing/mixin-save-queuing.mjs +0 -421
- package/esm2022/src/abstract-data-service-adapter.mjs +0 -325
- package/esm2022/src/array.mjs +0 -4
- package/esm2022/src/assert-param.mjs +0 -330
- package/esm2022/src/breeze.mjs +0 -85
- package/esm2022/src/complex-array.mjs +0 -117
- package/esm2022/src/config.mjs +0 -232
- package/esm2022/src/core.mjs +0 -712
- package/esm2022/src/csdl-metadata-parser.mjs +0 -385
- package/esm2022/src/data-service.mjs +0 -221
- package/esm2022/src/data-type.mjs +0 -510
- package/esm2022/src/default-property-interceptor.mjs +0 -460
- package/esm2022/src/entity-action.mjs +0 -45
- package/esm2022/src/entity-aspect.mjs +0 -897
- package/esm2022/src/entity-group.mjs +0 -192
- package/esm2022/src/entity-key.mjs +0 -125
- package/esm2022/src/entity-manager.mjs +0 -2163
- package/esm2022/src/entity-metadata.mjs +0 -2242
- package/esm2022/src/entity-query.mjs +0 -1024
- package/esm2022/src/entity-state.mjs +0 -107
- package/esm2022/src/enum.mjs +0 -143
- package/esm2022/src/event.mjs +0 -264
- package/esm2022/src/interface-registry.mjs +0 -39
- package/esm2022/src/key-generator.mjs +0 -110
- package/esm2022/src/local-query-comparison-options.mjs +0 -65
- package/esm2022/src/mapping-context.mjs +0 -411
- package/esm2022/src/naming-convention.mjs +0 -92
- package/esm2022/src/observable-array.mjs +0 -183
- package/esm2022/src/predicate.mjs +0 -1259
- package/esm2022/src/primitive-array.mjs +0 -85
- package/esm2022/src/query-options.mjs +0 -152
- package/esm2022/src/relation-array.mjs +0 -173
- package/esm2022/src/save-options.mjs +0 -41
- package/esm2022/src/unattached-children-map.mjs +0 -56
- package/esm2022/src/validate.mjs +0 -995
- package/esm2022/src/validation-options.mjs +0 -64
- package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs +0 -190
- package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-fetch.mjs +0 -190
- package/fesm2022/breeze-client-adapter-ajax-fetch.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs +0 -194
- package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-jquery.mjs +0 -114
- package/fesm2022/breeze-client-adapter-ajax-jquery.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-post.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-data-service-odata.mjs +0 -516
- package/fesm2022/breeze-client-adapter-data-service-odata.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-data-service-webapi.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs +0 -276
- package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-model-library-ko.mjs +0 -248
- package/fesm2022/breeze-client-adapter-model-library-ko.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-uri-builder-json.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs +0 -246
- package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs.map +0 -1
- package/fesm2022/breeze-client-mixin-get-entity-graph.mjs.map +0 -1
- package/fesm2022/breeze-client-mixin-save-queuing.mjs.map +0 -1
- package/fesm2022/breeze-client.mjs +0 -14144
- package/fesm2022/breeze-client.mjs.map +0 -1
- package/index.d.ts +0 -1
- package/mixin-get-entity-graph/index.d.ts +0 -5
- package/mixin-get-entity-graph/mixin-get-entity-graph.d.ts +0 -31
- package/mixin-save-queuing/index.d.ts +0 -5
- package/mixin-save-queuing/mixin-save-queuing.d.ts +0 -32
- package/src/abstract-data-service-adapter.d.ts +0 -84
- package/src/array.d.ts +0 -3
- package/src/breeze.d.ts +0 -139
- package/src/complex-array.d.ts +0 -13
- package/src/config.d.ts +0 -104
- package/src/core.d.ts +0 -164
- package/src/csdl-metadata-parser.d.ts +0 -7
- package/src/data-type.d.ts +0 -89
- package/src/default-property-interceptor.d.ts +0 -4
- package/src/entity-aspect.d.ts +0 -332
- package/src/entity-group.d.ts +0 -28
- package/src/entity-key.d.ts +0 -77
- package/src/entity-manager.d.ts +0 -680
- package/src/entity-metadata.d.ts +0 -988
- package/src/entity-query.d.ts +0 -444
- package/src/enum.d.ts +0 -100
- package/src/event.d.ts +0 -142
- package/src/interface-registry.d.ts +0 -150
- package/src/key-generator.d.ts +0 -12
- package/src/observable-array.d.ts +0 -52
- package/src/predicate.d.ts +0 -376
- package/src/primitive-array.d.ts +0 -7
- package/src/relation-array.d.ts +0 -18
- package/src/unattached-children-map.d.ts +0 -19
- package/src/validate.d.ts +0 -650
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { core } from '../core/core.js';
|
|
2
|
+
import { config } from '../config/config.js';
|
|
3
|
+
import { builtinAjax } from './http.js';
|
|
4
|
+
import { JsonResultsAdapter } from '../metadata/data-service.js';
|
|
5
|
+
import { EntityType, MetadataStore } from '../metadata/entity-metadata.js';
|
|
6
|
+
/** For use by breeze plugin authors only. The class is used as the base class for most {@link DataServiceAdapter} implementations
|
|
7
|
+
@adapter (see {@link DataServiceAdapter})
|
|
8
|
+
@hidden
|
|
9
|
+
*/
|
|
10
|
+
export class AbstractDataServiceAdapter {
|
|
11
|
+
// TODO use interface
|
|
12
|
+
checkForRecomposition(interfaceInitializedArgs) {
|
|
13
|
+
if (interfaceInitializedArgs.interfaceName === "ajax" && interfaceInitializedArgs.isDefault) {
|
|
14
|
+
this.initialize();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
initialize() {
|
|
18
|
+
// An ajax adapter is optional. A registered one (deprecated) is used if there is one;
|
|
19
|
+
// otherwise requests go through config.fetch, which defaults to globalThis.fetch. This
|
|
20
|
+
// is also why registration order no longer matters: there is nothing to resolve.
|
|
21
|
+
this.ajaxImpl = config.getAdapterInstance("ajax") || builtinAjax;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sends one request. Resolves with the response, or rejects with a `ServerError`.
|
|
25
|
+
*
|
|
26
|
+
* Subclasses should make their requests through this method rather than through
|
|
27
|
+
* `ajaxImpl`, whose callback-shaped contract is kept only for compatibility. This is the
|
|
28
|
+
* only place in the class that deals in success/error callbacks.
|
|
29
|
+
*/
|
|
30
|
+
_ajax(config, errorMessagePrefix, prepareResponse) {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
this.ajaxImpl.ajax({
|
|
33
|
+
...config,
|
|
34
|
+
// Each callback is guarded: a throw inside one would otherwise escape into the ajax
|
|
35
|
+
// adapter and leave this promise pending for ever.
|
|
36
|
+
success: (httpResponse) => {
|
|
37
|
+
try {
|
|
38
|
+
prepareResponse && prepareResponse(httpResponse);
|
|
39
|
+
resolve(httpResponse);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
error: (httpResponse) => {
|
|
46
|
+
try {
|
|
47
|
+
// must run before makeHttpError: createError reads httpResponse.saveContext
|
|
48
|
+
// to attach per-entity validation errors.
|
|
49
|
+
prepareResponse && prepareResponse(httpResponse);
|
|
50
|
+
reject(AbstractDataServiceAdapter.makeHttpError(httpResponse, errorMessagePrefix));
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
reject(e);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async fetchMetadata(metadataStore, dataService) {
|
|
60
|
+
const serviceName = dataService.serviceName;
|
|
61
|
+
const url = dataService.qualifyUrl("Metadata");
|
|
62
|
+
const httpResponse = await this._ajax({ type: "GET", url: url, dataType: 'json' }, "Metadata query failed for: " + url);
|
|
63
|
+
// might have been fetched by another query
|
|
64
|
+
if (metadataStore.hasMetadataFor(serviceName)) {
|
|
65
|
+
return "already fetched";
|
|
66
|
+
}
|
|
67
|
+
const data = httpResponse.data;
|
|
68
|
+
let metadata;
|
|
69
|
+
try {
|
|
70
|
+
metadata = typeof (data) === "string" ? JSON.parse(data) : data;
|
|
71
|
+
metadataStore.importMetadata(metadata);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const errMsg = "Unable to either parse or import metadata: " + e.message;
|
|
75
|
+
throw AbstractDataServiceAdapter.makeHttpError(httpResponse, "Metadata query failed for: " + url + ". " + errMsg);
|
|
76
|
+
}
|
|
77
|
+
// import may have brought in the service.
|
|
78
|
+
if (!metadataStore.hasMetadataFor(serviceName)) {
|
|
79
|
+
metadataStore.addDataService(dataService);
|
|
80
|
+
}
|
|
81
|
+
return metadata;
|
|
82
|
+
}
|
|
83
|
+
/** Execute the query in the mappingContext. */
|
|
84
|
+
async executeQuery(mappingContext) {
|
|
85
|
+
mappingContext.adapter = this;
|
|
86
|
+
const usePost = mappingContext.query.usePostEnabled;
|
|
87
|
+
const params = usePost ? this._makeQueryPostParams(mappingContext) : this._makeQueryGetParams(mappingContext);
|
|
88
|
+
const httpResponse = await this._ajax(params);
|
|
89
|
+
const data = httpResponse.data;
|
|
90
|
+
try {
|
|
91
|
+
const results = data && (data.results || data.Results);
|
|
92
|
+
if (results) {
|
|
93
|
+
return {
|
|
94
|
+
results: results,
|
|
95
|
+
inlineCount: data.inlineCount || data.InlineCount,
|
|
96
|
+
httpResponse: httpResponse,
|
|
97
|
+
query: mappingContext.query
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return { results: data, httpResponse: httpResponse, query: mappingContext.query };
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
if (e instanceof Error) {
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
throw AbstractDataServiceAdapter.makeHttpError(httpResponse);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Set up ajax parameters for query GET. This puts the query into the request querystring, in whatever syntax the UriBuilder produces. */
|
|
110
|
+
_makeQueryGetParams(mappingContext) {
|
|
111
|
+
const url = mappingContext.getUrl();
|
|
112
|
+
const params = {
|
|
113
|
+
type: "GET",
|
|
114
|
+
url: url,
|
|
115
|
+
params: mappingContext.query.parameters,
|
|
116
|
+
dataType: 'json',
|
|
117
|
+
crossDomain: false,
|
|
118
|
+
};
|
|
119
|
+
// useJsonp is deprecated. Breeze's own transport ignores dataType and crossDomain; this
|
|
120
|
+
// stays only because a registered (deprecated) ajax adapter could still act on them.
|
|
121
|
+
if (mappingContext.dataService.useJsonp) {
|
|
122
|
+
params.dataType = 'jsonp';
|
|
123
|
+
params.crossDomain = true;
|
|
124
|
+
}
|
|
125
|
+
return params;
|
|
126
|
+
}
|
|
127
|
+
/** Set up ajax parameters for query POST. This put the query into the request body as JSON. */
|
|
128
|
+
_makeQueryPostParams(mappingContext) {
|
|
129
|
+
const entityQuery = mappingContext.query;
|
|
130
|
+
const metadataStore = mappingContext.entityManager.metadataStore;
|
|
131
|
+
const url = mappingContext.dataService.qualifyUrl(entityQuery.resourceName);
|
|
132
|
+
let entityType = entityQuery._getFromEntityType(metadataStore, false);
|
|
133
|
+
if (!entityType) {
|
|
134
|
+
entityType = new EntityType(metadataStore);
|
|
135
|
+
}
|
|
136
|
+
const json = entityQuery.toJSONExt({ entityType: entityType, toNameOnServer: true });
|
|
137
|
+
json.from = undefined;
|
|
138
|
+
json.queryOptions = undefined;
|
|
139
|
+
// withParameters values go in the query string (params, below), as for a GET.
|
|
140
|
+
json.parameters = undefined;
|
|
141
|
+
const params = {
|
|
142
|
+
type: "POST",
|
|
143
|
+
url: url,
|
|
144
|
+
params: mappingContext.query.parameters,
|
|
145
|
+
dataType: 'json',
|
|
146
|
+
processData: false, // don't form-encode the body
|
|
147
|
+
contentType: "application/json; charset=UTF-8",
|
|
148
|
+
data: JSON.stringify(json),
|
|
149
|
+
crossDomain: false,
|
|
150
|
+
};
|
|
151
|
+
return params;
|
|
152
|
+
}
|
|
153
|
+
async saveChanges(saveContext, saveBundle) {
|
|
154
|
+
let adapter = saveContext.adapter = this;
|
|
155
|
+
let saveBundleSer = adapter._prepareSaveBundle(saveContext, saveBundle);
|
|
156
|
+
let bundle = JSON.stringify(saveBundleSer);
|
|
157
|
+
const url = saveContext.dataService.qualifyUrl(saveContext.resourceName);
|
|
158
|
+
// saveContext must be on the response before any error is built from it
|
|
159
|
+
const httpResponse = await this._ajax({
|
|
160
|
+
type: "POST",
|
|
161
|
+
url: url,
|
|
162
|
+
dataType: 'json',
|
|
163
|
+
contentType: "application/json",
|
|
164
|
+
data: bundle,
|
|
165
|
+
}, undefined, (r) => { r.saveContext = saveContext; });
|
|
166
|
+
const data = httpResponse.data;
|
|
167
|
+
if (data == null || data === "") {
|
|
168
|
+
const err = AbstractDataServiceAdapter.makeHttpError(httpResponse);
|
|
169
|
+
err.message = "The response to the save request to " + url + " (HTTP status " + httpResponse.status +
|
|
170
|
+
") had no body. Breeze needs the saved entities and any key mappings to complete the save.";
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
if (data.Errors || data.errors) {
|
|
174
|
+
throw AbstractDataServiceAdapter.makeHttpError(httpResponse);
|
|
175
|
+
}
|
|
176
|
+
const saveResult = adapter._prepareSaveResult(saveContext, data);
|
|
177
|
+
saveResult.httpResponse = httpResponse;
|
|
178
|
+
return saveResult;
|
|
179
|
+
}
|
|
180
|
+
/** Abstract method that needs to be overwritten in any concrete DataServiceAdapter subclass.
|
|
181
|
+
The return value from this method should be a serializable object that will be sent to the server after calling JSON.stringify on it.
|
|
182
|
+
*/
|
|
183
|
+
_prepareSaveBundle(saveContext, saveBundle) {
|
|
184
|
+
// The implementor should call _createChangeRequestInterceptor
|
|
185
|
+
throw new Error("Need a concrete implementation of _prepareSaveBundle");
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
Returns a constructor function for a "ChangeRequestInterceptor"
|
|
189
|
+
that can tweak the saveBundle both as it is built and when it is completed
|
|
190
|
+
by a concrete DataServiceAdapater.
|
|
191
|
+
|
|
192
|
+
Initialized with a default, no-op implementation that developers can replace with a
|
|
193
|
+
substantive implementation that changes the individual entity change requests
|
|
194
|
+
or aspects of the entire 'saveBundle' without having to write their own DataService adapters.
|
|
195
|
+
```ts
|
|
196
|
+
let adapter = breeze.config.getAdapterInstance('dataService');
|
|
197
|
+
adapter.changeRequestInterceptor = function (saveContext, saveBundle) {
|
|
198
|
+
this.getRequest = function (request, entity, index) {
|
|
199
|
+
// alter the request that the adapter prepared for this entity
|
|
200
|
+
// based on the entity, saveContext, and saveBundle
|
|
201
|
+
// e.g., add a custom header or prune the originalValuesMap
|
|
202
|
+
return request;
|
|
203
|
+
};
|
|
204
|
+
this.done = function (requests) {
|
|
205
|
+
// alter the array of requests representing the entire change-set
|
|
206
|
+
// based on the saveContext and saveBundle
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
@param saveContext - The BreezeJS "context" for the save operation.
|
|
212
|
+
@param saveBundle - Contains the array of entities-to-be-saved (AKA, the entity change-set).
|
|
213
|
+
@returns Constructor for a "ChangeRequestInterceptor".
|
|
214
|
+
*/
|
|
215
|
+
changeRequestInterceptor = DefaultChangeRequestInterceptor;
|
|
216
|
+
/**
|
|
217
|
+
* Creates the change request interceptor for one save, from `changeRequestInterceptor`.
|
|
218
|
+
* Call it at the start of `_prepareSaveBundle`, pass each entity's request through its
|
|
219
|
+
* `getRequest`, and pass the finished array to its `done`.
|
|
220
|
+
*
|
|
221
|
+
* Falls back to a no-op interceptor when `changeRequestInterceptor` is not set. If the
|
|
222
|
+
* interceptor it creates has `oneTime` set, the adapter goes back to the no-op
|
|
223
|
+
* interceptor afterwards, so only this save is intercepted.
|
|
224
|
+
* @throws if the interceptor has no `getRequest` or `done` method.
|
|
225
|
+
*/
|
|
226
|
+
_createChangeRequestInterceptor(saveContext, saveBundle) {
|
|
227
|
+
let adapter = saveContext.adapter;
|
|
228
|
+
let cri = adapter.changeRequestInterceptor;
|
|
229
|
+
let isFn = core.isFunction;
|
|
230
|
+
if (isFn(cri)) {
|
|
231
|
+
let pre = adapter.name + " DataServiceAdapter's ChangeRequestInterceptor";
|
|
232
|
+
let post = " is missing or not a function.";
|
|
233
|
+
let interceptor = new cri(saveContext, saveBundle);
|
|
234
|
+
if (!isFn(interceptor.getRequest)) {
|
|
235
|
+
throw new Error(pre + '.getRequest' + post);
|
|
236
|
+
}
|
|
237
|
+
if (!isFn(interceptor.done)) {
|
|
238
|
+
throw new Error(pre + '.done' + post);
|
|
239
|
+
}
|
|
240
|
+
if (interceptor.oneTime) {
|
|
241
|
+
adapter.changeRequestInterceptor = DefaultChangeRequestInterceptor;
|
|
242
|
+
}
|
|
243
|
+
return interceptor;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
return new DefaultChangeRequestInterceptor(saveContext, saveBundle);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Abstract method that needs to be overwritten in any concrete DataServiceAdapter sublclass.
|
|
250
|
+
This method needs to take the result returned the server and convert it into an ISaveResult.
|
|
251
|
+
*/
|
|
252
|
+
_prepareSaveResult(saveContext, data) {
|
|
253
|
+
throw new Error("Need a concrete implementation of _prepareSaveResult");
|
|
254
|
+
}
|
|
255
|
+
/** Utility method that may be used in any concrete DataServiceAdapter sublclass to handle any
|
|
256
|
+
http connection issues. For an error with status 0 - the request got no response - it says in
|
|
257
|
+
the message that the server could not be reached, keeping any message the transport gave.
|
|
258
|
+
An aborted request is left alone. `makeHttpError` already applies it.
|
|
259
|
+
*/
|
|
260
|
+
// Put this at the bottom of your http error analysis
|
|
261
|
+
static _catchNoConnectionError(err) {
|
|
262
|
+
if (err.status !== 0)
|
|
263
|
+
return;
|
|
264
|
+
const cause = err.httpResponse && err.httpResponse.error;
|
|
265
|
+
if (cause && cause.name === "AbortError")
|
|
266
|
+
return; // the app cancelled it; the server is irrelevant
|
|
267
|
+
const hint = "Likely did not or could not reach server. Is the server running?";
|
|
268
|
+
if (err.message && err.message.includes(hint))
|
|
269
|
+
return; // already applied
|
|
270
|
+
err.message = err.message
|
|
271
|
+
? "HTTP response status 0: " + err.message + ". " + hint
|
|
272
|
+
: "HTTP response status 0 and no message. " + hint;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Builds the Breeze error for a failed HTTP response: an `Error` carrying `status`,
|
|
276
|
+
* `statusText`, `url`, `body` and `httpResponse`, whose message comes from the response
|
|
277
|
+
* body (a .NET exception, or `{ message, errors }`). For a save, it also carries the
|
|
278
|
+
* server's per-entity `entityErrors`, if `httpResponse.saveContext` is set.
|
|
279
|
+
*
|
|
280
|
+
* `_ajax` uses it for every failed request. Call it when your adapter makes a request some
|
|
281
|
+
* other way, then throw or reject with the result.
|
|
282
|
+
* @param httpResponse - The failed response.
|
|
283
|
+
* @param messagePrefix - Put at the start of the message, followed by "; ".
|
|
284
|
+
*/
|
|
285
|
+
static makeHttpError(httpResponse, messagePrefix) {
|
|
286
|
+
const err = createError(httpResponse);
|
|
287
|
+
AbstractDataServiceAdapter._catchNoConnectionError(err);
|
|
288
|
+
if (messagePrefix) {
|
|
289
|
+
err.message = messagePrefix + "; " + err.message;
|
|
290
|
+
}
|
|
291
|
+
return err;
|
|
292
|
+
}
|
|
293
|
+
jsonResultsAdapter = new JsonResultsAdapter({
|
|
294
|
+
name: "noop",
|
|
295
|
+
visitNode: function ( /* node, mappingContext, nodeContext */) {
|
|
296
|
+
return {};
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function createError(httpResponse) {
|
|
301
|
+
let err = new Error();
|
|
302
|
+
err.httpResponse = httpResponse;
|
|
303
|
+
err.status = httpResponse.status;
|
|
304
|
+
err.statusText = httpResponse.statusText;
|
|
305
|
+
err.body = httpResponse.data;
|
|
306
|
+
err.url = httpResponse.config && httpResponse.config.url;
|
|
307
|
+
let errObj = httpResponse.data;
|
|
308
|
+
if (!errObj) {
|
|
309
|
+
err.message = httpResponse.error && httpResponse.error.toString();
|
|
310
|
+
return err;
|
|
311
|
+
}
|
|
312
|
+
// some ajax providers convert an errant result into an object, others do not
|
|
313
|
+
// if not do it here.
|
|
314
|
+
if (typeof errObj === "string") {
|
|
315
|
+
try {
|
|
316
|
+
errObj = JSON.parse(errObj);
|
|
317
|
+
}
|
|
318
|
+
catch (e) {
|
|
319
|
+
// sometimes httpResponse.data is just the error message itself
|
|
320
|
+
err.message = errObj;
|
|
321
|
+
return err;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// The RFC 9457 `type` member, taken before the branch below because it is spelled the same
|
|
325
|
+
// whichever shape the rest of the document has: a Breeze server sends it alongside the
|
|
326
|
+
// capitalised pre-3.0 members as well as instead of them. This is what lets a caller tell a
|
|
327
|
+
// concurrency conflict from a duplicate key, which share a status code.
|
|
328
|
+
if (typeof errObj.type === "string")
|
|
329
|
+
err.problemType = errObj.type;
|
|
330
|
+
let saveContext = httpResponse.saveContext;
|
|
331
|
+
// if any of the follow properties exist the source is .NET
|
|
332
|
+
let tmp = errObj.Message || errObj.ExceptionMessage || errObj.EntityErrors || errObj.Errors;
|
|
333
|
+
let isDotNet = !!tmp;
|
|
334
|
+
let message, entityErrors;
|
|
335
|
+
if (!isDotNet) {
|
|
336
|
+
// RFC 9457 (Problem Details for HTTP APIs) calls the human-readable text `detail`, with
|
|
337
|
+
// `title` as the shorter summary of the problem *type*. A server that sends problem+json and
|
|
338
|
+
// nothing else would otherwise fall through to the generic message at the end of this
|
|
339
|
+
// function, which says entity errors were encountered whether or not any were - a confidently
|
|
340
|
+
// wrong message is harder to diagnose than a missing one.
|
|
341
|
+
message = errObj.message || errObj.detail || errObj.title;
|
|
342
|
+
// `entityErrors` is a Breeze extension member; RFC 9457 section 3.2 allows those, and the
|
|
343
|
+
// spec requires consumers to ignore members they do not recognize.
|
|
344
|
+
entityErrors = errObj.errors || errObj.entityErrors;
|
|
345
|
+
// Normalize the same way the .NET branch does. Without this a server sending the natural
|
|
346
|
+
// "Namespace.Type" spelling gets "Unable to locate a 'Type' by the name ..." from the entity
|
|
347
|
+
// lookup in processServerErrors, with nothing to connect it to the error format.
|
|
348
|
+
entityErrors = entityErrors && entityErrors.map(function (e) {
|
|
349
|
+
return e.entityTypeName
|
|
350
|
+
? { ...e, entityTypeName: MetadataStore.normalizeTypeName(e.entityTypeName) }
|
|
351
|
+
: e;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
let tmp = errObj;
|
|
356
|
+
do {
|
|
357
|
+
// .NET exceptions can provide both ExceptionMessage and Message but ExceptionMethod if it
|
|
358
|
+
// exists has a more detailed message.
|
|
359
|
+
message = tmp.ExceptionMessage || tmp.Message;
|
|
360
|
+
tmp = tmp.InnerException;
|
|
361
|
+
} while (tmp);
|
|
362
|
+
// .EntityErrors will only occur as a result of an EntityErrorsException being deliberately thrown on the server
|
|
363
|
+
entityErrors = errObj.Errors || errObj.EntityErrors;
|
|
364
|
+
entityErrors = entityErrors && entityErrors.map(function (e) {
|
|
365
|
+
return {
|
|
366
|
+
errorName: e.ErrorName,
|
|
367
|
+
entityTypeName: MetadataStore.normalizeTypeName(e.EntityTypeName),
|
|
368
|
+
keyValues: e.KeyValues,
|
|
369
|
+
propertyName: e.PropertyName,
|
|
370
|
+
errorMessage: e.ErrorMessage,
|
|
371
|
+
custom: e.Custom
|
|
372
|
+
};
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
if (saveContext && entityErrors) {
|
|
376
|
+
let propNameFn = saveContext.entityManager.metadataStore.namingConvention.serverPropertyNameToClient;
|
|
377
|
+
entityErrors.forEach(function (e) {
|
|
378
|
+
e.propertyName = e.propertyName && propNameFn(e.propertyName);
|
|
379
|
+
});
|
|
380
|
+
err.entityErrors = entityErrors;
|
|
381
|
+
}
|
|
382
|
+
err.message = message || "Server side errors encountered - see the entityErrors collection on this object for more detail";
|
|
383
|
+
return err;
|
|
384
|
+
}
|
|
385
|
+
/** This is a default, no-op implementation that developers can replace. */
|
|
386
|
+
class DefaultChangeRequestInterceptor {
|
|
387
|
+
constructor(saveContext, saveBundle) {
|
|
388
|
+
}
|
|
389
|
+
getRequest(request, entity, index) {
|
|
390
|
+
return request;
|
|
391
|
+
}
|
|
392
|
+
done(requests) {
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
//# sourceMappingURL=abstract-data-service-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-data-service-adapter.js","sourceRoot":"","sources":["../../src/adapters/abstract-data-service-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAKxC,OAAO,EAAe,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE3E;;;EAGE;AACF,MAAM,OAAgB,0BAA0B;IAa9C,qBAAqB;IACrB,qBAAqB,CAAC,wBAA6B;QACjD,IAAI,wBAAw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Y;gBAC5B,YAAY,EAAE,CAAC,CAAC,YAAY;gBAC5B,MAAM,EAAE,CAAC,CAAC,MAAM;aACjB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,WAAW,IAAI,YAAY,EAAE,CAAC;QAEhC,IAAI,UAAU,GAAG,WAAW,CAAC,aAAa,CAAC,aAAa,CAAC,gBAAgB,CAAC,0BAA0B,CAAC;QACrG,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC;YAC9B,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,IAAI,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;QACF,GAA2B,CAAC,YAAY,GAAG,YAAY,CAAC;IAC3D,CAAC;IAED,GAAG,CAAC,OAAO,GAAG,OAAO,IAAI,iGAAiG,CAAC;IAC3H,OAAO,GAAG,CAAC;AACb,CAAC;AAGD,2EAA2E;AAC3E,MAAM,+BAA+B;IACnC,YAAY,WAAwB,EAAE,UAAsB;IAE5D,CAAC;IAED,UAAU,CAAC,OAAY,EAAE,MAAc,EAAE,KAAa;QACpD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,CAAC,QAAkB;IACvB,CAAC;CACF","sourcesContent":["import { core } from '../core/core.js';\r\nimport { config } from '../config/config.js';\r\nimport { builtinAjax } from './http.js';\r\nimport { EntityQuery } from '../query/entity-query.js';\r\nimport { DataServiceAdapter, AjaxAdapter, AjaxConfig, ChangeRequestInterceptorCtor, ChangeRequestInterceptor } from '../config/interface-registry.js';\r\nimport { Entity } from '../entity/entity-aspect.js';\r\nimport { MappingContext } from '../query/mapping-context.js';\r\nimport { DataService, JsonResultsAdapter } from '../metadata/data-service.js';\r\nimport { HttpResponse, SaveContext, SaveBundle, ServerError, SaveResult, SaveErrorFromServer, QueryResult } from '../manager/entity-manager.js';\r\nimport { EntityType, MetadataStore } from '../metadata/entity-metadata.js';\r\n\r\n/** For use by breeze plugin authors only. The class is used as the base class for most {@link DataServiceAdapter} implementations\r\n@adapter (see {@link DataServiceAdapter}) \r\n@hidden\r\n*/\r\nexport abstract class AbstractDataServiceAdapter implements DataServiceAdapter {\r\n /** @hidden @internal */\r\n declare _$impl?: any;\r\n /** The name of this adapter. */\r\n declare name: string;\r\n /**\r\n * The ajax adapter requests go through: the registered default if there is one, otherwise\r\n * a built-in one that uses `config.fetch`.\r\n * @deprecated Make requests with `_ajax`, and supply the transport with\r\n * `configureBreeze({ fetch })`.\r\n */\r\n declare ajaxImpl: AjaxAdapter;\r\n\r\n // TODO use interface\r\n checkForRecomposition(interfaceInitializedArgs: any) {\r\n if (interfaceInitializedArgs.interfaceName === \"ajax\" && interfaceInitializedArgs.isDefault) {\r\n this.initialize();\r\n }\r\n }\r\n\r\n initialize() {\r\n // An ajax adapter is optional. A registered one (deprecated) is used if there is one;\r\n // otherwise requests go through config.fetch, which defaults to globalThis.fetch. This\r\n // is also why registration order no longer matters: there is nothing to resolve.\r\n this.ajaxImpl = config.getAdapterInstance<AjaxAdapter>(\"ajax\") || builtinAjax;\r\n }\r\n\r\n /**\r\n * Sends one request. Resolves with the response, or rejects with a `ServerError`.\r\n *\r\n * Subclasses should make their requests through this method rather than through\r\n * `ajaxImpl`, whose callback-shaped contract is kept only for compatibility. This is the\r\n * only place in the class that deals in success/error callbacks.\r\n */\r\n protected _ajax(\r\n config: Omit<AjaxConfig, 'success' | 'error'>,\r\n errorMessagePrefix?: string,\r\n prepareResponse?: (httpResponse: HttpResponse) => void): Promise<HttpResponse> {\r\n return new Promise<HttpResponse>((resolve, reject) => {\r\n this.ajaxImpl.ajax({\r\n ...config,\r\n // Each callback is guarded: a throw inside one would otherwise escape into the ajax\r\n // adapter and leave this promise pending for ever.\r\n success: (httpResponse: HttpResponse) => {\r\n try {\r\n prepareResponse && prepareResponse(httpResponse);\r\n resolve(httpResponse);\r\n } catch (e) {\r\n reject(e);\r\n }\r\n },\r\n error: (httpResponse: HttpResponse) => {\r\n try {\r\n // must run before makeHttpError: createError reads httpResponse.saveContext\r\n // to attach per-entity validation errors.\r\n prepareResponse && prepareResponse(httpResponse);\r\n reject(AbstractDataServiceAdapter.makeHttpError(httpResponse, errorMessagePrefix));\r\n } catch (e) {\r\n reject(e);\r\n }\r\n },\r\n } as AjaxConfig);\r\n });\r\n }\r\n\r\n async fetchMetadata(metadataStore: MetadataStore, dataService: DataService) {\r\n const serviceName = dataService.serviceName;\r\n const url = dataService.qualifyUrl(\"Metadata\");\r\n\r\n const httpResponse = await this._ajax(\r\n { type: \"GET\", url: url, dataType: 'json' },\r\n \"Metadata query failed for: \" + url);\r\n\r\n // might have been fetched by another query\r\n if (metadataStore.hasMetadataFor(serviceName)) {\r\n return \"already fetched\";\r\n }\r\n\r\n const data = httpResponse.data;\r\n let metadata: any;\r\n try {\r\n metadata = typeof (data) === \"string\" ? JSON.parse(data) : data;\r\n metadataStore.importMetadata(metadata);\r\n } catch (e) {\r\n const errMsg = \"Unable to either parse or import metadata: \" + (e as Error).message;\r\n throw AbstractDataServiceAdapter.makeHttpError(httpResponse, \"Metadata query failed for: \" + url + \". \" + errMsg);\r\n }\r\n\r\n // import may have brought in the service.\r\n if (!metadataStore.hasMetadataFor(serviceName)) {\r\n metadataStore.addDataService(dataService);\r\n }\r\n\r\n return metadata;\r\n }\r\n\r\n /** Execute the query in the mappingContext. */\r\n async executeQuery(mappingContext: MappingContext): Promise<QueryResult> {\r\n mappingContext.adapter = this;\r\n\r\n const usePost = (mappingContext.query as EntityQuery).usePostEnabled;\r\n const params = usePost ? this._makeQueryPostParams(mappingContext) : this._makeQueryGetParams(mappingContext) as any;\r\n\r\n const httpResponse = await this._ajax(params);\r\n\r\n const data = httpResponse.data;\r\n try {\r\n const results = data && (data.results || data.Results);\r\n if (results) {\r\n return {\r\n results: results,\r\n inlineCount: data.inlineCount || data.InlineCount,\r\n httpResponse: httpResponse,\r\n query: mappingContext.query\r\n } as QueryResult;\r\n }\r\n return { results: data, httpResponse: httpResponse, query: mappingContext.query } as QueryResult;\r\n } catch (e) {\r\n if (e instanceof Error) { throw e; }\r\n throw AbstractDataServiceAdapter.makeHttpError(httpResponse);\r\n }\r\n }\r\n\r\n /** Set up ajax parameters for query GET. This puts the query into the request querystring, in whatever syntax the UriBuilder produces. */\r\n _makeQueryGetParams(mappingContext: MappingContext) {\r\n const url = mappingContext.getUrl();\r\n\r\n const params = {\r\n type: \"GET\",\r\n url: url,\r\n params: (mappingContext.query as EntityQuery).parameters,\r\n dataType: 'json',\r\n crossDomain: false,\r\n };\r\n // useJsonp is deprecated. Breeze's own transport ignores dataType and crossDomain; this\r\n // stays only because a registered (deprecated) ajax adapter could still act on them.\r\n if (mappingContext.dataService.useJsonp) {\r\n params.dataType = 'jsonp';\r\n params.crossDomain = true;\r\n }\r\n return params;\r\n }\r\n\r\n /** Set up ajax parameters for query POST. This put the query into the request body as JSON. */\r\n _makeQueryPostParams(mappingContext: MappingContext) {\r\n const entityQuery = mappingContext.query as EntityQuery;\r\n const metadataStore = mappingContext.entityManager.metadataStore;\r\n const url = mappingContext.dataService.qualifyUrl(entityQuery.resourceName!);\r\n\r\n let entityType = entityQuery._getFromEntityType(metadataStore, false);\r\n if (!entityType) { entityType = new EntityType(metadataStore); }\r\n const json = entityQuery.toJSONExt({ entityType: entityType, toNameOnServer: true}) as any;\r\n json.from = undefined;\r\n json.queryOptions = undefined;\r\n // withParameters values go in the query string (params, below), as for a GET.\r\n json.parameters = undefined;\r\n\r\n const params = {\r\n type: \"POST\",\r\n url: url,\r\n params: (mappingContext.query as EntityQuery).parameters,\r\n dataType: 'json',\r\n processData: false, // don't form-encode the body\r\n contentType: \"application/json; charset=UTF-8\",\r\n data: JSON.stringify(json),\r\n crossDomain: false,\r\n };\r\n return params;\r\n }\r\n\r\n async saveChanges(saveContext: SaveContext, saveBundle: SaveBundle): Promise<SaveResult> {\r\n let adapter = saveContext.adapter = this;\r\n\r\n let saveBundleSer = adapter._prepareSaveBundle(saveContext, saveBundle);\r\n let bundle = JSON.stringify(saveBundleSer);\r\n\r\n const url = saveContext.dataService.qualifyUrl(saveContext.resourceName);\r\n\r\n // saveContext must be on the response before any error is built from it\r\n const httpResponse = await this._ajax(\r\n {\r\n type: \"POST\",\r\n url: url,\r\n dataType: 'json',\r\n contentType: \"application/json\",\r\n data: bundle,\r\n },\r\n undefined,\r\n (r) => { r.saveContext = saveContext; });\r\n\r\n const data = httpResponse.data;\r\n if (data == null || data === \"\") {\r\n const err = AbstractDataServiceAdapter.makeHttpError(httpResponse);\r\n err.message = \"The response to the save request to \" + url + \" (HTTP status \" + httpResponse.status +\r\n \") had no body. Breeze needs the saved entities and any key mappings to complete the save.\";\r\n throw err;\r\n }\r\n if (data.Errors || data.errors) {\r\n throw AbstractDataServiceAdapter.makeHttpError(httpResponse);\r\n }\r\n\r\n const saveResult = adapter._prepareSaveResult(saveContext, data);\r\n saveResult.httpResponse = httpResponse;\r\n return saveResult;\r\n }\r\n\r\n /** Abstract method that needs to be overwritten in any concrete DataServiceAdapter subclass. \r\n The return value from this method should be a serializable object that will be sent to the server after calling JSON.stringify on it.\r\n */\r\n _prepareSaveBundle(saveContext: SaveContext, saveBundle: SaveBundle): any {\r\n // The implementor should call _createChangeRequestInterceptor\r\n throw new Error(\"Need a concrete implementation of _prepareSaveBundle\");\r\n }\r\n\r\n /**\r\n Returns a constructor function for a \"ChangeRequestInterceptor\"\r\n that can tweak the saveBundle both as it is built and when it is completed\r\n by a concrete DataServiceAdapater.\r\n\r\n Initialized with a default, no-op implementation that developers can replace with a\r\n substantive implementation that changes the individual entity change requests\r\n or aspects of the entire 'saveBundle' without having to write their own DataService adapters.\r\n ```ts\r\n let adapter = breeze.config.getAdapterInstance('dataService');\r\n adapter.changeRequestInterceptor = function (saveContext, saveBundle) {\r\n this.getRequest = function (request, entity, index) {\r\n // alter the request that the adapter prepared for this entity\r\n // based on the entity, saveContext, and saveBundle\r\n // e.g., add a custom header or prune the originalValuesMap\r\n return request;\r\n };\r\n this.done = function (requests) {\r\n // alter the array of requests representing the entire change-set\r\n // based on the saveContext and saveBundle\r\n };\r\n }\r\n ```\r\n\r\n @param saveContext - The BreezeJS \"context\" for the save operation.\r\n @param saveBundle - Contains the array of entities-to-be-saved (AKA, the entity change-set).\r\n @returns Constructor for a \"ChangeRequestInterceptor\".\r\n */\r\n changeRequestInterceptor: ChangeRequestInterceptorCtor = DefaultChangeRequestInterceptor;\r\n\r\n /**\r\n * Creates the change request interceptor for one save, from `changeRequestInterceptor`.\r\n * Call it at the start of `_prepareSaveBundle`, pass each entity's request through its\r\n * `getRequest`, and pass the finished array to its `done`.\r\n *\r\n * Falls back to a no-op interceptor when `changeRequestInterceptor` is not set. If the\r\n * interceptor it creates has `oneTime` set, the adapter goes back to the no-op\r\n * interceptor afterwards, so only this save is intercepted.\r\n * @throws if the interceptor has no `getRequest` or `done` method.\r\n */\r\n protected _createChangeRequestInterceptor(saveContext: SaveContext, saveBundle: SaveBundle): ChangeRequestInterceptor {\r\n let adapter = saveContext.adapter!;\r\n let cri = adapter.changeRequestInterceptor;\r\n let isFn = core.isFunction;\r\n\r\n if (isFn(cri)) {\r\n let pre = adapter.name + \" DataServiceAdapter's ChangeRequestInterceptor\";\r\n let post = \" is missing or not a function.\";\r\n let interceptor = new cri(saveContext, saveBundle);\r\n if (!isFn(interceptor.getRequest)) {\r\n throw new Error(pre + '.getRequest' + post);\r\n }\r\n if (!isFn(interceptor.done)) {\r\n throw new Error(pre + '.done' + post);\r\n }\r\n if (interceptor.oneTime) {\r\n adapter.changeRequestInterceptor = DefaultChangeRequestInterceptor;\r\n }\r\n return interceptor;\r\n } else {\r\n return new DefaultChangeRequestInterceptor(saveContext, saveBundle) as ChangeRequestInterceptor;\r\n }\r\n }\r\n\r\n /** Abstract method that needs to be overwritten in any concrete DataServiceAdapter sublclass. \r\n This method needs to take the result returned the server and convert it into an ISaveResult. \r\n */\r\n _prepareSaveResult(saveContext: SaveContext, data: any): SaveResult {\r\n throw new Error(\"Need a concrete implementation of _prepareSaveResult\");\r\n }\r\n\r\n\r\n /** Utility method that may be used in any concrete DataServiceAdapter sublclass to handle any \r\n http connection issues. For an error with status 0 - the request got no response - it says in\r\n the message that the server could not be reached, keeping any message the transport gave.\r\n An aborted request is left alone. `makeHttpError` already applies it.\r\n */\r\n // Put this at the bottom of your http error analysis\r\n static _catchNoConnectionError(err: ServerError) {\r\n if (err.status !== 0) return;\r\n const cause = err.httpResponse && err.httpResponse.error;\r\n if (cause && cause.name === \"AbortError\") return; // the app cancelled it; the server is irrelevant\r\n const hint = \"Likely did not or could not reach server. Is the server running?\";\r\n if (err.message && err.message.includes(hint)) return; // already applied\r\n err.message = err.message\r\n ? \"HTTP response status 0: \" + err.message + \". \" + hint\r\n : \"HTTP response status 0 and no message. \" + hint;\r\n }\r\n\r\n /**\r\n * Builds the Breeze error for a failed HTTP response: an `Error` carrying `status`,\r\n * `statusText`, `url`, `body` and `httpResponse`, whose message comes from the response\r\n * body (a .NET exception, or `{ message, errors }`). For a save, it also carries the\r\n * server's per-entity `entityErrors`, if `httpResponse.saveContext` is set.\r\n *\r\n * `_ajax` uses it for every failed request. Call it when your adapter makes a request some\r\n * other way, then throw or reject with the result.\r\n * @param httpResponse - The failed response.\r\n * @param messagePrefix - Put at the start of the message, followed by \"; \".\r\n */\r\n static makeHttpError(httpResponse: HttpResponse, messagePrefix?: string): ServerError {\r\n const err = createError(httpResponse);\r\n AbstractDataServiceAdapter._catchNoConnectionError(err);\r\n if (messagePrefix) {\r\n err.message = messagePrefix + \"; \" + err.message;\r\n }\r\n return err;\r\n }\r\n\r\n jsonResultsAdapter = new JsonResultsAdapter({\r\n name: \"noop\",\r\n\r\n visitNode: function (/* node, mappingContext, nodeContext */) {\r\n return {};\r\n }\r\n });\r\n}\r\n\r\nfunction createError(httpResponse: HttpResponse) {\r\n let err = new Error() as ServerError;\r\n err.httpResponse = httpResponse;\r\n err.status = httpResponse.status;\r\n err.statusText = httpResponse.statusText;\r\n err.body = httpResponse.data;\r\n err.url = httpResponse.config && httpResponse.config.url;\r\n\r\n let errObj = httpResponse.data;\r\n\r\n if (!errObj) {\r\n err.message = httpResponse.error && httpResponse.error.toString();\r\n return err;\r\n }\r\n\r\n // some ajax providers convert an errant result into an object, others do not\r\n // if not do it here.\r\n if (typeof errObj === \"string\") {\r\n try {\r\n errObj = JSON.parse(errObj);\r\n } catch (e) {\r\n // sometimes httpResponse.data is just the error message itself\r\n err.message = errObj;\r\n return err;\r\n }\r\n }\r\n\r\n // The RFC 9457 `type` member, taken before the branch below because it is spelled the same\r\n // whichever shape the rest of the document has: a Breeze server sends it alongside the\r\n // capitalised pre-3.0 members as well as instead of them. This is what lets a caller tell a\r\n // concurrency conflict from a duplicate key, which share a status code.\r\n if (typeof errObj.type === \"string\") err.problemType = errObj.type;\r\n\r\n let saveContext = httpResponse.saveContext;\r\n\r\n // if any of the follow properties exist the source is .NET\r\n let tmp = errObj.Message || errObj.ExceptionMessage || errObj.EntityErrors || errObj.Errors;\r\n let isDotNet = !!tmp;\r\n let message: string, entityErrors: any[];\r\n if (!isDotNet) {\r\n // RFC 9457 (Problem Details for HTTP APIs) calls the human-readable text `detail`, with\r\n // `title` as the shorter summary of the problem *type*. A server that sends problem+json and\r\n // nothing else would otherwise fall through to the generic message at the end of this\r\n // function, which says entity errors were encountered whether or not any were - a confidently\r\n // wrong message is harder to diagnose than a missing one.\r\n message = errObj.message || errObj.detail || errObj.title;\r\n // `entityErrors` is a Breeze extension member; RFC 9457 section 3.2 allows those, and the\r\n // spec requires consumers to ignore members they do not recognize.\r\n entityErrors = errObj.errors || errObj.entityErrors;\r\n // Normalize the same way the .NET branch does. Without this a server sending the natural\r\n // \"Namespace.Type\" spelling gets \"Unable to locate a 'Type' by the name ...\" from the entity\r\n // lookup in processServerErrors, with nothing to connect it to the error format.\r\n entityErrors = entityErrors && entityErrors.map(function (e: any) {\r\n return e.entityTypeName\r\n ? { ...e, entityTypeName: MetadataStore.normalizeTypeName(e.entityTypeName) }\r\n : e;\r\n });\r\n } else {\r\n let tmp = errObj;\r\n do {\r\n // .NET exceptions can provide both ExceptionMessage and Message but ExceptionMethod if it\r\n // exists has a more detailed message.\r\n message = tmp.ExceptionMessage || tmp.Message;\r\n tmp = tmp.InnerException;\r\n } while (tmp);\r\n // .EntityErrors will only occur as a result of an EntityErrorsException being deliberately thrown on the server\r\n entityErrors = errObj.Errors || errObj.EntityErrors;\r\n entityErrors = entityErrors && entityErrors.map(function (e) {\r\n return {\r\n errorName: e.ErrorName,\r\n entityTypeName: MetadataStore.normalizeTypeName(e.EntityTypeName),\r\n keyValues: e.KeyValues,\r\n propertyName: e.PropertyName,\r\n errorMessage: e.ErrorMessage,\r\n custom: e.Custom\r\n };\r\n });\r\n }\r\n\r\n if (saveContext && entityErrors) {\r\n\r\n let propNameFn = saveContext.entityManager.metadataStore.namingConvention.serverPropertyNameToClient;\r\n entityErrors.forEach(function (e) {\r\n e.propertyName = e.propertyName && propNameFn(e.propertyName);\r\n });\r\n (err as SaveErrorFromServer).entityErrors = entityErrors;\r\n }\r\n\r\n err.message = message || \"Server side errors encountered - see the entityErrors collection on this object for more detail\";\r\n return err;\r\n}\r\n\r\n\r\n/** This is a default, no-op implementation that developers can replace. */\r\nclass DefaultChangeRequestInterceptor {\r\n constructor(saveContext: SaveContext, saveBundle: SaveBundle) {\r\n\r\n }\r\n\r\n getRequest(request: any, entity: Entity, index: number) {\r\n return request;\r\n }\r\n\r\n done(requests: Object[]) {\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AjaxFetchAdapter` - deprecated.
|
|
3
|
+
*
|
|
4
|
+
* Breeze 3 does not need an ajax adapter. Requests go through `config.fetch`, which you set
|
|
5
|
+
* with `configureBreeze({ fetch })` and which defaults to `globalThis.fetch`.
|
|
6
|
+
*
|
|
7
|
+
* This entry point is kept so that 2.x startup code - `AjaxFetchAdapter.register()`,
|
|
8
|
+
* `configureBreeze({ ajax: AjaxFetchAdapter })`, `config.initializeAdapterInstance('ajax',
|
|
9
|
+
* 'fetch')` - and code that uses the adapter's `defaultSettings` or `requestInterceptor`
|
|
10
|
+
* keeps working. The implementation now lives in the core, shared with the default path.
|
|
11
|
+
*/
|
|
12
|
+
export { AjaxFetchAdapter } from './http.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AjaxFetchAdapter` - deprecated.
|
|
3
|
+
*
|
|
4
|
+
* Breeze 3 does not need an ajax adapter. Requests go through `config.fetch`, which you set
|
|
5
|
+
* with `configureBreeze({ fetch })` and which defaults to `globalThis.fetch`.
|
|
6
|
+
*
|
|
7
|
+
* This entry point is kept so that 2.x startup code - `AjaxFetchAdapter.register()`,
|
|
8
|
+
* `configureBreeze({ ajax: AjaxFetchAdapter })`, `config.initializeAdapterInstance('ajax',
|
|
9
|
+
* 'fetch')` - and code that uses the adapter's `defaultSettings` or `requestInterceptor`
|
|
10
|
+
* keeps working. The implementation now lives in the core, shared with the default path.
|
|
11
|
+
*/
|
|
12
|
+
export { AjaxFetchAdapter } from './http.js';
|
|
13
|
+
//# sourceMappingURL=adapter-ajax-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-ajax-fetch.js","sourceRoot":"","sources":["../../src/adapters/adapter-ajax-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["/**\n * `AjaxFetchAdapter` - deprecated.\n *\n * Breeze 3 does not need an ajax adapter. Requests go through `config.fetch`, which you set\n * with `configureBreeze({ fetch })` and which defaults to `globalThis.fetch`.\n *\n * This entry point is kept so that 2.x startup code - `AjaxFetchAdapter.register()`,\n * `configureBreeze({ ajax: AjaxFetchAdapter })`, `config.initializeAdapterInstance('ajax',\n * 'fetch')` - and code that uses the adapter's `defaultSettings` or `requestInterceptor`\n * keeps working. The implementation now lives in the core, shared with the default path.\n */\nexport { AjaxFetchAdapter } from './http.js';\n"]}
|
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
import * as breeze from 'breeze
|
|
2
|
-
/**
|
|
3
|
-
* Functions to enable Breeze to use POST for queries when
|
|
4
|
-
* special parameters are passed using the .withParameters function.
|
|
5
|
-
*
|
|
6
|
-
* Copyright 2015-
|
|
7
|
-
* Use, reproduction, distribution, and modification of this code is subject to the terms and
|
|
8
|
-
* conditions of the IdeaBlade Breeze license, available at http://www.breezejs.com/license
|
|
9
|
-
*
|
|
10
|
-
* Author: Steve Schmitt
|
|
11
|
-
* Version:
|
|
12
|
-
* 1.2.0 - Moved into breeze-client repo and npm package
|
|
13
|
-
* 1.1.0 - revised: eliminated return object, configAjaxAdapter method; add ajaxPostEnabled flag
|
|
14
|
-
* 1.0.6 - original
|
|
15
|
-
*
|
|
16
|
-
* Special parameters:
|
|
17
|
-
* $method: ‘POST’ or ‘GET’ (the default)
|
|
18
|
-
* $encoding: ‘JSON’ or x-www-form-urlencoded (the default)
|
|
19
|
-
* $data: contains the data to be sent to the server
|
|
20
|
-
*
|
|
21
|
-
* Installation:
|
|
22
|
-
*
|
|
23
|
-
* AjaxPostWrapper.wrapAjax(ajaxAdapter);
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
import * as breeze from '../breeze.js';
|
|
2
|
+
/**
|
|
3
|
+
* Functions to enable Breeze to use POST for queries when
|
|
4
|
+
* special parameters are passed using the .withParameters function.
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2026 IdeaBlade, Inc. All Rights Reserved.
|
|
7
|
+
* Use, reproduction, distribution, and modification of this code is subject to the terms and
|
|
8
|
+
* conditions of the IdeaBlade Breeze license, available at http://www.breezejs.com/license
|
|
9
|
+
*
|
|
10
|
+
* Author: Steve Schmitt
|
|
11
|
+
* Version:
|
|
12
|
+
* 1.2.0 - Moved into breeze-client repo and npm package
|
|
13
|
+
* 1.1.0 - revised: eliminated return object, configAjaxAdapter method; add ajaxPostEnabled flag
|
|
14
|
+
* 1.0.6 - original
|
|
15
|
+
*
|
|
16
|
+
* Special parameters:
|
|
17
|
+
* $method: ‘POST’ or ‘GET’ (the default)
|
|
18
|
+
* $encoding: ‘JSON’ or x-www-form-urlencoded (the default)
|
|
19
|
+
* $data: contains the data to be sent to the server
|
|
20
|
+
*
|
|
21
|
+
* Installation:
|
|
22
|
+
* const ajaxAdapter = config.getAdapterInstance<AjaxAdapter>('ajax');
|
|
23
|
+
* AjaxPostWrapper.wrapAjax(ajaxAdapter);
|
|
24
|
+
*
|
|
25
|
+
* Breeze 3 needs no ajax adapter, so there is one to wrap only if you registered one with
|
|
26
|
+
* configureBreeze({ ajax: MyAdapter }). Otherwise wrap your own fetch function instead.
|
|
27
|
+
*
|
|
28
|
+
* Example:
|
|
29
|
+
* const query = EntityQuery.from('SimilarCustomersPOST')
|
|
30
|
+
* .toType(Customer)
|
|
31
|
+
* .withParameters({
|
|
32
|
+
* $method: 'POST',
|
|
33
|
+
* $encoding: 'JSON',
|
|
34
|
+
* $data: { companyName: 'Hilo Hattie', contactName: 'Donald', city: 'Duck', country: 'USA', phone: '808-234-5678' }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
export declare class AjaxPostWrapper {
|
|
39
|
+
static wrapAjax(ajaxAdapter: breeze.AjaxAdapter): void;
|
|
40
|
+
}
|