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
package/core/core.js
ADDED
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
/** See if this comment will make it into .d.ts */
|
|
2
|
+
import { BreezeEnum } from './enum.js';
|
|
3
|
+
// NOTE: the `|| {}` on every Object.keys call below is load-bearing. These helpers are
|
|
4
|
+
// called with null and undefined by design; the `for...in` loops they replaced treated
|
|
5
|
+
// that as a no-op, whereas Object.keys(null) throws.
|
|
6
|
+
// iterate over object
|
|
7
|
+
function objectForEach(obj, kvFn) {
|
|
8
|
+
const rec = obj;
|
|
9
|
+
for (const key of Object.keys(rec || {})) {
|
|
10
|
+
kvFn(key, rec[key]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function objectMap(obj, kvFn) {
|
|
14
|
+
const rec = obj;
|
|
15
|
+
let results = [];
|
|
16
|
+
for (const key of Object.keys(rec || {})) {
|
|
17
|
+
let result = kvFn ? kvFn(key, rec[key]) : rec[key];
|
|
18
|
+
if (result !== undefined) {
|
|
19
|
+
results.push(result);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
function objectFirst(obj, kvPredicate) {
|
|
25
|
+
const rec = obj;
|
|
26
|
+
for (const key of Object.keys(rec || {})) {
|
|
27
|
+
let value = rec[key];
|
|
28
|
+
if (kvPredicate(key, value)) {
|
|
29
|
+
return { key: key, value: value };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function isSettable(obj, propertyName) {
|
|
35
|
+
let pd = getPropDescriptor(obj, propertyName);
|
|
36
|
+
if (pd == null)
|
|
37
|
+
return true;
|
|
38
|
+
return !!(pd.writable || pd.set);
|
|
39
|
+
}
|
|
40
|
+
function getPropDescriptor(obj, propertyName) {
|
|
41
|
+
if (obj.hasOwnProperty(propertyName)) {
|
|
42
|
+
return Object.getOwnPropertyDescriptor(obj, propertyName);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
let nextObj = Object.getPrototypeOf(obj);
|
|
46
|
+
if (nextObj == null)
|
|
47
|
+
return undefined;
|
|
48
|
+
return getPropDescriptor(nextObj, propertyName);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Functional extensions
|
|
52
|
+
/** can be used like: persons.filter(propEq("firstName", "John")) */
|
|
53
|
+
function propEq(propertyName, value) {
|
|
54
|
+
return function (obj) {
|
|
55
|
+
return obj[propertyName] === value;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** can be used like: persons.filter(propEq("firstName", "FirstName", "John")) */
|
|
59
|
+
function propsEq(property1Name, property2Name, value) {
|
|
60
|
+
return function (obj) {
|
|
61
|
+
return obj[property1Name] === value || obj[property2Name] === value;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** can be used like persons.map(pluck("firstName")) */
|
|
65
|
+
function pluck(propertyName) {
|
|
66
|
+
return function (obj) {
|
|
67
|
+
return obj[propertyName];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// end functional extensions
|
|
71
|
+
/** Return an array of property values from source */
|
|
72
|
+
function getOwnPropertyValues(source) {
|
|
73
|
+
const rec = source;
|
|
74
|
+
let result = [];
|
|
75
|
+
for (const name of Object.keys(rec || {})) {
|
|
76
|
+
result.push(rec[name]);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
/** Copy properties from source to target. Returns target. */
|
|
81
|
+
function extend(target, source, propNames) {
|
|
82
|
+
if (!source)
|
|
83
|
+
return target;
|
|
84
|
+
const tgt = target, src = source;
|
|
85
|
+
if (propNames) {
|
|
86
|
+
propNames.forEach(function (propName) {
|
|
87
|
+
tgt[propName] = src[propName];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
for (const propName of Object.keys(src || {})) {
|
|
92
|
+
tgt[propName] = src[propName];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return target;
|
|
96
|
+
}
|
|
97
|
+
/** Copy properties from defaults iff undefined on target. Returns target. */
|
|
98
|
+
function updateWithDefaults(target, defaults) {
|
|
99
|
+
const tgt = target, def = defaults;
|
|
100
|
+
for (const name of Object.keys(def || {})) {
|
|
101
|
+
if (tgt[name] === undefined) {
|
|
102
|
+
tgt[name] = def[name];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return target;
|
|
106
|
+
}
|
|
107
|
+
/** Set ctor.defaultInstance to an instance of ctor with properties from target.
|
|
108
|
+
We want to insure that the object returned by ctor.defaultInstance is always immutable
|
|
109
|
+
Use 'target' as the primary template for the ctor.defaultInstance;
|
|
110
|
+
Use current 'ctor.defaultInstance' as the template for any missing properties
|
|
111
|
+
creates a new instance for ctor.defaultInstance
|
|
112
|
+
returns target unchanged */
|
|
113
|
+
function setAsDefault(target, ctor) {
|
|
114
|
+
ctor.defaultInstance = updateWithDefaults(new ctor(target), ctor.defaultInstance);
|
|
115
|
+
return target;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
'source' is an object that will be transformed into another
|
|
119
|
+
'template' is a map where the
|
|
120
|
+
keys: are the keys to return
|
|
121
|
+
if a key contains ','s then the key is treated as a delimited string with first of the
|
|
122
|
+
keys being the key to return and the others all valid aliases for this key
|
|
123
|
+
'values' are either
|
|
124
|
+
1) the 'default' value of the key
|
|
125
|
+
2) a function that takes in the source value and should return the value to set
|
|
126
|
+
The value from the source is then set on the target,
|
|
127
|
+
after first passing thru the fn, if provided, UNLESS:
|
|
128
|
+
1) it is the default value
|
|
129
|
+
2) it is undefined ( nulls WILL be set)
|
|
130
|
+
'target' is optional
|
|
131
|
+
- if it exists then properties of the target will be set ( overwritten if the exist)
|
|
132
|
+
- if it does not exist then a new object will be created as filled.
|
|
133
|
+
'target is returned.
|
|
134
|
+
*/
|
|
135
|
+
function toJson(source, template, target = {}) {
|
|
136
|
+
const src = source, tmpl = template, tgt = target;
|
|
137
|
+
for (const key of Object.keys(tmpl || {})) {
|
|
138
|
+
let aliases = key.split(",");
|
|
139
|
+
let defaultValue = tmpl[key];
|
|
140
|
+
// using some as a forEach with a 'break'
|
|
141
|
+
aliases.some(function (propName) {
|
|
142
|
+
if (!(propName in source))
|
|
143
|
+
return false;
|
|
144
|
+
let value = src[propName];
|
|
145
|
+
// there is a functional property defined with this alias ( not what we want to replace).
|
|
146
|
+
if (typeof value === 'function')
|
|
147
|
+
return false;
|
|
148
|
+
// '==' is deliberate here - idea is that null or undefined values will never get serialized
|
|
149
|
+
// if default value is set to null.
|
|
150
|
+
// tslint:disable-next-line
|
|
151
|
+
if (value == defaultValue)
|
|
152
|
+
return true;
|
|
153
|
+
if (Array.isArray(value) && value.length === 0)
|
|
154
|
+
return true;
|
|
155
|
+
if (typeof (defaultValue) === "function") {
|
|
156
|
+
value = defaultValue(value);
|
|
157
|
+
}
|
|
158
|
+
else if (typeof (value) === "object") {
|
|
159
|
+
if (value && value instanceof BreezeEnum) {
|
|
160
|
+
value = value.name;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (value === undefined)
|
|
164
|
+
return true;
|
|
165
|
+
tgt[aliases[0]] = value;
|
|
166
|
+
return true;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return target;
|
|
170
|
+
}
|
|
171
|
+
/** Replacer function for toJSONSafe, when serializing entities. Excludes entityAspect and other internal properties. */
|
|
172
|
+
function toJSONSafeReplacer(prop, val) {
|
|
173
|
+
if (prop === "entityAspect" || prop === "complexAspect" || prop === "entityType" || prop === "complexType"
|
|
174
|
+
|| prop === "getProperty" || prop === "setProperty"
|
|
175
|
+
|| prop === "constructor" || prop.charAt(0) === '_' || prop.charAt(0) === '$')
|
|
176
|
+
return;
|
|
177
|
+
return val;
|
|
178
|
+
}
|
|
179
|
+
/** Safely perform toJSON logic on objects with cycles. */
|
|
180
|
+
function toJSONSafe(obj, replacer) {
|
|
181
|
+
if (obj !== Object(obj))
|
|
182
|
+
return obj; // primitive value
|
|
183
|
+
if (obj._$visited)
|
|
184
|
+
return undefined;
|
|
185
|
+
if (obj.toJSON) {
|
|
186
|
+
let newObj = obj.toJSON();
|
|
187
|
+
if (newObj !== Object(newObj))
|
|
188
|
+
return newObj; // primitive value
|
|
189
|
+
if (newObj !== obj)
|
|
190
|
+
return toJSONSafe(newObj, replacer);
|
|
191
|
+
// toJSON returned the object unchanged.
|
|
192
|
+
obj = newObj;
|
|
193
|
+
}
|
|
194
|
+
obj._$visited = true;
|
|
195
|
+
let result;
|
|
196
|
+
if (obj instanceof Array) {
|
|
197
|
+
result = obj.map(function (o) {
|
|
198
|
+
return toJSONSafe(o, replacer);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else if (typeof (obj) === "function") {
|
|
202
|
+
result = undefined;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
result = {};
|
|
206
|
+
for (let prop in obj) {
|
|
207
|
+
if (prop === "_$visited")
|
|
208
|
+
continue;
|
|
209
|
+
let val = obj[prop];
|
|
210
|
+
if (replacer) {
|
|
211
|
+
val = replacer(prop, val);
|
|
212
|
+
if (val === undefined)
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
val = toJSONSafe(val, replacer);
|
|
216
|
+
if (val === undefined)
|
|
217
|
+
continue;
|
|
218
|
+
result[prop] = val;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
delete obj._$visited;
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
/** Resolves the values of a list of properties by checking each property in multiple sources until a value is found. */
|
|
225
|
+
function resolveProperties(sources, propertyNames) {
|
|
226
|
+
let r = {};
|
|
227
|
+
let length = sources.length;
|
|
228
|
+
propertyNames.forEach(function (pn) {
|
|
229
|
+
for (let i = 0; i < length; i++) {
|
|
230
|
+
let src = sources[i];
|
|
231
|
+
if (src) {
|
|
232
|
+
let val = src[pn];
|
|
233
|
+
if (val !== undefined) {
|
|
234
|
+
r[pn] = val;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return r;
|
|
241
|
+
}
|
|
242
|
+
// array functions
|
|
243
|
+
function toArray(item) {
|
|
244
|
+
if (item == null) {
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
else if (Array.isArray(item)) {
|
|
248
|
+
return item;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
return [item];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** a version of Array.map that doesn't require an array, i.e. works on arrays and scalars. */
|
|
255
|
+
// function map<T, U>(items: T | T[], fn: (v: T, ix?: number) => U, includeNull?: boolean): U | U[] {
|
|
256
|
+
function map(items, fn, includeNull) {
|
|
257
|
+
// whether to return nulls in array of results; default = true;
|
|
258
|
+
includeNull = includeNull == null ? true : includeNull;
|
|
259
|
+
if (items == null)
|
|
260
|
+
return items;
|
|
261
|
+
// let result: U[];
|
|
262
|
+
if (Array.isArray(items)) {
|
|
263
|
+
let result = [];
|
|
264
|
+
items.forEach(function (v, ix) {
|
|
265
|
+
let r = fn(v, ix);
|
|
266
|
+
if (r != null || includeNull) {
|
|
267
|
+
result[ix] = r;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
let result = fn(items);
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function arrayFirst(array, predicate) {
|
|
278
|
+
for (let i = 0, j = array.length; i < j; i++) {
|
|
279
|
+
if (predicate(array[i])) {
|
|
280
|
+
return array[i];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
function arrayIndexOf(array, predicate) {
|
|
286
|
+
for (let i = 0, j = array.length; i < j; i++) {
|
|
287
|
+
if (predicate(array[i]))
|
|
288
|
+
return i;
|
|
289
|
+
}
|
|
290
|
+
return -1;
|
|
291
|
+
}
|
|
292
|
+
/** Add item if not already in array */
|
|
293
|
+
function arrayAddItemUnique(array, item) {
|
|
294
|
+
let ix = array.indexOf(item);
|
|
295
|
+
if (ix === -1)
|
|
296
|
+
array.push(item);
|
|
297
|
+
}
|
|
298
|
+
/** Remove items from the array
|
|
299
|
+
* @param array
|
|
300
|
+
* @param predicateOrItem - item to remove, or function to determine matching item
|
|
301
|
+
* @param shouldRemoveMultiple - true to keep removing after first match, false otherwise
|
|
302
|
+
*/
|
|
303
|
+
function arrayRemoveItem(array, predicateOrItem, shouldRemoveMultiple) {
|
|
304
|
+
let predicate = (isFunction(predicateOrItem) ? predicateOrItem : undefined);
|
|
305
|
+
let lastIx = array.length - 1;
|
|
306
|
+
let removed = false;
|
|
307
|
+
for (let i = lastIx; i >= 0; i--) {
|
|
308
|
+
if (predicate ? predicate(array[i]) : (array[i] === predicateOrItem)) {
|
|
309
|
+
array.splice(i, 1);
|
|
310
|
+
removed = true;
|
|
311
|
+
if (!shouldRemoveMultiple) {
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return removed;
|
|
317
|
+
}
|
|
318
|
+
/** Combine array elements using the callback. Returns array with length == min(a1.length, a2.length) */
|
|
319
|
+
function arrayZip(a1, a2, callback) {
|
|
320
|
+
let result = [];
|
|
321
|
+
let n = Math.min(a1.length, a2.length);
|
|
322
|
+
for (let i = 0; i < n; ++i) {
|
|
323
|
+
result.push(callback(a1[i], a2[i]));
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
|
+
//function arrayDistinct(array) {
|
|
328
|
+
// array = array || [];
|
|
329
|
+
// let result = [];
|
|
330
|
+
// for (let i = 0, j = array.length; i < j; i++) {
|
|
331
|
+
// if (result.indexOf(array[i]) < 0)
|
|
332
|
+
// result.push(array[i]);
|
|
333
|
+
// }
|
|
334
|
+
// return result;
|
|
335
|
+
//}
|
|
336
|
+
// Not yet needed
|
|
337
|
+
//// much faster but only works on array items with a toString method that
|
|
338
|
+
//// returns distinct string for distinct objects. So this is safe for arrays with primitive
|
|
339
|
+
//// types but not for arrays with object types, unless toString() has been implemented.
|
|
340
|
+
//function arrayDistinctUnsafe(array) {
|
|
341
|
+
// let o = {}, i, l = array.length, r = [];
|
|
342
|
+
// for (i = 0; i < l; i += 1) {
|
|
343
|
+
// let v = array[i];
|
|
344
|
+
// o[v] = v;
|
|
345
|
+
// }
|
|
346
|
+
// for (i in o) r.push(o[i]);
|
|
347
|
+
// return r;
|
|
348
|
+
//}
|
|
349
|
+
function arrayEquals(a1, a2, equalsFn) {
|
|
350
|
+
//Check if the arrays are undefined/null
|
|
351
|
+
if (!a1 || !a2)
|
|
352
|
+
return false;
|
|
353
|
+
if (a1.length !== a2.length)
|
|
354
|
+
return false;
|
|
355
|
+
//go thru all the vars
|
|
356
|
+
for (let i = 0; i < a1.length; i++) {
|
|
357
|
+
//if the let is an array, we need to make a recursive check
|
|
358
|
+
//otherwise we'll just compare the values
|
|
359
|
+
if (Array.isArray(a1[i])) {
|
|
360
|
+
if (!arrayEquals(a1[i], a2[i]))
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
if (equalsFn) {
|
|
365
|
+
if (!equalsFn(a1[i], a2[i]))
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
if (a1[i] !== a2[i])
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
// end of array functions
|
|
377
|
+
/** Returns the array stored under key, creating it if absent. */
|
|
378
|
+
function getMapArray(map, key) {
|
|
379
|
+
let arr = map.get(key);
|
|
380
|
+
if (!arr) {
|
|
381
|
+
arr = [];
|
|
382
|
+
map.set(key, arr);
|
|
383
|
+
}
|
|
384
|
+
return arr;
|
|
385
|
+
}
|
|
386
|
+
/** Execute fn while obj has tempValue for property */
|
|
387
|
+
function using(obj, property, tempValue, fn) {
|
|
388
|
+
if (!obj) {
|
|
389
|
+
return fn();
|
|
390
|
+
}
|
|
391
|
+
const rec = obj;
|
|
392
|
+
let originalValue = rec[property];
|
|
393
|
+
if (tempValue === originalValue) {
|
|
394
|
+
return fn();
|
|
395
|
+
}
|
|
396
|
+
rec[property] = tempValue;
|
|
397
|
+
try {
|
|
398
|
+
return fn();
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
if (originalValue === undefined) {
|
|
402
|
+
delete rec[property];
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
rec[property] = originalValue;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/** Call state = startFn(), call fn(), call endFn(state) */
|
|
410
|
+
function wrapExecution(startFn, endFn, fn) {
|
|
411
|
+
let state;
|
|
412
|
+
try {
|
|
413
|
+
state = startFn();
|
|
414
|
+
return fn();
|
|
415
|
+
}
|
|
416
|
+
catch (e) {
|
|
417
|
+
if (typeof (state) === 'object') {
|
|
418
|
+
state.error = e;
|
|
419
|
+
}
|
|
420
|
+
throw e;
|
|
421
|
+
}
|
|
422
|
+
finally {
|
|
423
|
+
endFn(state);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/** Remember & return the value of fn() when it was called with its current args */
|
|
427
|
+
function memoize(fn) {
|
|
428
|
+
return function () {
|
|
429
|
+
let args = arraySlice(arguments), hash = "", i = args.length, currentArg = null;
|
|
430
|
+
while (i--) {
|
|
431
|
+
currentArg = args[i];
|
|
432
|
+
hash += (currentArg === Object(currentArg)) ? JSON.stringify(currentArg) : currentArg;
|
|
433
|
+
fn.memoize || (fn.memoize = {});
|
|
434
|
+
}
|
|
435
|
+
return (hash in fn.memoize) ?
|
|
436
|
+
fn.memoize[hash] :
|
|
437
|
+
fn.memoize[hash] = fn.apply(this, args);
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
const durationrex = /^P((\d+Y)?(\d+M)?(\d+D)?)?(T(\d+H)?(\d+M)?(\d+S)?)?$/;
|
|
441
|
+
const lettersrex = /[A-Za-z]+/g;
|
|
442
|
+
function durationToSeconds(duration) {
|
|
443
|
+
// basic algorithm from https://github.com/nezasa/iso8601-js-period
|
|
444
|
+
if (typeof duration !== "string")
|
|
445
|
+
throw new Error("Invalid ISO8601 duration '" + duration + "'");
|
|
446
|
+
// regex splits as follows - grp0, grp1, y, m, d, grp2, h, m, s
|
|
447
|
+
// 0 1 2 3 4 5 6 7 8
|
|
448
|
+
let struct = durationrex.exec(duration);
|
|
449
|
+
if (!struct)
|
|
450
|
+
throw new Error("Invalid ISO8601 duration '" + duration + "'");
|
|
451
|
+
let ymdhmsIndexes = [2, 3, 4, 6, 7, 8]; // -> grp1,y,m,d,grp2,h,m,s
|
|
452
|
+
let factors = [31104000, // year (360*24*60*60)
|
|
453
|
+
2592000, // month (30*24*60*60)
|
|
454
|
+
86400, // day (24*60*60)
|
|
455
|
+
3600, // hour (60*60)
|
|
456
|
+
60, // minute (60)
|
|
457
|
+
1]; // second (1)
|
|
458
|
+
let seconds = 0;
|
|
459
|
+
for (let i = 0; i < 6; i++) {
|
|
460
|
+
let digit = struct[ymdhmsIndexes[i]];
|
|
461
|
+
// remove letters, replace by 0 if not defined
|
|
462
|
+
digit = (digit ? +digit.replace(lettersrex, '') : 0);
|
|
463
|
+
seconds += digit * factors[i];
|
|
464
|
+
}
|
|
465
|
+
return seconds;
|
|
466
|
+
}
|
|
467
|
+
// is functions
|
|
468
|
+
function noop() {
|
|
469
|
+
// does nothing
|
|
470
|
+
}
|
|
471
|
+
function identity(x) {
|
|
472
|
+
return x;
|
|
473
|
+
}
|
|
474
|
+
function classof(o) {
|
|
475
|
+
if (o === null) {
|
|
476
|
+
return "null";
|
|
477
|
+
}
|
|
478
|
+
if (o === undefined) {
|
|
479
|
+
return "undefined";
|
|
480
|
+
}
|
|
481
|
+
return Object.prototype.toString.call(o).slice(8, -1).toLowerCase();
|
|
482
|
+
}
|
|
483
|
+
function isDate(o) {
|
|
484
|
+
return classof(o) === "date" && !isNaN(o.getTime());
|
|
485
|
+
}
|
|
486
|
+
const isdaterex = /^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/;
|
|
487
|
+
function isDateString(s) {
|
|
488
|
+
// let rx = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/;
|
|
489
|
+
return (typeof s === "string") && isdaterex.test(s);
|
|
490
|
+
}
|
|
491
|
+
function isFunction(o) {
|
|
492
|
+
return classof(o) === "function";
|
|
493
|
+
}
|
|
494
|
+
// function isString(o: any) {
|
|
495
|
+
// return (typeof o === "string");
|
|
496
|
+
// }
|
|
497
|
+
// function isObject(o: any) {
|
|
498
|
+
// return (typeof o === "object");
|
|
499
|
+
// }
|
|
500
|
+
const isguidrex = /^[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}$/;
|
|
501
|
+
function isGuid(value) {
|
|
502
|
+
return (typeof value === "string") && isguidrex.test(value);
|
|
503
|
+
}
|
|
504
|
+
const isdurationrex = /^(-|)?P[T]?[\d\.,\-]+[YMDTHS]/;
|
|
505
|
+
function isDuration(value) {
|
|
506
|
+
return (typeof value === "string") && isdurationrex.test(value);
|
|
507
|
+
}
|
|
508
|
+
function isEmpty(obj) {
|
|
509
|
+
if (obj === null || obj === undefined) {
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
for (let key in obj) {
|
|
513
|
+
if (hasOwnProperty(obj, key)) {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
// end of is Functions
|
|
520
|
+
// string functions
|
|
521
|
+
// Based on fragment from Dean Edwards' Base 2 library
|
|
522
|
+
/**
|
|
523
|
+
* Replaces `%1`, `%2`, ... in `str` with the arguments that follow it.
|
|
524
|
+
*
|
|
525
|
+
* formatString("a %1 and a %2", "cat", "dog") // "a cat and a dog"
|
|
526
|
+
*
|
|
527
|
+
* It declared rest parameters and then read `arguments` anyway, and compiled a fresh `RegExp`
|
|
528
|
+
* on every call to bound the placeholder to the number of arguments given - so `%3` with two
|
|
529
|
+
* arguments was left in place rather than replaced. One shared pattern does the same thing:
|
|
530
|
+
* a placeholder with no argument for it is left alone here too.
|
|
531
|
+
* @hidden
|
|
532
|
+
*/
|
|
533
|
+
export function formatString(str, ...params) {
|
|
534
|
+
return str.replace(formatStringRex, (match, index) => {
|
|
535
|
+
const param = params[Number(index) - 1];
|
|
536
|
+
return param === undefined ? match : param;
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
const formatStringRex = /%([1-9])/g;
|
|
540
|
+
// end of string functions
|
|
541
|
+
// --- superseded by the language -------------------------------------------------------------
|
|
542
|
+
//
|
|
543
|
+
// Each of these is now exactly a JavaScript built-in, and calls it. They are gathered here,
|
|
544
|
+
// apart from the helpers that still earn their place, because `core` marks every one of them
|
|
545
|
+
// @deprecated. What an application should stop writing is the access path - `breeze.core.getUuid`
|
|
546
|
+
// and the rest - not the function, so Breeze imports them by name from this module instead of
|
|
547
|
+
// reading them off `core`. Nothing inside the library uses a member it tells applications not
|
|
548
|
+
// to use.
|
|
549
|
+
//
|
|
550
|
+
// They stay above the `core` object literal, which reads them by value.
|
|
551
|
+
// Both of these were built with an `uncurry` helper - `Function.call.apply(fn, arguments)` -
|
|
552
|
+
// which is how you borrowed a prototype method before the language had a way to say it.
|
|
553
|
+
/** @hidden @internal */
|
|
554
|
+
export const hasOwnProperty = Object.hasOwn;
|
|
555
|
+
/** @hidden @internal */
|
|
556
|
+
export const arraySlice = (ar, start, end) => Array.prototype.slice.call(ar, start, end);
|
|
557
|
+
/** @hidden */
|
|
558
|
+
export function arrayFlatMap(arr, mapFn) {
|
|
559
|
+
return arr.flatMap(mapFn);
|
|
560
|
+
}
|
|
561
|
+
const uuidrex = /[xy]/g;
|
|
562
|
+
/**
|
|
563
|
+
* A version 4 UUID.
|
|
564
|
+
*
|
|
565
|
+
* `crypto.randomUUID()` where it exists, which is everywhere Breeze supports except a browser
|
|
566
|
+
* outside a secure context - it is unavailable over plain HTTP. It is both properly random and
|
|
567
|
+
* about 30x faster than building one out of `Math.random()`, which matters because this is what
|
|
568
|
+
* names a new entity with a Guid key.
|
|
569
|
+
*
|
|
570
|
+
* The fallback is the old implementation. `Math.random()` is not a cryptographic source, so the
|
|
571
|
+
* values it produces are unique enough for a client-side temporary key and should not be relied
|
|
572
|
+
* on for anything else.
|
|
573
|
+
* @hidden
|
|
574
|
+
*/
|
|
575
|
+
export function getUuid() {
|
|
576
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
577
|
+
return crypto.randomUUID();
|
|
578
|
+
}
|
|
579
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(uuidrex, function (c) {
|
|
580
|
+
// tslint:disable-next-line
|
|
581
|
+
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
582
|
+
return v.toString(16);
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
// These two exist for their null handling, which is what the local query operators need: a
|
|
586
|
+
// property that is null does not start with anything, and comparing against a null prefix asks
|
|
587
|
+
// nothing. `String.prototype.startsWith` throws on the first and compares against the text
|
|
588
|
+
// "null" on the second. The comparison itself is the built-in now - `endsWith` is 2.3x the
|
|
589
|
+
// `indexOf` arithmetic it replaces.
|
|
590
|
+
/** @hidden */
|
|
591
|
+
export function stringStartsWith(str, prefix) {
|
|
592
|
+
// returns true for empty string or null prefix
|
|
593
|
+
if ((!str))
|
|
594
|
+
return false;
|
|
595
|
+
if (prefix === "" || prefix == null)
|
|
596
|
+
return true;
|
|
597
|
+
return str.startsWith(prefix);
|
|
598
|
+
}
|
|
599
|
+
/** @hidden */
|
|
600
|
+
export function stringEndsWith(str, suffix) {
|
|
601
|
+
// returns true for empty string or null suffix
|
|
602
|
+
if ((!str))
|
|
603
|
+
return false;
|
|
604
|
+
if (suffix === "" || suffix == null)
|
|
605
|
+
return true;
|
|
606
|
+
return str.endsWith(suffix);
|
|
607
|
+
}
|
|
608
|
+
// strings for error messages
|
|
609
|
+
const strings = {
|
|
610
|
+
/** Advice appended to errors about a query whose entity type Breeze cannot determine. */
|
|
611
|
+
"TO_TYPE": "Add 'EntityQuery.toType()' to your query, or call 'MetadataStore.setEntityTypeForResourceName()' to register an EntityType for this resourceName."
|
|
612
|
+
};
|
|
613
|
+
// // not all methods above are exported
|
|
614
|
+
/** Utility functions that Breeze 2.x exposed as `breeze.core`, kept for code written against 2.x.
|
|
615
|
+
Several now just call a JavaScript built-in; those are marked deprecated and name it. */
|
|
616
|
+
export const core = {
|
|
617
|
+
/** @deprecated Use `Object.hasOwn(obj, key)`, which this now calls. */
|
|
618
|
+
hasOwnProperty: hasOwnProperty,
|
|
619
|
+
/** The values of an object's own enumerable properties. `Object.values(obj)`, except that null
|
|
620
|
+
or undefined gives `[]`. */
|
|
621
|
+
getOwnPropertyValues: getOwnPropertyValues,
|
|
622
|
+
/** The descriptor of `propertyName` on `obj` or, failing that, on the nearest prototype that
|
|
623
|
+
has it; `undefined` if none does. Unlike `Object.getOwnPropertyDescriptor`, it searches the
|
|
624
|
+
prototype chain. */
|
|
625
|
+
getPropertyDescriptor: getPropDescriptor,
|
|
626
|
+
/** Calls `kvFn(key, value)` for each of an object's own enumerable properties. Does nothing for
|
|
627
|
+
null or undefined. */
|
|
628
|
+
objectForEach: objectForEach,
|
|
629
|
+
/** The first of an object's own enumerable properties for which `kvPredicate(key, value)` is
|
|
630
|
+
true, as `{ key, value }`; `null` if there is none. */
|
|
631
|
+
objectFirst: objectFirst,
|
|
632
|
+
/** Calls `kvFn(key, value)` for each of an object's own enumerable properties and returns the
|
|
633
|
+
results, leaving out any that are `undefined`. Without `kvFn`, returns the values. */
|
|
634
|
+
objectMap: objectMap, // TODO: replace this with something strongly typed.
|
|
635
|
+
/** Copies properties from `source` onto `target` and returns `target`: all of `source`'s own
|
|
636
|
+
enumerable properties, or only `propNames` when given. A shallow copy, like `Object.assign`. */
|
|
637
|
+
extend: extend,
|
|
638
|
+
/** A predicate that is true for an object whose `propertyName` is `=== value`:
|
|
639
|
+
`people.filter(core.propEq('firstName', 'John'))`. */
|
|
640
|
+
propEq: propEq,
|
|
641
|
+
/** A predicate that is true for an object whose `property1Name` or `property2Name` is
|
|
642
|
+
`=== value`. */
|
|
643
|
+
propsEq: propsEq,
|
|
644
|
+
/** A function that returns an object's `propertyName`: `people.map(core.pluck('firstName'))`. */
|
|
645
|
+
pluck: pluck,
|
|
646
|
+
/** `Array.prototype.map` that also takes a single value, which it passes to `fn` and returns
|
|
647
|
+
the result of. Null or undefined is returned as is. With `includeNull` false, an element
|
|
648
|
+
whose result is null or undefined is left as a hole in the returned array. */
|
|
649
|
+
map: map,
|
|
650
|
+
/** An object with each of `propertyNames` taken from the first of `sources` in which it is not
|
|
651
|
+
`undefined`. Breeze uses it to combine a query's settings with its manager's and the
|
|
652
|
+
defaults, in {@link QueryOptions.resolve} and {@link DataService.resolve}. */
|
|
653
|
+
resolveProperties: resolveProperties,
|
|
654
|
+
/** Creates an instance of `ctor` from `target`, fills in whatever it leaves unset from the
|
|
655
|
+
current `ctor.defaultInstance`, and makes that the new `ctor.defaultInstance`. Returns
|
|
656
|
+
`target`. The `setAsDefault()` methods of {@link QueryOptions}, {@link SaveOptions},
|
|
657
|
+
{@link NamingConvention} and {@link LocalQueryComparisonOptions} are built on it. */
|
|
658
|
+
setAsDefault: setAsDefault,
|
|
659
|
+
/** Copies each property of `defaults` onto `target` where `target`'s is `undefined`, and
|
|
660
|
+
returns `target`. */
|
|
661
|
+
updateWithDefaults: updateWithDefaults,
|
|
662
|
+
/** The array stored in `map` under `key`, after storing an empty one there if there was none. */
|
|
663
|
+
getMapArray: getMapArray,
|
|
664
|
+
/** `[]` for null or undefined, the array itself for an array, and `[item]` for anything else. */
|
|
665
|
+
toArray: toArray,
|
|
666
|
+
/** Whether two arrays have the same length and equal elements, compared with `===` or with
|
|
667
|
+
`equalsFn` if given. An element that is itself an array is compared element by element, with
|
|
668
|
+
`===`. False if either array is null or undefined. */
|
|
669
|
+
arrayEquals: arrayEquals,
|
|
670
|
+
/** @deprecated Use `arr.slice(start, end)`, or `Array.prototype.slice.call(arrayLike)` for
|
|
671
|
+
an arguments object. That is what this now does. */
|
|
672
|
+
arraySlice: arraySlice,
|
|
673
|
+
/** The first element for which `predicate` is true, or `null`. Like `Array.prototype.find`,
|
|
674
|
+
except for returning `null` rather than `undefined`. */
|
|
675
|
+
arrayFirst: arrayFirst,
|
|
676
|
+
/** The index of the first element for which `predicate` is true, or -1. The same as
|
|
677
|
+
`Array.prototype.findIndex`. */
|
|
678
|
+
arrayIndexOf: arrayIndexOf,
|
|
679
|
+
/** Removes from `array`, in place, either `predicateOrItem` itself or the elements that
|
|
680
|
+
`predicateOrItem`, a function, matches. Removes only the last match unless
|
|
681
|
+
`shouldRemoveMultiple` is true. Returns whether anything was removed. */
|
|
682
|
+
arrayRemoveItem: arrayRemoveItem,
|
|
683
|
+
/** Combines the elements of two arrays pairwise with `callback`. The result is as long as the
|
|
684
|
+
shorter array. */
|
|
685
|
+
arrayZip: arrayZip,
|
|
686
|
+
/** Pushes `item` onto `array` unless the array already holds it. */
|
|
687
|
+
arrayAddItemUnique: arrayAddItemUnique,
|
|
688
|
+
/** @deprecated Use `arr.flatMap(fn)`, which this now calls. */
|
|
689
|
+
arrayFlatMap: arrayFlatMap,
|
|
690
|
+
/** Sets `obj[property]` to `tempValue`, calls `fn`, then restores the original value, deleting
|
|
691
|
+
the property if it had none, whether or not `fn` throws. Returns what `fn` returns. */
|
|
692
|
+
using: using,
|
|
693
|
+
/** Calls `startFn()`, then `fn()`, then `endFn(state)` with what `startFn` returned, whether or
|
|
694
|
+
not `fn` throws. If it throws and the state is an object, the error is set on `state.error`
|
|
695
|
+
first. Returns what `fn` returns. */
|
|
696
|
+
wrapExecution: wrapExecution,
|
|
697
|
+
/** Wraps `fn` so that it runs once for each distinct set of arguments and afterwards returns
|
|
698
|
+
the stored result. Arguments are keyed by value, objects by their `JSON.stringify`. The
|
|
699
|
+
results are stored on `fn` itself and never released. */
|
|
700
|
+
memoize: memoize,
|
|
701
|
+
/** @deprecated Use `crypto.randomUUID()`. This calls it where it exists and falls back to a
|
|
702
|
+
`Math.random()` implementation in a browser outside a secure context, where it does not. */
|
|
703
|
+
getUuid: getUuid,
|
|
704
|
+
/** Converts an ISO 8601 duration such as `PT1H30M` to seconds, counting a year as 360 days and
|
|
705
|
+
a month as 30. Throws for a string that is not a duration. */
|
|
706
|
+
durationToSeconds: durationToSeconds,
|
|
707
|
+
/** Whether `obj[propertyName]` can be assigned: true if no object on the prototype chain
|
|
708
|
+
defines it, or if its descriptor is writable or has a setter. */
|
|
709
|
+
isSettable: isSettable,
|
|
710
|
+
/** Whether `o` is a `Date` holding a valid time - not an Invalid Date. */
|
|
711
|
+
isDate: isDate,
|
|
712
|
+
/** Whether `s` is an ISO 8601 date-time with a time zone, such as `2024-05-01T10:30:00Z` or
|
|
713
|
+
`2024-05-01T10:30:00.5+02:00`. A string with no time zone, or a date with no time, is not. */
|
|
714
|
+
isDateString: isDateString,
|
|
715
|
+
/** Whether `value` is a string in GUID form: 8-4-4-4-12 hexadecimal digits. */
|
|
716
|
+
isGuid: isGuid,
|
|
717
|
+
/** Whether `value` is a string that looks like an ISO 8601 duration, such as `PT1H`. A quick
|
|
718
|
+
check of its shape, not a full parse - see {@link core.durationToSeconds}. */
|
|
719
|
+
isDuration: isDuration,
|
|
720
|
+
/** Whether `o` is an ordinary function. False for async and generator functions: it checks
|
|
721
|
+
`Object.prototype.toString`, which names those differently. */
|
|
722
|
+
isFunction: isFunction,
|
|
723
|
+
/** Whether `obj` is null, undefined, or has no own enumerable properties. */
|
|
724
|
+
isEmpty: isEmpty,
|
|
725
|
+
/** Returns its argument. */
|
|
726
|
+
identity: identity,
|
|
727
|
+
/** Does nothing. */
|
|
728
|
+
noop: noop,
|
|
729
|
+
/** @deprecated Use `str.startsWith(prefix)`. Not quite the same: this answers `false` for a
|
|
730
|
+
null string and `true` for a null prefix, where the built-in throws and compares against
|
|
731
|
+
the text "null" respectively. Guard the null yourself. */
|
|
732
|
+
stringStartsWith: stringStartsWith,
|
|
733
|
+
/** @deprecated Use `str.endsWith(suffix)`, with the same caveat about nulls as
|
|
734
|
+
{@link core.stringStartsWith}. */
|
|
735
|
+
stringEndsWith: stringEndsWith,
|
|
736
|
+
/** Replaces `%1`, `%2`, ... in `str` with the arguments that follow it:
|
|
737
|
+
`formatString('a %1 and a %2', 'cat', 'dog')` is `'a cat and a dog'`. */
|
|
738
|
+
formatString: formatString,
|
|
739
|
+
/** Copies properties of `source` to `target`, a new object by default, as `template` directs,
|
|
740
|
+
and returns `target`. Each key of `template` names a property to copy; a key such as `'a,b'`
|
|
741
|
+
also accepts `b` as another name for `a`. The template's value is the property's default: a
|
|
742
|
+
property equal to it (by `==`), `undefined`, or an empty array is left out. If the
|
|
743
|
+
template's value is a function, it converts the property's value instead, and a
|
|
744
|
+
{@link BreezeEnum} is written as its name. Breeze's metadata classes build their `toJSON`
|
|
745
|
+
output with it. */
|
|
746
|
+
toJson: toJson,
|
|
747
|
+
/** A copy of `obj` that `JSON.stringify` can serialize even when the object graph has cycles: a
|
|
748
|
+
reference back to an object already being copied is left out. Uses an object's own `toJSON`
|
|
749
|
+
when it has one, leaves out functions, and passes each property through `replacer` when
|
|
750
|
+
given, leaving out any it returns `undefined` for. */
|
|
751
|
+
toJSONSafe: toJSONSafe,
|
|
752
|
+
/** A `replacer` for {@link core.toJSONSafe} that leaves out an entity's Breeze members -
|
|
753
|
+
`entityAspect`, `complexAspect`, `entityType`, `complexType`, `getProperty`, `setProperty`
|
|
754
|
+
and `constructor` - and any property whose name starts with `_` or `$`. Breeze serializes
|
|
755
|
+
unmapped property values with it. */
|
|
756
|
+
toJSONSafeReplacer: toJSONSafeReplacer,
|
|
757
|
+
/** Text that Breeze uses in its error messages. */
|
|
758
|
+
strings: strings
|
|
759
|
+
};
|
|
760
|
+
// Unused
|
|
761
|
+
/*
|
|
762
|
+
// returns true for booleans, numbers, strings and dates
|
|
763
|
+
// false for null, and non-date objects, functions, and arrays
|
|
764
|
+
function isPrimitive(obj: any) {
|
|
765
|
+
if (obj == null) return false;
|
|
766
|
+
// true for numbers, strings, booleans and null, false for objects
|
|
767
|
+
if (obj != Object(obj)) return true;
|
|
768
|
+
return isDate(obj);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
*/
|
|
772
|
+
//# sourceMappingURL=core.js.map
|