breeze-client 2.1.6 → 2.1.7
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/breeze-client.metadata.json +1 -1
- package/bundles/breeze-client.umd.js +88 -38
- package/bundles/breeze-client.umd.js.map +1 -1
- package/bundles/breeze-client.umd.min.js +1 -1
- package/bundles/breeze-client.umd.min.js.map +1 -1
- package/esm2015/src/abstract-data-service-adapter.js +68 -37
- package/esm2015/src/entity-query.js +23 -4
- package/esm5/src/abstract-data-service-adapter.js +68 -37
- package/esm5/src/entity-query.js +23 -4
- package/fesm2015/breeze-client.js +88 -38
- package/fesm2015/breeze-client.js.map +1 -1
- package/fesm5/breeze-client.js +88 -38
- package/fesm5/breeze-client.js.map +1 -1
- package/package.json +1 -1
- package/src/abstract-data-service-adapter.d.ts +20 -0
- package/src/entity-query.d.ts +17 -3
|
@@ -5004,6 +5004,7 @@ class EntityQuery {
|
|
|
5004
5004
|
this.parameters = {};
|
|
5005
5005
|
this.inlineCountEnabled = false;
|
|
5006
5006
|
this.noTrackingEnabled = false;
|
|
5007
|
+
this.usePostEnabled = false;
|
|
5007
5008
|
// default is to get queryOptions and dataService from the entityManager.
|
|
5008
5009
|
// this.queryOptions = new QueryOptions();
|
|
5009
5010
|
// this.dataService = new DataService();
|
|
@@ -5273,7 +5274,7 @@ class EntityQuery {
|
|
|
5273
5274
|
return clone(this, "parameters", parameters);
|
|
5274
5275
|
}
|
|
5275
5276
|
/**
|
|
5276
|
-
Returns a query with the
|
|
5277
|
+
Returns a query with the `inlineCount` capability either enabled or disabled. With `inlineCount` enabled, an additional 'inlineCount' property
|
|
5277
5278
|
will be returned with the query results that will contain the number of entities that would have been returned by this
|
|
5278
5279
|
query with only the 'where'/'filter' clauses applied, i.e. without any 'skip'/'take' operators applied. For local queries this clause is ignored.
|
|
5279
5280
|
> let query = new EntityQuery("Customers")
|
|
@@ -5281,7 +5282,7 @@ class EntityQuery {
|
|
|
5281
5282
|
> .orderBy("CompanyName")
|
|
5282
5283
|
> .inlineCount(true);
|
|
5283
5284
|
|
|
5284
|
-
will return the first 20 customers as well as a count of
|
|
5285
|
+
will return the first 20 customers as well as a count of _all_ of the customers in the remote store.
|
|
5285
5286
|
@param enabled - (default = true) Whether or not inlineCount capability should be enabled. If this parameter is omitted, true is assumed.
|
|
5286
5287
|
**/
|
|
5287
5288
|
inlineCount(enabled) {
|
|
@@ -5295,7 +5296,7 @@ class EntityQuery {
|
|
|
5295
5296
|
return clone(this, "usesNameOnServer", usesNameOnServer);
|
|
5296
5297
|
}
|
|
5297
5298
|
/**
|
|
5298
|
-
Returns a query with the
|
|
5299
|
+
Returns a query with the `noTracking` capability either enabled or disabled. With `noTracking` enabled, the results of this query
|
|
5299
5300
|
will not be coerced into entities but will instead look like raw javascript projections. i.e. simple javascript objects.
|
|
5300
5301
|
> let query = new EntityQuery("Customers")
|
|
5301
5302
|
> .take(20)
|
|
@@ -5309,6 +5310,22 @@ class EntityQuery {
|
|
|
5309
5310
|
return clone(this, "noTrackingEnabled", enabled);
|
|
5310
5311
|
}
|
|
5311
5312
|
/**
|
|
5313
|
+
Returns a query with the `usePost` capability either enabled or disabled. With `usePost` enabled, the query is sent
|
|
5314
|
+
as a POST request (instead of GET) and the query expression will be sent as JSON in the body of the post.
|
|
5315
|
+
Note that the server must be able to parse the body of the request; otherwise the query expression will be ignored.
|
|
5316
|
+
> let query = new EntityQuery("Customers")
|
|
5317
|
+
> .where("companyId", "eq", 1)
|
|
5318
|
+
> .usePost(true);
|
|
5319
|
+
results in a POST request to `{host}/{path}/Customers`
|
|
5320
|
+
with body `{"where": {"companyId":{"eq":1}}}`
|
|
5321
|
+
@param enabled - (default = true) Whether or not usePost should be enabled. If this parameter is omitted, true is assumed.
|
|
5322
|
+
**/
|
|
5323
|
+
usePost(enabled) {
|
|
5324
|
+
assertParam(enabled, "enabled").isBoolean().isOptional().check();
|
|
5325
|
+
enabled = (enabled === undefined) ? true : !!enabled;
|
|
5326
|
+
return clone(this, "usePostEnabled", enabled);
|
|
5327
|
+
}
|
|
5328
|
+
/**
|
|
5312
5329
|
Returns a copy of this EntityQuery with the specified [[EntityManager]], [[DataService]],
|
|
5313
5330
|
[[JsonResultsAdapter]], [[MergeStrategy]] or [[FetchStrategy]] applied.
|
|
5314
5331
|
> // 'using' can be used to return a new query with a specified EntityManager.
|
|
@@ -5620,6 +5637,7 @@ function fromJSON(eq, json) {
|
|
|
5620
5637
|
},
|
|
5621
5638
|
"inlineCountEnabled,inlineCount": false,
|
|
5622
5639
|
"noTrackingEnabled,noTracking": false,
|
|
5640
|
+
"usePostEnabled,usePost": false,
|
|
5623
5641
|
queryOptions: function (v) {
|
|
5624
5642
|
return v ? QueryOptions.fromJSON(v) : undefined;
|
|
5625
5643
|
}
|
|
@@ -5644,6 +5662,7 @@ function clone(eq, propName, value) {
|
|
|
5644
5662
|
"expandClause",
|
|
5645
5663
|
"inlineCountEnabled",
|
|
5646
5664
|
"noTrackingEnabled",
|
|
5665
|
+
"usePostEnabled",
|
|
5647
5666
|
"usesNameOnServer",
|
|
5648
5667
|
"queryOptions",
|
|
5649
5668
|
"entityManager",
|
|
@@ -9918,51 +9937,82 @@ class AbstractDataServiceAdapter {
|
|
|
9918
9937
|
});
|
|
9919
9938
|
return promise;
|
|
9920
9939
|
}
|
|
9940
|
+
/** Execute the query in the mappingContext using the ajaxImpl. */
|
|
9921
9941
|
executeQuery(mappingContext) {
|
|
9922
9942
|
mappingContext.adapter = this;
|
|
9943
|
+
const usePost = mappingContext.query.usePostEnabled;
|
|
9944
|
+
const params = usePost ? this._makeQueryPostParams(mappingContext) : this._makeQueryGetParams(mappingContext);
|
|
9923
9945
|
let promise = new Promise((resolve, reject) => {
|
|
9924
|
-
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
try {
|
|
9933
|
-
let rData;
|
|
9934
|
-
let results = data && (data.results || data.Results);
|
|
9935
|
-
if (results) {
|
|
9936
|
-
rData = { results: results, inlineCount: data.inlineCount || data.InlineCount,
|
|
9937
|
-
httpResponse: httpResponse, query: mappingContext.query };
|
|
9938
|
-
}
|
|
9939
|
-
else {
|
|
9940
|
-
rData = { results: data, httpResponse: httpResponse, query: mappingContext.query };
|
|
9941
|
-
}
|
|
9942
|
-
resolve(rData);
|
|
9946
|
+
params.success = function (httpResponse) {
|
|
9947
|
+
let data = httpResponse.data;
|
|
9948
|
+
try {
|
|
9949
|
+
let rData;
|
|
9950
|
+
let results = data && (data.results || data.Results);
|
|
9951
|
+
if (results) {
|
|
9952
|
+
rData = { results: results, inlineCount: data.inlineCount || data.InlineCount,
|
|
9953
|
+
httpResponse: httpResponse, query: mappingContext.query };
|
|
9943
9954
|
}
|
|
9944
|
-
|
|
9945
|
-
|
|
9946
|
-
reject(e);
|
|
9947
|
-
}
|
|
9948
|
-
else {
|
|
9949
|
-
handleHttpError(reject, httpResponse);
|
|
9950
|
-
}
|
|
9955
|
+
else {
|
|
9956
|
+
rData = { results: data, httpResponse: httpResponse, query: mappingContext.query };
|
|
9951
9957
|
}
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9958
|
+
resolve(rData);
|
|
9959
|
+
}
|
|
9960
|
+
catch (e) {
|
|
9961
|
+
if (e instanceof Error) {
|
|
9962
|
+
reject(e);
|
|
9963
|
+
}
|
|
9964
|
+
else {
|
|
9965
|
+
handleHttpError(reject, httpResponse);
|
|
9966
|
+
}
|
|
9967
|
+
}
|
|
9968
|
+
};
|
|
9969
|
+
params.error = function (httpResponse) {
|
|
9970
|
+
handleHttpError(reject, httpResponse);
|
|
9957
9971
|
};
|
|
9958
|
-
if (mappingContext.dataService.useJsonp) {
|
|
9959
|
-
params.dataType = 'jsonp';
|
|
9960
|
-
params.crossDomain = true;
|
|
9961
|
-
}
|
|
9962
9972
|
this.ajaxImpl.ajax(params);
|
|
9963
9973
|
});
|
|
9964
9974
|
return promise;
|
|
9965
9975
|
}
|
|
9976
|
+
/** Set up ajax parameters for query GET. This puts the query into the request querystring in either JSON or OData-style syntax, depending upon the UriBuilder. */
|
|
9977
|
+
_makeQueryGetParams(mappingContext) {
|
|
9978
|
+
const url = mappingContext.getUrl();
|
|
9979
|
+
const params = {
|
|
9980
|
+
type: "GET",
|
|
9981
|
+
url: url,
|
|
9982
|
+
params: mappingContext.query.parameters,
|
|
9983
|
+
dataType: 'json',
|
|
9984
|
+
crossDomain: false,
|
|
9985
|
+
};
|
|
9986
|
+
if (mappingContext.dataService.useJsonp) {
|
|
9987
|
+
params.dataType = 'jsonp';
|
|
9988
|
+
params.crossDomain = true;
|
|
9989
|
+
}
|
|
9990
|
+
return params;
|
|
9991
|
+
}
|
|
9992
|
+
/** Set up ajax parameters for query POST. This put the query into the request body as JSON. */
|
|
9993
|
+
_makeQueryPostParams(mappingContext) {
|
|
9994
|
+
const entityQuery = mappingContext.query;
|
|
9995
|
+
const metadataStore = mappingContext.entityManager.metadataStore;
|
|
9996
|
+
const url = mappingContext.dataService.qualifyUrl(entityQuery.resourceName);
|
|
9997
|
+
let entityType = entityQuery._getFromEntityType(metadataStore, false);
|
|
9998
|
+
if (!entityType) {
|
|
9999
|
+
entityType = new EntityType(metadataStore);
|
|
10000
|
+
}
|
|
10001
|
+
const json = entityQuery.toJSONExt({ entityType: entityType, toNameOnServer: true });
|
|
10002
|
+
json.from = undefined;
|
|
10003
|
+
json.queryOptions = undefined;
|
|
10004
|
+
const params = {
|
|
10005
|
+
type: "POST",
|
|
10006
|
+
url: url,
|
|
10007
|
+
params: mappingContext.query.parameters,
|
|
10008
|
+
dataType: 'json',
|
|
10009
|
+
processData: false,
|
|
10010
|
+
contentType: "application/json; charset=UTF-8",
|
|
10011
|
+
data: JSON.stringify(json),
|
|
10012
|
+
crossDomain: false,
|
|
10013
|
+
};
|
|
10014
|
+
return params;
|
|
10015
|
+
}
|
|
9966
10016
|
saveChanges(saveContext, saveBundle) {
|
|
9967
10017
|
let adapter = saveContext.adapter = this;
|
|
9968
10018
|
let saveBundleSer = adapter._prepareSaveBundle(saveContext, saveBundle);
|