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,246 @@
|
|
|
1
|
+
import { assertConfig } from '../core/assert-param.js';
|
|
2
|
+
import { config } from '../config/config.js';
|
|
3
|
+
import { core, stringEndsWith } from '../core/core.js';
|
|
4
|
+
/**
|
|
5
|
+
A DataService instance is used to encapsulate the details of a single 'service'; this includes a serviceName, a dataService adapterInstance,
|
|
6
|
+
and whether the service has server side metadata.
|
|
7
|
+
|
|
8
|
+
You can construct an EntityManager with either a serviceName or a DataService instance, if you use a serviceName then a DataService
|
|
9
|
+
is constructed for you. (It can also be set via the EntityManager.setProperties method).
|
|
10
|
+
|
|
11
|
+
The same applies to the MetadataStore.fetchMetadata method, i.e. it takes either a serviceName or a DataService instance.
|
|
12
|
+
|
|
13
|
+
Each metadataStore contains a list of DataServices, each accessible via its ‘serviceName’.
|
|
14
|
+
( see MetadataStore.getDataService and MetadataStore.addDataService). The ‘addDataService’ method is called internally
|
|
15
|
+
anytime a MetadataStore.fetchMetadata call occurs with a new dataService ( or service name).
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
export class DataService {
|
|
19
|
+
/** DataService constructor
|
|
20
|
+
```ts
|
|
21
|
+
var dataService = new DataService({
|
|
22
|
+
serviceName: altServiceName,
|
|
23
|
+
hasServerMetadata: false
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
var metadataStore = new MetadataStore({
|
|
29
|
+
namingConvention: NamingConvention.camelCase
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
return new EntityManager({
|
|
35
|
+
dataService: dataService,
|
|
36
|
+
metadataStore: metadataStore
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
@param config - A configuration object.
|
|
40
|
+
*/
|
|
41
|
+
constructor(config) {
|
|
42
|
+
updateWithConfig(this, config);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
Returns a copy of this DataService with the specified properties applied.
|
|
46
|
+
@param config - The configuration object to apply to create a new DataService.
|
|
47
|
+
*/
|
|
48
|
+
using(config) {
|
|
49
|
+
if (!config)
|
|
50
|
+
return this;
|
|
51
|
+
let result = new DataService(this);
|
|
52
|
+
return updateWithConfig(result, config);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
Combines several DataServices into one, taking each property from the first of them that has it
|
|
56
|
+
set, and filling in the adapters: the named ones, or the defaults. Breeze uses it to combine a
|
|
57
|
+
query's or save's own DataService with the EntityManager's before each request; applications do
|
|
58
|
+
not normally need it.
|
|
59
|
+
@param dataServices - The DataServices to combine, most specific first. Entries may be null or
|
|
60
|
+
undefined. The array is modified.
|
|
61
|
+
@throws if none of them has a `serviceName`.
|
|
62
|
+
*/
|
|
63
|
+
static resolve(dataServices) {
|
|
64
|
+
// final defaults
|
|
65
|
+
// Deliberate use of 'as any' below.
|
|
66
|
+
dataServices.push({
|
|
67
|
+
hasServerMetadata: true,
|
|
68
|
+
useJsonp: false
|
|
69
|
+
});
|
|
70
|
+
let ds = new DataService(core.resolveProperties(dataServices, ["serviceName", "adapterName", "uriBuilderName", "hasServerMetadata", "jsonResultsAdapter", "useJsonp"]));
|
|
71
|
+
if (!ds.serviceName) {
|
|
72
|
+
throw new Error("Unable to resolve a 'serviceName' for this dataService");
|
|
73
|
+
}
|
|
74
|
+
ds.adapterInstance = ds.adapterInstance || config.getAdapterInstance("dataService", ds.adapterName);
|
|
75
|
+
ds.jsonResultsAdapter = ds.jsonResultsAdapter || ds.adapterInstance.jsonResultsAdapter;
|
|
76
|
+
ds.uriBuilder = ds.uriBuilder || config.getAdapterInstance("uriBuilder", ds.uriBuilderName);
|
|
77
|
+
return ds;
|
|
78
|
+
}
|
|
79
|
+
/** @hidden @internal */
|
|
80
|
+
static _normalizeServiceName(serviceName) {
|
|
81
|
+
serviceName = serviceName.trim();
|
|
82
|
+
if (serviceName.substr(-1) !== "/") {
|
|
83
|
+
return serviceName + '/';
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return serviceName;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
Returns the serializable form of this DataService: `serviceName`, `adapterName`,
|
|
91
|
+
`uriBuilderName`, `hasServerMetadata`, `useJsonp` and the `name` of its `jsonResultsAdapter`,
|
|
92
|
+
leaving out any that are not set. `JSON.stringify` calls it when `MetadataStore.exportMetadata`
|
|
93
|
+
and `EntityManager.exportEntities` serialize their DataServices; {@link DataService.fromJSON}
|
|
94
|
+
reads it back.
|
|
95
|
+
*/
|
|
96
|
+
toJSON() {
|
|
97
|
+
// don't use default value here - because we want to be able to distinguish undefined props for inheritence purposes.
|
|
98
|
+
return core.toJson(this, {
|
|
99
|
+
serviceName: null,
|
|
100
|
+
adapterName: null,
|
|
101
|
+
uriBuilderName: null,
|
|
102
|
+
hasServerMetadata: null,
|
|
103
|
+
jsonResultsAdapter: function (v) {
|
|
104
|
+
return v && v.name;
|
|
105
|
+
},
|
|
106
|
+
useJsonp: null
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
Creates a DataService from the output of {@link DataService.toJSON}. Used when importing metadata
|
|
111
|
+
and exported entities. The `jsonResultsAdapter` name is looked up among the
|
|
112
|
+
{@link JsonResultsAdapter}s created so far, so create a custom one before importing.
|
|
113
|
+
@param json - A serialized DataService. Its `jsonResultsAdapter` property is replaced.
|
|
114
|
+
@throws if the named `jsonResultsAdapter` does not exist.
|
|
115
|
+
*/
|
|
116
|
+
static fromJSON(json) {
|
|
117
|
+
json.jsonResultsAdapter = config._fetchObject(JsonResultsAdapter, json.jsonResultsAdapter);
|
|
118
|
+
return new DataService(json);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
Returns a url for this dataService with the specified suffix. This method handles dataService names either
|
|
122
|
+
with or without trailing '/'s. If the suffix starts with "http" then it will be returned as-is.
|
|
123
|
+
@param suffix {String} The resulting url.
|
|
124
|
+
@returns {a Url string}
|
|
125
|
+
*/
|
|
126
|
+
qualifyUrl(suffix) {
|
|
127
|
+
if (suffix && suffix.startsWith("http")) {
|
|
128
|
+
return suffix;
|
|
129
|
+
}
|
|
130
|
+
let url = this.serviceName;
|
|
131
|
+
// remove any trailing "/"
|
|
132
|
+
if (stringEndsWith(url, "/")) {
|
|
133
|
+
url = url.substr(0, url.length - 1);
|
|
134
|
+
}
|
|
135
|
+
// ensure that it ends with "/" + suffix
|
|
136
|
+
suffix = "/" + suffix;
|
|
137
|
+
if (!stringEndsWith(url, suffix)) {
|
|
138
|
+
url = url + suffix;
|
|
139
|
+
}
|
|
140
|
+
return url;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
DataService.prototype._$typeName = "DataService";
|
|
144
|
+
function updateWithConfig(obj, dsConfig) {
|
|
145
|
+
if (dsConfig) {
|
|
146
|
+
assertConfig(dsConfig)
|
|
147
|
+
.whereParam("serviceName").isOptional()
|
|
148
|
+
.whereParam("adapterName").isString().isOptional()
|
|
149
|
+
.whereParam("uriBuilderName").isString().isOptional()
|
|
150
|
+
.whereParam("hasServerMetadata").isBoolean().isOptional()
|
|
151
|
+
.whereParam("jsonResultsAdapter").isInstanceOf(JsonResultsAdapter).isOptional()
|
|
152
|
+
.whereParam("useJsonp").isBoolean().isOptional()
|
|
153
|
+
.applyAll(obj);
|
|
154
|
+
obj.serviceName = obj.serviceName && DataService._normalizeServiceName(obj.serviceName);
|
|
155
|
+
obj.adapterInstance = obj.adapterName ? config.getAdapterInstance("dataService", obj.adapterName) : undefined;
|
|
156
|
+
obj.uriBuilder = obj.uriBuilderName ? config.getAdapterInstance("uriBuilder", obj.uriBuilderName) : undefined;
|
|
157
|
+
}
|
|
158
|
+
return obj;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
A JsonResultsAdapter instance is used to provide custom extraction and parsing logic on the json results returned by any web service.
|
|
162
|
+
This facility makes it possible for breeze to talk to virtually any web service and return objects that will be first class 'breeze' citizens.
|
|
163
|
+
*/
|
|
164
|
+
export class JsonResultsAdapter {
|
|
165
|
+
/** The name of this adapter. This name is used to uniquely identify and locate this instance when an 'exported' JsonResultsAdapter is later imported. */
|
|
166
|
+
name;
|
|
167
|
+
/** A Function that is called once per query operation to extract the 'payload' from any json received over the wire.
|
|
168
|
+
This method has a default implementation which simply returns the "results" property from any json returned as a result of executing the query. */
|
|
169
|
+
extractResults; // TODO - refine
|
|
170
|
+
/** A function that is called once per save operation to extract the entities from any json received over the wire. Must return an array.
|
|
171
|
+
This method has a default implementation which simply returns the "entities" property from any json returned as a result of executing the save. */
|
|
172
|
+
extractSaveResults;
|
|
173
|
+
/** A function that is called once per save operation to extract the key mappings from any json received over the wire. Must return an array.
|
|
174
|
+
This method has a default implementation which simply returns the "keyMappings" property from any json returned as a result of executing the save. */
|
|
175
|
+
extractKeyMappings;
|
|
176
|
+
/** A function that is called once per save operation to extract any deleted keys from any json received over the wire. Must return an array.
|
|
177
|
+
This method has a default implementation which is to simply returns the "deletedKeys" property from any json returned as a result of executing the save. */
|
|
178
|
+
extractDeletedKeys; // TODO: refine
|
|
179
|
+
/** A visitor method that will be called on each node of the returned payload. */
|
|
180
|
+
visitNode;
|
|
181
|
+
/**
|
|
182
|
+
JsonResultsAdapter constructor
|
|
183
|
+
|
|
184
|
+
@example
|
|
185
|
+
//
|
|
186
|
+
var jsonResultsAdapter = new JsonResultsAdapter({
|
|
187
|
+
name: "test1e",
|
|
188
|
+
extractResults: function(json) {
|
|
189
|
+
return json.results;
|
|
190
|
+
},
|
|
191
|
+
visitNode: function(node, mappingContext, nodeContext) {
|
|
192
|
+
var entityType = normalizeTypeName(node.$type);
|
|
193
|
+
var propertyName = nodeContext.propertyName;
|
|
194
|
+
var ignore = propertyName && propertyName.substr(0, 1) === "$";
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
entityType: entityType,
|
|
198
|
+
nodeId: node.$id,
|
|
199
|
+
nodeRefId: node.$ref,
|
|
200
|
+
ignore: ignore,
|
|
201
|
+
passThru: false // default
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
var dataService = new DataService( {
|
|
207
|
+
serviceName: "breeze/foo",
|
|
208
|
+
jsonResultsAdapter: jsonResultsAdapter
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
var entityManager = new EntityManager( {
|
|
212
|
+
dataService: dataService
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
@param jsConfig - A configuration object.
|
|
216
|
+
|
|
217
|
+
*/
|
|
218
|
+
constructor(jsConfig) {
|
|
219
|
+
if (arguments.length !== 1) {
|
|
220
|
+
throw new Error("The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.");
|
|
221
|
+
}
|
|
222
|
+
assertConfig(jsConfig)
|
|
223
|
+
.whereParam("name").isNonEmptyString()
|
|
224
|
+
.whereParam("extractResults").isFunction().isOptional().withDefault(extractResultsDefault)
|
|
225
|
+
.whereParam("extractSaveResults").isFunction().isOptional().withDefault(extractSaveResultsDefault)
|
|
226
|
+
.whereParam("extractKeyMappings").isFunction().isOptional().withDefault(extractKeyMappingsDefault)
|
|
227
|
+
.whereParam("extractDeletedKeys").isFunction().isOptional().withDefault(extractDeletedKeysDefault)
|
|
228
|
+
.whereParam("visitNode").isFunction()
|
|
229
|
+
.applyAll(this);
|
|
230
|
+
config._storeObject(this, "JsonResultsAdapter", this.name);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
JsonResultsAdapter.prototype._$typeName = "JsonResultsAdapter";
|
|
234
|
+
function extractResultsDefault(data) {
|
|
235
|
+
return data.results;
|
|
236
|
+
}
|
|
237
|
+
function extractSaveResultsDefault(data) {
|
|
238
|
+
return data.entities || data.Entities || [];
|
|
239
|
+
}
|
|
240
|
+
function extractKeyMappingsDefault(data) {
|
|
241
|
+
return data.keyMappings || data.KeyMappings || [];
|
|
242
|
+
}
|
|
243
|
+
function extractDeletedKeysDefault(data) {
|
|
244
|
+
return data.deletedKeys || data.DeletedKeys || [];
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=data-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-service.js","sourceRoot":"","sources":["../../src/metadata/data-service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,O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AI,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;CAEF;AACD,kBAAkB,CAAC,SAAS,CAAC,UAAU,GAAG,oBAAoB,CAAC;AAE/D,SAAS,qBAAqB,CAAC,IAAS;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAS;IAC1C,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;AAC9C,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAS;IAC1C,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAS;IAC1C,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import { EntityType, NavigationProperty } from './entity-metadata.js';\nimport { DataServiceAdapter, UriBuilderAdapter } from '../config/interface-registry.js';\nimport { KeyMapping } from '../manager/entity-manager.js';\nimport { MappingContext } from '../query/mapping-context.js';\nimport { assertConfig } from '../core/assert-param.js';\nimport { config } from '../config/config.js';\nimport { core, stringEndsWith } from '../core/core.js';\n\n/** Configuration info to be passed to the {@link DataService} constructor */\nexport interface DataServiceConfig {\n /** The serviceName for this DataService. */\n serviceName?: string;\n /** The adapter name for the {@link DataServiceAdapter} to be used with this service. */\n adapterName?: string;\n /** The adapter name for the {@link UriBuilderAdapter} to be used with this service. */\n uriBuilderName?: string;\n /** Whether the server can provide metadata for this service. */\n hasServerMetadata?: boolean;\n /** The {@link JsonResultsAdapter} used to process the results of any query against this DataService. */\n jsonResultsAdapter?: JsonResultsAdapter;\n /** Whether to use JSONP when performing a 'GET' request against this service.\n @deprecated No effect on Breeze's own transport, which has no JSONP support. Kept because it is\n part of a serialized DataService, and because a registered (deprecated) ajax adapter can still\n act on the dataType and crossDomain settings it produces. */\n useJsonp?: boolean;\n}\n/**\nA DataService instance is used to encapsulate the details of a single 'service'; this includes a serviceName, a dataService adapterInstance,\nand whether the service has server side metadata.\n\nYou can construct an EntityManager with either a serviceName or a DataService instance, if you use a serviceName then a DataService\nis constructed for you. (It can also be set via the EntityManager.setProperties method).\n\nThe same applies to the MetadataStore.fetchMetadata method, i.e. it takes either a serviceName or a DataService instance.\n\nEach metadataStore contains a list of DataServices, each accessible via its ‘serviceName’.\n( see MetadataStore.getDataService and MetadataStore.addDataService). The ‘addDataService’ method is called internally\nanytime a MetadataStore.fetchMetadata call occurs with a new dataService ( or service name).\n\n*/\nexport class DataService {\n /** @hidden @internal */\n declare _$typeName: string; // actually put on prototype.\n /** The serviceName for this DataService. __Read Only__ */\n declare serviceName: string;\n /** The adapter name for the {@link DataServiceAdapter} to be used with this service. __Read Only__ */\n declare adapterName: string;\n /** The {@link DataServiceAdapter} implementation instance associated with this EntityManager. __Read Only__ */\n declare adapterInstance?: DataServiceAdapter;\n /** The adapter name for the {@link UriBuilderAdapter} to be used with this service. __Read Only__ */\n declare uriBuilderName: string;\n /** The {@link UriBuilderAdapter} implementation instance associated with this EntityManager. __Read Only__ */\n declare uriBuilder?: UriBuilderAdapter;\n /** Whether the server can provide metadata for this service. __Read Only__ */\n declare hasServerMetadata: boolean;\n /** The {@link JsonResultsAdapter} used to process the results of any query against this DataService. __Read Only__ */\n declare jsonResultsAdapter: JsonResultsAdapter;\n /** Whether to use JSONP when performing a 'GET' request against this service. __Read Only__\n @deprecated No effect on Breeze's own transport, which has no JSONP support. Kept because it is\n part of a serialized DataService, and because a registered (deprecated) ajax adapter can still\n act on the dataType and crossDomain settings it produces. */\n declare useJsonp: boolean;\n\n /** DataService constructor\n ```ts\n var dataService = new DataService({\n serviceName: altServiceName,\n hasServerMetadata: false\n });\n ```\n\n ```ts\n var metadataStore = new MetadataStore({\n namingConvention: NamingConvention.camelCase\n });\n ```\n\n ```ts\n return new EntityManager({\n dataService: dataService,\n metadataStore: metadataStore\n });\n ```\n @param config - A configuration object.\n */\n constructor(config?: DataServiceConfig) {\n updateWithConfig(this, config);\n }\n\n\n /**\n Returns a copy of this DataService with the specified properties applied.\n @param config - The configuration object to apply to create a new DataService.\n */\n using(config: DataServiceConfig) {\n if (!config) return this;\n let result = new DataService(this);\n return updateWithConfig(result, config);\n }\n\n /**\n Combines several DataServices into one, taking each property from the first of them that has it\n set, and filling in the adapters: the named ones, or the defaults. Breeze uses it to combine a\n query's or save's own DataService with the EntityManager's before each request; applications do\n not normally need it.\n @param dataServices - The DataServices to combine, most specific first. Entries may be null or\n undefined. The array is modified.\n @throws if none of them has a `serviceName`.\n */\n static resolve(dataServices: DataService[]) {\n // final defaults\n // Deliberate use of 'as any' below.\n (dataServices as any).push({\n hasServerMetadata: true,\n useJsonp: false\n });\n let ds = new DataService(core.resolveProperties(dataServices,\n [\"serviceName\", \"adapterName\", \"uriBuilderName\", \"hasServerMetadata\", \"jsonResultsAdapter\", \"useJsonp\"]));\n\n if (!ds.serviceName) {\n throw new Error(\"Unable to resolve a 'serviceName' for this dataService\");\n }\n ds.adapterInstance = ds.adapterInstance || config.getAdapterInstance<DataServiceAdapter>(\"dataService\", ds.adapterName);\n ds.jsonResultsAdapter = ds.jsonResultsAdapter || ds.adapterInstance!.jsonResultsAdapter;\n ds.uriBuilder = ds.uriBuilder || config.getAdapterInstance<UriBuilderAdapter>(\"uriBuilder\", ds.uriBuilderName);\n return ds;\n }\n\n /** @hidden @internal */\n static _normalizeServiceName(serviceName: string) {\n serviceName = serviceName.trim();\n if (serviceName.substr(-1) !== \"/\") {\n return serviceName + '/';\n } else {\n return serviceName;\n }\n }\n\n /**\n Returns the serializable form of this DataService: `serviceName`, `adapterName`,\n `uriBuilderName`, `hasServerMetadata`, `useJsonp` and the `name` of its `jsonResultsAdapter`,\n leaving out any that are not set. `JSON.stringify` calls it when `MetadataStore.exportMetadata`\n and `EntityManager.exportEntities` serialize their DataServices; {@link DataService.fromJSON}\n reads it back.\n */\n toJSON() {\n // don't use default value here - because we want to be able to distinguish undefined props for inheritence purposes.\n return core.toJson(this, {\n serviceName: null,\n adapterName: null,\n uriBuilderName: null,\n hasServerMetadata: null,\n jsonResultsAdapter: function (v: any) {\n return v && v.name;\n },\n useJsonp: null\n });\n }\n\n /**\n Creates a DataService from the output of {@link DataService.toJSON}. Used when importing metadata\n and exported entities. The `jsonResultsAdapter` name is looked up among the\n {@link JsonResultsAdapter}s created so far, so create a custom one before importing.\n @param json - A serialized DataService. Its `jsonResultsAdapter` property is replaced.\n @throws if the named `jsonResultsAdapter` does not exist.\n */\n static fromJSON(json: any) {\n json.jsonResultsAdapter = config._fetchObject(JsonResultsAdapter, json.jsonResultsAdapter);\n return new DataService(json);\n }\n\n /**\n Returns a url for this dataService with the specified suffix. This method handles dataService names either\n with or without trailing '/'s. If the suffix starts with \"http\" then it will be returned as-is.\n @param suffix {String} The resulting url.\n @returns {a Url string}\n */\n qualifyUrl(suffix: string) {\n if (suffix && suffix.startsWith(\"http\")) {\n return suffix;\n }\n let url = this.serviceName;\n // remove any trailing \"/\"\n if (stringEndsWith(url, \"/\")) {\n url = url.substr(0, url.length - 1);\n }\n // ensure that it ends with \"/\" + suffix\n suffix = \"/\" + suffix;\n if (!stringEndsWith(url, suffix)) {\n url = url + suffix;\n }\n return url;\n }\n\n}\nDataService.prototype._$typeName = \"DataService\";\n\nfunction updateWithConfig(obj: DataService, dsConfig?: DataServiceConfig) {\n if (dsConfig) {\n assertConfig(dsConfig)\n .whereParam(\"serviceName\").isOptional()\n .whereParam(\"adapterName\").isString().isOptional()\n .whereParam(\"uriBuilderName\").isString().isOptional()\n .whereParam(\"hasServerMetadata\").isBoolean().isOptional()\n .whereParam(\"jsonResultsAdapter\").isInstanceOf(JsonResultsAdapter).isOptional()\n .whereParam(\"useJsonp\").isBoolean().isOptional()\n .applyAll(obj);\n obj.serviceName = obj.serviceName && DataService._normalizeServiceName(obj.serviceName);\n obj.adapterInstance = obj.adapterName ? config.getAdapterInstance<DataServiceAdapter>(\"dataService\", obj.adapterName) : undefined;\n obj.uriBuilder = obj.uriBuilderName ? config.getAdapterInstance<UriBuilderAdapter>(\"uriBuilder\", obj.uriBuilderName) : undefined;\n }\n return obj;\n}\n\n/**\nWhat a {@link JsonResultsAdapter}'s `visitNode` returns for one node of a query or save result,\ntelling Breeze how to treat it. Every property is optional; returning `{}` (or nothing) treats the\nnode as plain data.\n*/\nexport interface NodeMeta {\n /** The type of entity or complex object this node is, or its name. When set, Breeze materializes the node as an entity of that type and merges it into the cache (unless the query is `noTracking`); a complex type is mapped without merging. For a top-level query result with no type, Breeze uses the query's result type. */\n entityType?: EntityType;\n /** An id for this node, such as a Json.NET `$id`, that other nodes can refer to with `nodeRefId`. */\n nodeId?: string;\n /** The `nodeId` of another node that this node stands for, such as a Json.NET `$ref`. Breeze returns the entity or object read from that node in its place. */\n nodeRefId?: string;\n /** Whether to skip this node. A skipped property is left off the object that holds it; a skipped top-level node is dropped from the results (or is `null` there, when the query includes deleted entities). */\n ignore?: boolean;\n /** Whether to keep the node exactly as the server sent it, without mapping its property names to the client's or visiting what it contains. Ignored for a top-level node that has an `entityType`, which is merged as an entity. */\n passThru?: boolean;\n /** Anything else about the node to keep. Breeze stores it on the entity's `entityAspect.extraMetadata`. */\n extraMetadata?: any;\n /** Use this object in place of the node that was visited. */\n node?: any;\n}\n\n/** Where a node passed to a {@link JsonResultsAdapter}'s `visitNode` sits in the result. */\nexport interface NodeContext {\n /** `\"root\"` for a top-level result, `\"navProp\"` or `\"navPropItem\"` for the value or an item of a navigation property, and `\"anonProp\"` or `\"anonPropItem\"` for the value or an item of a property of a plain (non-entity) object. */\n nodeType: string;\n /** For an `\"anonProp\"` or `\"anonPropItem\"` node, the client name of the property that holds it. */\n propertyName?: string;\n /** For a `\"navProp\"` or `\"navPropItem\"` node, the navigation property that holds it. */\n navigationProperty?: NavigationProperty;\n}\n\n/** Configuration info to be passed to the {@link JsonResultsAdapter} constructor */\nexport interface JsonResultsAdapterConfig {\n /** The name of this adapter. This name is used to uniquely identify and locate this instance when an 'exported' JsonResultsAdapter is later imported. */\n name: string;\n /** A Function that is called once per query operation to extract the 'payload' from any json received over the wire. \n This method has a default implementation which to simply return the \"results\" property from any json returned as a result of executing the query. \n */\n extractResults?: Function;\n /** A function that is called once per save operation to extract the entities from any json received over the wire. Must return an array.\n This method has a default implementation which simply returns the \"entities\" property from any json returned as a result of executing the save. */\n extractSaveResults?: Function;\n /** A function that is called once per save operation to extract the key mappings from any json received over the wire. Must return an array.\n This method has a default implementation which simply returns the \"keyMappings\" property from any json returned as a result of executing the save. */\n extractKeyMappings?: (data: {}) => KeyMapping[];\n /** A function that is called once per save operation to extract any deleted keys from any json received over the wire. Must return an array.\n This method has a default implementation which simply returns an empty array. */\n extractDeletedKeys?: (data: {}) => any[]; // TODO: refine\n /** A visitor method that will be called on each node of the returned payload. Required.\n Breeze always passes all three arguments. Returning nothing is the same as returning `{}`. */\n visitNode: (node: any, mappingContext: MappingContext, nodeContext: NodeContext) => NodeMeta | null | void;\n\n}\n\n/**\nA JsonResultsAdapter instance is used to provide custom extraction and parsing logic on the json results returned by any web service.\nThis facility makes it possible for breeze to talk to virtually any web service and return objects that will be first class 'breeze' citizens.\n*/\nexport class JsonResultsAdapter {\n /** @hidden @internal */\n declare _$typeName: string; // actually put on prototype.\n /** The name of this adapter. This name is used to uniquely identify and locate this instance when an 'exported' JsonResultsAdapter is later imported. */\n name: string;\n /** A Function that is called once per query operation to extract the 'payload' from any json received over the wire. \n This method has a default implementation which simply returns the \"results\" property from any json returned as a result of executing the query. */\n extractResults: Function; // TODO - refine\n /** A function that is called once per save operation to extract the entities from any json received over the wire. Must return an array.\n This method has a default implementation which simply returns the \"entities\" property from any json returned as a result of executing the save. */\n extractSaveResults: Function;\n /** A function that is called once per save operation to extract the key mappings from any json received over the wire. Must return an array.\n This method has a default implementation which simply returns the \"keyMappings\" property from any json returned as a result of executing the save. */\n extractKeyMappings: (data: {}) => KeyMapping[];\n /** A function that is called once per save operation to extract any deleted keys from any json received over the wire. Must return an array.\n This method has a default implementation which is to simply returns the \"deletedKeys\" property from any json returned as a result of executing the save. */\n extractDeletedKeys?: (data: {}) => any[]; // TODO: refine\n /** A visitor method that will be called on each node of the returned payload. */\n visitNode: Function;\n\n /**\n JsonResultsAdapter constructor\n\n @example\n //\n var jsonResultsAdapter = new JsonResultsAdapter({\n name: \"test1e\",\n extractResults: function(json) {\n return json.results;\n },\n visitNode: function(node, mappingContext, nodeContext) {\n var entityType = normalizeTypeName(node.$type);\n var propertyName = nodeContext.propertyName;\n var ignore = propertyName && propertyName.substr(0, 1) === \"$\";\n\n return {\n entityType: entityType,\n nodeId: node.$id,\n nodeRefId: node.$ref,\n ignore: ignore,\n passThru: false // default\n };\n }\n });\n\n var dataService = new DataService( {\n serviceName: \"breeze/foo\",\n jsonResultsAdapter: jsonResultsAdapter\n });\n\n var entityManager = new EntityManager( {\n dataService: dataService\n });\n\n @param jsConfig - A configuration object.\n\n */\n constructor(jsConfig: JsonResultsAdapterConfig) {\n if (arguments.length !== 1) {\n throw new Error(\"The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.\");\n }\n\n assertConfig(jsConfig)\n .whereParam(\"name\").isNonEmptyString()\n .whereParam(\"extractResults\").isFunction().isOptional().withDefault(extractResultsDefault)\n .whereParam(\"extractSaveResults\").isFunction().isOptional().withDefault(extractSaveResultsDefault)\n .whereParam(\"extractKeyMappings\").isFunction().isOptional().withDefault(extractKeyMappingsDefault)\n .whereParam(\"extractDeletedKeys\").isFunction().isOptional().withDefault(extractDeletedKeysDefault)\n .whereParam(\"visitNode\").isFunction()\n .applyAll(this);\n config._storeObject(this, \"JsonResultsAdapter\", this.name);\n }\n\n}\nJsonResultsAdapter.prototype._$typeName = \"JsonResultsAdapter\";\n\nfunction extractResultsDefault(data: any) {\n return data.results;\n}\n\nfunction extractSaveResultsDefault(data: any) {\n return data.entities || data.Entities || [];\n}\n\nfunction extractKeyMappingsDefault(data: any) {\n return data.keyMappings || data.KeyMappings || [];\n}\n\nfunction extractDeletedKeysDefault(data: any) {\n return data.deletedKeys || data.DeletedKeys || [];\n}\n\n"]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { BreezeEnum } from '../core/enum.js';
|
|
2
|
+
import { Validator } from '../validation/validate.js';
|
|
3
|
+
/**
|
|
4
|
+
DataType is an 'Enum' containing all of the supported data types.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DataType extends BreezeEnum {
|
|
7
|
+
/** The default value of this DataType. __Read Only__ */
|
|
8
|
+
defaultValue?: any;
|
|
9
|
+
/** Whether this is a 'numeric' DataType. __Read Only__ */
|
|
10
|
+
isNumeric?: boolean;
|
|
11
|
+
/** Whether this is an 'integer' DataType. __Read Only__ */
|
|
12
|
+
isInteger?: boolean;
|
|
13
|
+
/** The constructor function to create a {@link Validator} to be used in validating instances of this DataType. */
|
|
14
|
+
validatorCtor?(context?: any): Validator;
|
|
15
|
+
/**
|
|
16
|
+
Optional function to normalize a data value for comparison, if its value cannot be used directly.
|
|
17
|
+
Note that this will be called each time a property is changed, so make it fast.
|
|
18
|
+
@returns value appropriate for this DataType
|
|
19
|
+
*/
|
|
20
|
+
normalize?(value: any): any;
|
|
21
|
+
/**
|
|
22
|
+
Optional function to convert a raw (server) value from string to this DataType.
|
|
23
|
+
@returns value appropriate for this DataType
|
|
24
|
+
*/
|
|
25
|
+
parseRawValue?(value: any): any;
|
|
26
|
+
/**
|
|
27
|
+
Optional function to convert a value from string to this DataType. Note that this will be called each time a property is changed, so make it fast.
|
|
28
|
+
@returns value appropriate for this DataType
|
|
29
|
+
*/
|
|
30
|
+
parse?(source: any, sourceTypeName: string): any;
|
|
31
|
+
/**
|
|
32
|
+
Optional function to get the next value for key generation, if this datatype is used as a key. Uses an internal table of previous values.
|
|
33
|
+
@returns value appropriate for this DataType
|
|
34
|
+
*/
|
|
35
|
+
getNext?(): any;
|
|
36
|
+
/**
|
|
37
|
+
Optional function to get the next value when the datatype is used as a concurrency property.
|
|
38
|
+
@param previousValue
|
|
39
|
+
@returns the next concurrency value, which may be a function of the previousValue.
|
|
40
|
+
*/
|
|
41
|
+
getConcurrencyValue?(previousValue?: any): any;
|
|
42
|
+
/**
|
|
43
|
+
The function Breeze converts `DateTime` and `DateTimeOffset` values from the server with, when it
|
|
44
|
+
materializes query and save results. Defaults to {@link DataType.parseDateAsUTC}. Replace it at
|
|
45
|
+
startup, before the first query, to change how a date-time string with no offset is read - for
|
|
46
|
+
example with {@link DataType.parseDateAsLocal}. It does not affect saves, which always send UTC.
|
|
47
|
+
*/
|
|
48
|
+
static parseDateFromServer: (value: any) => any;
|
|
49
|
+
/** A string (.NET `String`; also `Char`). Default `""`. */
|
|
50
|
+
static String: DataType;
|
|
51
|
+
/** A 64-bit integer (.NET `Int64`; also `UInt32` and `UInt64`), held as a JavaScript `number`, so values beyond ±2^53 lose precision. Default `0`. */
|
|
52
|
+
static Int64: DataType;
|
|
53
|
+
/** A 32-bit integer (.NET `Int32`; also `UInt16`), held as a `number`. Default `0`. */
|
|
54
|
+
static Int32: DataType;
|
|
55
|
+
/** A 16-bit integer (.NET `Int16`; also `SByte`), held as a `number`. Default `0`. */
|
|
56
|
+
static Int16: DataType;
|
|
57
|
+
/** An unsigned 8-bit integer, 0 to 255 (.NET `Byte`), held as a `number`. Default `0`. */
|
|
58
|
+
static Byte: DataType;
|
|
59
|
+
/** A decimal number (.NET `Decimal`), held as a JavaScript `number` - a double - so digits beyond its precision are lost. Default `0`. */
|
|
60
|
+
static Decimal: DataType;
|
|
61
|
+
/** A 64-bit floating-point number (.NET `Double`). Also the type Breeze infers for an unmapped property that holds a number. Default `0`. */
|
|
62
|
+
static Double: DataType;
|
|
63
|
+
/** A 32-bit floating-point number (.NET `Single`), held as a `number`. Default `0`. */
|
|
64
|
+
static Single: DataType;
|
|
65
|
+
/** A calendar date with no time (.NET `DateOnly`), held as a `Date` at local midnight. Read from the first ten characters (`YYYY-MM-DD`) of the server's value, sent back as `YYYY-MM-DD` from the local date, and compared by date alone. Default 1 January 1900. */
|
|
66
|
+
static DateOnly: DataType;
|
|
67
|
+
/** A date and time (.NET `DateTime`), held as a `Date`. Read from the server with {@link DataType.parseDateFromServer} and sent as ISO 8601 in UTC. Also the type Breeze infers for an unmapped property that holds a `Date`. Default 1 January 1900, local midnight. */
|
|
68
|
+
static DateTime: DataType;
|
|
69
|
+
/** A date and time with an offset (.NET `DateTimeOffset`), held as a `Date`, which has no offset: it is read with {@link DataType.parseDateFromServer} and sent back in UTC, so the original offset is lost. Default 1 January 1900, local midnight. */
|
|
70
|
+
static DateTimeOffset: DataType;
|
|
71
|
+
/** A duration (.NET `TimeSpan`), held as the ISO 8601 duration string the server sends, such as `PT4H30M`. Compared as a number of seconds in local queries. Default `PT0S`. */
|
|
72
|
+
static Time: DataType;
|
|
73
|
+
/** A time of day (.NET `TimeOnly`), held as the string the server sends: "14:30:00" or "01:23:45.678". */
|
|
74
|
+
static TimeOnly: DataType;
|
|
75
|
+
/** A `true` or `false` value (.NET `Boolean`). Default `false`. */
|
|
76
|
+
static Boolean: DataType;
|
|
77
|
+
/** A GUID (.NET `Guid`), held as a lower-case string. Default `"00000000-0000-0000-0000-000000000000"`. */
|
|
78
|
+
static Guid: DataType;
|
|
79
|
+
/** Binary data (.NET `byte[]`), such as a SQL `rowversion`, held as the base64 string the server sends. Default `null`. */
|
|
80
|
+
static Binary: DataType;
|
|
81
|
+
/** An unknown type: a server type name the client does not recognize (the original is kept in the property's `rawTypeName`), or an unmapped property whose type cannot be inferred. Values are not converted or validated. Default `undefined`. */
|
|
82
|
+
static Undefined: DataType;
|
|
83
|
+
/**
|
|
84
|
+
Returns the function Breeze uses to turn values of a data type into something `===`, `<` and `>`
|
|
85
|
+
compare correctly, in local queries and when ordering: the data type's `normalize` if it has one,
|
|
86
|
+
a conversion to seconds for {@link DataType.Time}, and otherwise the value itself. Applications do
|
|
87
|
+
not normally need it.
|
|
88
|
+
@param dataType - The data type of the values to compare.
|
|
89
|
+
*/
|
|
90
|
+
static getComparableFn(dataType?: DataType): (value: any) => any;
|
|
91
|
+
/**
|
|
92
|
+
Returns the DataType with the specified name, or undefined if there is none. Also accepts the names the .NET
|
|
93
|
+
servers use for some types, such as 'TimeSpan' for {@link DataType.Time}.
|
|
94
|
+
*/
|
|
95
|
+
static fromName(name: string): DataType | undefined;
|
|
96
|
+
/** Returns the DataType for a specified input. */
|
|
97
|
+
static fromValue(val: any): DataType;
|
|
98
|
+
/**
|
|
99
|
+
Converts a {@link DataType.Time} value from the server. By default it returns the value unchanged:
|
|
100
|
+
a `Time` is held as the ISO 8601 duration string the server sends, such as `PT4H30M`. Replace it
|
|
101
|
+
at startup, before the first query, to hold durations some other way - as a number of seconds,
|
|
102
|
+
say, with {@link core.durationToSeconds}.
|
|
103
|
+
*/
|
|
104
|
+
static parseTimeFromServer(source: any): any;
|
|
105
|
+
/**
|
|
106
|
+
Converts a date-time string from the server to a `Date`. This is the default
|
|
107
|
+
{@link DataType.parseDateFromServer}.
|
|
108
|
+
- A string with `Z` or an offset (`2024-03-15T10:30:00Z`, `...10:30:00+02:00`) is read as given.
|
|
109
|
+
- A string with no offset that ends in fractional seconds, of any length
|
|
110
|
+
(`2024-03-15T10:30:00.5`, `...00.000`, `...00.1234567`), is read as UTC: Breeze appends `Z`.
|
|
111
|
+
- Any other string with no offset, such as `2024-03-15T10:30:00`, goes to `Date.parse`
|
|
112
|
+
unchanged, which reads it as **local** time.
|
|
113
|
+
@param source - The value from the server.
|
|
114
|
+
*/
|
|
115
|
+
static parseDateAsUTC(source: any): any;
|
|
116
|
+
/** Parse as UTC then shift to local time */
|
|
117
|
+
static parseDateAsLocal(source: string): any;
|
|
118
|
+
/** if val is a Date, return a date-only string e.g. '2023-12-31' */
|
|
119
|
+
static toDateOnlyString(val: any): any;
|
|
120
|
+
/** Returns a raw value converted to the specified DataType */
|
|
121
|
+
static parseRawValue(val: any, dataType?: DataType): any;
|
|
122
|
+
}
|