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.
Files changed (299) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +83 -63
  3. package/adapters/abstract-data-service-adapter.d.ts +120 -0
  4. package/adapters/abstract-data-service-adapter.js +395 -0
  5. package/adapters/abstract-data-service-adapter.js.map +1 -0
  6. package/adapters/adapter-ajax-fetch.d.ts +12 -0
  7. package/adapters/adapter-ajax-fetch.js +13 -0
  8. package/adapters/adapter-ajax-fetch.js.map +1 -0
  9. package/{adapter-ajax-post → adapters}/adapter-ajax-post.d.ts +40 -36
  10. package/{fesm2022/breeze-client-adapter-ajax-post.mjs → adapters/adapter-ajax-post.js} +80 -82
  11. package/adapters/adapter-ajax-post.js.map +1 -0
  12. package/{adapter-ajax-fetch → adapters}/adapter-core.d.ts +4 -4
  13. package/{fesm2022/breeze-client-adapter-uri-builder-json.mjs → adapters/adapter-core.js} +48 -91
  14. package/adapters/adapter-core.js.map +1 -0
  15. package/adapters/adapter-data-service-webapi.d.ts +9 -0
  16. package/{fesm2022/breeze-client-adapter-data-service-webapi.mjs → adapters/adapter-data-service-webapi.js} +105 -107
  17. package/adapters/adapter-data-service-webapi.js.map +1 -0
  18. package/adapters/adapter-model-library-backing-store.d.ts +32 -0
  19. package/adapters/adapter-model-library-backing-store.js +321 -0
  20. package/adapters/adapter-model-library-backing-store.js.map +1 -0
  21. package/adapters/adapter-uri-builder-json.d.ts +11 -0
  22. package/adapters/adapter-uri-builder-json.js +40 -0
  23. package/adapters/adapter-uri-builder-json.js.map +1 -0
  24. package/adapters/http.d.ts +52 -0
  25. package/adapters/http.js +202 -0
  26. package/adapters/http.js.map +1 -0
  27. package/angular/adapter-angular-httpclient.d.ts +21 -0
  28. package/angular/adapter-angular-httpclient.js +70 -0
  29. package/angular/adapter-angular-httpclient.js.map +1 -0
  30. package/breeze.d.ts +215 -0
  31. package/breeze.js +141 -0
  32. package/breeze.js.map +1 -0
  33. package/config/config.d.ts +212 -0
  34. package/config/config.js +392 -0
  35. package/config/config.js.map +1 -0
  36. package/config/configure.d.ts +66 -0
  37. package/config/configure.js +46 -0
  38. package/config/configure.js.map +1 -0
  39. package/config/default-adapters.d.ts +1 -0
  40. package/config/default-adapters.js +40 -0
  41. package/config/default-adapters.js.map +1 -0
  42. package/config/interface-registry.d.ts +191 -0
  43. package/config/interface-registry.js +5 -0
  44. package/config/interface-registry.js.map +1 -0
  45. package/{src → core}/assert-param.d.ts +52 -60
  46. package/core/assert-param.js +390 -0
  47. package/core/assert-param.js.map +1 -0
  48. package/core/core.d.ts +285 -0
  49. package/core/core.js +772 -0
  50. package/core/core.js.map +1 -0
  51. package/core/enum.d.ts +116 -0
  52. package/core/enum.js +167 -0
  53. package/core/enum.js.map +1 -0
  54. package/core/event.d.ts +169 -0
  55. package/core/event.js +338 -0
  56. package/core/event.js.map +1 -0
  57. package/entity/array.d.ts +3 -0
  58. package/entity/array.js +4 -0
  59. package/entity/array.js.map +1 -0
  60. package/entity/complex-array.d.ts +17 -0
  61. package/entity/complex-array.js +104 -0
  62. package/entity/complex-array.js.map +1 -0
  63. package/entity/default-property-interceptor.d.ts +1 -0
  64. package/entity/default-property-interceptor.js +496 -0
  65. package/entity/default-property-interceptor.js.map +1 -0
  66. package/{src → entity}/entity-action.d.ts +36 -42
  67. package/entity/entity-action.js +45 -0
  68. package/entity/entity-action.js.map +1 -0
  69. package/entity/entity-aspect.d.ts +457 -0
  70. package/entity/entity-aspect.js +1262 -0
  71. package/entity/entity-aspect.js.map +1 -0
  72. package/entity/entity-base.d.ts +55 -0
  73. package/entity/entity-base.js +41 -0
  74. package/entity/entity-base.js.map +1 -0
  75. package/entity/entity-group.d.ts +1 -0
  76. package/entity/entity-group.js +224 -0
  77. package/entity/entity-group.js.map +1 -0
  78. package/entity/entity-key.d.ts +95 -0
  79. package/entity/entity-key.js +189 -0
  80. package/entity/entity-key.js.map +1 -0
  81. package/{src → entity}/entity-state.d.ts +112 -84
  82. package/entity/entity-state.js +135 -0
  83. package/entity/entity-state.js.map +1 -0
  84. package/entity/key-generator.d.ts +57 -0
  85. package/entity/key-generator.js +155 -0
  86. package/entity/key-generator.js.map +1 -0
  87. package/entity/observable-array.d.ts +25 -0
  88. package/entity/observable-array.js +230 -0
  89. package/entity/observable-array.js.map +1 -0
  90. package/entity/primitive-array.d.ts +12 -0
  91. package/entity/primitive-array.js +71 -0
  92. package/entity/primitive-array.js.map +1 -0
  93. package/entity/relation-array.d.ts +24 -0
  94. package/entity/relation-array.js +176 -0
  95. package/entity/relation-array.js.map +1 -0
  96. package/entity/unattached-children-map.d.ts +1 -0
  97. package/entity/unattached-children-map.js +105 -0
  98. package/entity/unattached-children-map.js.map +1 -0
  99. package/generate-entity-classes.js +1176 -0
  100. package/manager/entity-manager.d.ts +801 -0
  101. package/manager/entity-manager.js +2395 -0
  102. package/manager/entity-manager.js.map +1 -0
  103. package/{src → manager}/save-options.d.ts +48 -42
  104. package/manager/save-options.js +51 -0
  105. package/manager/save-options.js.map +1 -0
  106. package/{src → metadata}/data-service.d.ts +229 -184
  107. package/metadata/data-service.js +246 -0
  108. package/metadata/data-service.js.map +1 -0
  109. package/metadata/data-type.d.ts +122 -0
  110. package/metadata/data-type.js +465 -0
  111. package/metadata/data-type.js.map +1 -0
  112. package/metadata/entity-metadata.d.ts +1193 -0
  113. package/metadata/entity-metadata.js +2502 -0
  114. package/metadata/entity-metadata.js.map +1 -0
  115. package/{src → metadata}/local-query-comparison-options.d.ts +65 -59
  116. package/metadata/local-query-comparison-options.js +69 -0
  117. package/metadata/local-query-comparison-options.js.map +1 -0
  118. package/{src → metadata}/naming-convention.d.ts +75 -72
  119. package/metadata/naming-convention.js +97 -0
  120. package/metadata/naming-convention.js.map +1 -0
  121. package/mixins/mixin-get-entity-graph.d.ts +63 -0
  122. package/{fesm2022/breeze-client-mixin-get-entity-graph.mjs → mixins/mixin-get-entity-graph.js} +331 -253
  123. package/mixins/mixin-get-entity-graph.js.map +1 -0
  124. package/mixins/mixin-save-queuing.d.ts +98 -0
  125. package/{fesm2022/breeze-client-mixin-save-queuing.mjs → mixins/mixin-save-queuing.js} +493 -365
  126. package/mixins/mixin-save-queuing.js.map +1 -0
  127. package/package.json +63 -94
  128. package/query/entity-query.d.ts +521 -0
  129. package/query/entity-query.js +1149 -0
  130. package/query/entity-query.js.map +1 -0
  131. package/{src → query}/mapping-context.d.ts +44 -46
  132. package/query/mapping-context.js +412 -0
  133. package/query/mapping-context.js.map +1 -0
  134. package/query/predicate.d.ts +394 -0
  135. package/query/predicate.js +1294 -0
  136. package/query/predicate.js.map +1 -0
  137. package/query/property-path.d.ts +252 -0
  138. package/query/property-path.js +2 -0
  139. package/query/property-path.js.map +1 -0
  140. package/{src → query}/query-options.d.ts +143 -119
  141. package/query/query-options.js +180 -0
  142. package/query/query-options.js.map +1 -0
  143. package/rxjs/breeze-rxjs.d.ts +72 -0
  144. package/rxjs/breeze-rxjs.js +117 -0
  145. package/rxjs/breeze-rxjs.js.map +1 -0
  146. package/validation/validate.d.ts +583 -0
  147. package/validation/validate.js +961 -0
  148. package/validation/validate.js.map +1 -0
  149. package/{src → validation}/validation-options.d.ts +67 -63
  150. package/validation/validation-options.js +70 -0
  151. package/validation/validation-options.js.map +1 -0
  152. package/adapter-ajax-angularjs/adapter-ajax-angularjs.d.ts +0 -17
  153. package/adapter-ajax-angularjs/adapter-core.d.ts +0 -4
  154. package/adapter-ajax-angularjs/index.d.ts +0 -5
  155. package/adapter-ajax-fetch/adapter-ajax-fetch.d.ts +0 -18
  156. package/adapter-ajax-fetch/index.d.ts +0 -5
  157. package/adapter-ajax-httpclient/adapter-ajax-httpclient.d.ts +0 -13
  158. package/adapter-ajax-httpclient/adapter-core.d.ts +0 -4
  159. package/adapter-ajax-httpclient/index.d.ts +0 -5
  160. package/adapter-ajax-jquery/adapter-ajax-jquery.d.ts +0 -15
  161. package/adapter-ajax-jquery/index.d.ts +0 -5
  162. package/adapter-ajax-post/index.d.ts +0 -5
  163. package/adapter-data-service-odata/adapter-core.d.ts +0 -4
  164. package/adapter-data-service-odata/adapter-data-service-odata.d.ts +0 -17
  165. package/adapter-data-service-odata/index.d.ts +0 -5
  166. package/adapter-data-service-webapi/adapter-data-service-webapi.d.ts +0 -15
  167. package/adapter-data-service-webapi/index.d.ts +0 -5
  168. package/adapter-model-library-backing-store/adapter-model-library-backing-store.d.ts +0 -10
  169. package/adapter-model-library-backing-store/index.d.ts +0 -5
  170. package/adapter-model-library-ko/adapter-model-library-ko.d.ts +0 -10
  171. package/adapter-model-library-ko/index.d.ts +0 -5
  172. package/adapter-uri-builder-json/adapter-core.d.ts +0 -4
  173. package/adapter-uri-builder-json/adapter-uri-builder-json.d.ts +0 -8
  174. package/adapter-uri-builder-json/index.d.ts +0 -5
  175. package/adapter-uri-builder-odata/adapter-core.d.ts +0 -4
  176. package/adapter-uri-builder-odata/adapter-uri-builder-odata.d.ts +0 -8
  177. package/adapter-uri-builder-odata/index.d.ts +0 -5
  178. package/esm2022/adapter-ajax-angularjs/adapter-ajax-angularjs.mjs +0 -135
  179. package/esm2022/adapter-ajax-angularjs/adapter-core.mjs +0 -49
  180. package/esm2022/adapter-ajax-angularjs/breeze-client-adapter-ajax-angularjs.mjs +0 -5
  181. package/esm2022/adapter-ajax-fetch/adapter-ajax-fetch.mjs +0 -135
  182. package/esm2022/adapter-ajax-fetch/adapter-core.mjs +0 -49
  183. package/esm2022/adapter-ajax-fetch/breeze-client-adapter-ajax-fetch.mjs +0 -5
  184. package/esm2022/adapter-ajax-httpclient/adapter-ajax-httpclient.mjs +0 -139
  185. package/esm2022/adapter-ajax-httpclient/adapter-core.mjs +0 -49
  186. package/esm2022/adapter-ajax-httpclient/breeze-client-adapter-ajax-httpclient.mjs +0 -5
  187. package/esm2022/adapter-ajax-jquery/adapter-ajax-jquery.mjs +0 -107
  188. package/esm2022/adapter-ajax-jquery/breeze-client-adapter-ajax-jquery.mjs +0 -5
  189. package/esm2022/adapter-ajax-post/adapter-ajax-post.mjs +0 -77
  190. package/esm2022/adapter-ajax-post/breeze-client-adapter-ajax-post.mjs +0 -5
  191. package/esm2022/adapter-data-service-odata/adapter-core.mjs +0 -49
  192. package/esm2022/adapter-data-service-odata/adapter-data-service-odata.mjs +0 -461
  193. package/esm2022/adapter-data-service-odata/breeze-client-adapter-data-service-odata.mjs +0 -5
  194. package/esm2022/adapter-data-service-webapi/adapter-data-service-webapi.mjs +0 -100
  195. package/esm2022/adapter-data-service-webapi/breeze-client-adapter-data-service-webapi.mjs +0 -5
  196. package/esm2022/adapter-model-library-backing-store/adapter-model-library-backing-store.mjs +0 -269
  197. package/esm2022/adapter-model-library-backing-store/breeze-client-adapter-model-library-backing-store.mjs +0 -5
  198. package/esm2022/adapter-model-library-ko/adapter-model-library-ko.mjs +0 -241
  199. package/esm2022/adapter-model-library-ko/breeze-client-adapter-model-library-ko.mjs +0 -5
  200. package/esm2022/adapter-uri-builder-json/adapter-core.mjs +0 -49
  201. package/esm2022/adapter-uri-builder-json/adapter-uri-builder-json.mjs +0 -37
  202. package/esm2022/adapter-uri-builder-json/breeze-client-adapter-uri-builder-json.mjs +0 -5
  203. package/esm2022/adapter-uri-builder-odata/adapter-core.mjs +0 -49
  204. package/esm2022/adapter-uri-builder-odata/adapter-uri-builder-odata.mjs +0 -191
  205. package/esm2022/adapter-uri-builder-odata/breeze-client-adapter-uri-builder-odata.mjs +0 -5
  206. package/esm2022/breeze-client.mjs +0 -5
  207. package/esm2022/index.mjs +0 -2
  208. package/esm2022/mixin-get-entity-graph/breeze-client-mixin-get-entity-graph.mjs +0 -5
  209. package/esm2022/mixin-get-entity-graph/mixin-get-entity-graph.mjs +0 -269
  210. package/esm2022/mixin-save-queuing/breeze-client-mixin-save-queuing.mjs +0 -5
  211. package/esm2022/mixin-save-queuing/mixin-save-queuing.mjs +0 -421
  212. package/esm2022/src/abstract-data-service-adapter.mjs +0 -325
  213. package/esm2022/src/array.mjs +0 -4
  214. package/esm2022/src/assert-param.mjs +0 -330
  215. package/esm2022/src/breeze.mjs +0 -85
  216. package/esm2022/src/complex-array.mjs +0 -117
  217. package/esm2022/src/config.mjs +0 -232
  218. package/esm2022/src/core.mjs +0 -712
  219. package/esm2022/src/csdl-metadata-parser.mjs +0 -385
  220. package/esm2022/src/data-service.mjs +0 -221
  221. package/esm2022/src/data-type.mjs +0 -510
  222. package/esm2022/src/default-property-interceptor.mjs +0 -460
  223. package/esm2022/src/entity-action.mjs +0 -45
  224. package/esm2022/src/entity-aspect.mjs +0 -897
  225. package/esm2022/src/entity-group.mjs +0 -192
  226. package/esm2022/src/entity-key.mjs +0 -125
  227. package/esm2022/src/entity-manager.mjs +0 -2163
  228. package/esm2022/src/entity-metadata.mjs +0 -2242
  229. package/esm2022/src/entity-query.mjs +0 -1024
  230. package/esm2022/src/entity-state.mjs +0 -107
  231. package/esm2022/src/enum.mjs +0 -143
  232. package/esm2022/src/event.mjs +0 -264
  233. package/esm2022/src/interface-registry.mjs +0 -39
  234. package/esm2022/src/key-generator.mjs +0 -110
  235. package/esm2022/src/local-query-comparison-options.mjs +0 -65
  236. package/esm2022/src/mapping-context.mjs +0 -411
  237. package/esm2022/src/naming-convention.mjs +0 -92
  238. package/esm2022/src/observable-array.mjs +0 -183
  239. package/esm2022/src/predicate.mjs +0 -1259
  240. package/esm2022/src/primitive-array.mjs +0 -85
  241. package/esm2022/src/query-options.mjs +0 -152
  242. package/esm2022/src/relation-array.mjs +0 -173
  243. package/esm2022/src/save-options.mjs +0 -41
  244. package/esm2022/src/unattached-children-map.mjs +0 -56
  245. package/esm2022/src/validate.mjs +0 -995
  246. package/esm2022/src/validation-options.mjs +0 -64
  247. package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs +0 -190
  248. package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs.map +0 -1
  249. package/fesm2022/breeze-client-adapter-ajax-fetch.mjs +0 -190
  250. package/fesm2022/breeze-client-adapter-ajax-fetch.mjs.map +0 -1
  251. package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs +0 -194
  252. package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs.map +0 -1
  253. package/fesm2022/breeze-client-adapter-ajax-jquery.mjs +0 -114
  254. package/fesm2022/breeze-client-adapter-ajax-jquery.mjs.map +0 -1
  255. package/fesm2022/breeze-client-adapter-ajax-post.mjs.map +0 -1
  256. package/fesm2022/breeze-client-adapter-data-service-odata.mjs +0 -516
  257. package/fesm2022/breeze-client-adapter-data-service-odata.mjs.map +0 -1
  258. package/fesm2022/breeze-client-adapter-data-service-webapi.mjs.map +0 -1
  259. package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs +0 -276
  260. package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs.map +0 -1
  261. package/fesm2022/breeze-client-adapter-model-library-ko.mjs +0 -248
  262. package/fesm2022/breeze-client-adapter-model-library-ko.mjs.map +0 -1
  263. package/fesm2022/breeze-client-adapter-uri-builder-json.mjs.map +0 -1
  264. package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs +0 -246
  265. package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs.map +0 -1
  266. package/fesm2022/breeze-client-mixin-get-entity-graph.mjs.map +0 -1
  267. package/fesm2022/breeze-client-mixin-save-queuing.mjs.map +0 -1
  268. package/fesm2022/breeze-client.mjs +0 -14144
  269. package/fesm2022/breeze-client.mjs.map +0 -1
  270. package/index.d.ts +0 -1
  271. package/mixin-get-entity-graph/index.d.ts +0 -5
  272. package/mixin-get-entity-graph/mixin-get-entity-graph.d.ts +0 -31
  273. package/mixin-save-queuing/index.d.ts +0 -5
  274. package/mixin-save-queuing/mixin-save-queuing.d.ts +0 -32
  275. package/src/abstract-data-service-adapter.d.ts +0 -84
  276. package/src/array.d.ts +0 -3
  277. package/src/breeze.d.ts +0 -139
  278. package/src/complex-array.d.ts +0 -13
  279. package/src/config.d.ts +0 -104
  280. package/src/core.d.ts +0 -164
  281. package/src/csdl-metadata-parser.d.ts +0 -7
  282. package/src/data-type.d.ts +0 -89
  283. package/src/default-property-interceptor.d.ts +0 -4
  284. package/src/entity-aspect.d.ts +0 -332
  285. package/src/entity-group.d.ts +0 -28
  286. package/src/entity-key.d.ts +0 -77
  287. package/src/entity-manager.d.ts +0 -680
  288. package/src/entity-metadata.d.ts +0 -988
  289. package/src/entity-query.d.ts +0 -444
  290. package/src/enum.d.ts +0 -100
  291. package/src/event.d.ts +0 -142
  292. package/src/interface-registry.d.ts +0 -150
  293. package/src/key-generator.d.ts +0 -12
  294. package/src/observable-array.d.ts +0 -52
  295. package/src/predicate.d.ts +0 -376
  296. package/src/primitive-array.d.ts +0 -7
  297. package/src/relation-array.d.ts +0 -18
  298. package/src/unattached-children-map.d.ts +0 -19
  299. package/src/validate.d.ts +0 -650
@@ -1,254 +1,332 @@
1
- import { EntityManager, EntityQuery, EntityState, ExpandClause } from 'breeze-client';
2
-
3
- //#region Copyright, Version, and Description
4
- function mixinEntityGraph(emclass) {
5
- const proto = EntityManager.prototype;
6
- if (!proto.getEntityGraph) {
7
- proto.getEntityGraph = getEntityGraph;
8
- }
9
- }
10
- mixinEntityGraph(EntityManager);
11
- function getEntityGraph(roots, expand) {
12
- if (roots instanceof EntityQuery) {
13
- let newRoots = this.executeQueryLocally(roots);
14
- return getEntityGraphCore(newRoots, expand || roots.expandClause);
15
- }
16
- else {
17
- return getEntityGraphCore(roots, expand);
18
- }
19
- }
20
- function getEntityGraphCore(root, expand) {
21
- let entityGroupMap;
22
- let graph = [];
23
- let rootType;
24
- let roots = Array.isArray(root) ? root : [root];
25
- addToGraph(roots); // removes dups & nulls
26
- roots = graph.slice(); // copy of de-duped roots
27
- if (roots.length) {
28
- getRootInfo();
29
- getExpand();
30
- buildGraph();
31
- }
32
- return graph;
33
- function addToGraph(entities) {
34
- entities.forEach(function (entity) {
35
- if (entity && graph.indexOf(entity) < 0) {
36
- graph.push(entity);
37
- }
38
- });
39
- }
40
- function getRootInfo() {
41
- let compatTypes;
42
- roots.forEach(function (root, ix) {
43
- let aspect;
44
- if (!root || !(aspect = root.entityAspect)) {
45
- throw getRootErr(ix, 'is not an entity');
46
- }
47
- if (aspect.entityState === EntityState.Detached) {
48
- throw getRootErr(ix, 'is a detached entity');
49
- }
50
- let em = aspect.entityManager;
51
- if (entityGroupMap) {
52
- if (entityGroupMap !== em._entityGroupMap) {
53
- throw getRootErr(ix, "has a different 'EntityManager' than other roots");
54
- }
55
- }
56
- else {
57
- entityGroupMap = em._entityGroupMap;
58
- }
59
- getRootType(root, ix);
60
- });
61
- function getRootErr(ix, msg) {
62
- return new Error("'getEntityGraph' root[" + ix + "] " + msg);
63
- }
64
- function getRootType(root, ix) {
65
- let thisType = root.entityType;
66
- if (!rootType) {
67
- rootType = thisType;
68
- return;
69
- }
70
- else if (rootType === thisType) {
71
- return;
72
- }
73
- // Types differs. Look for closest common base type
74
- // does thisType derive from current rootType?
75
- let baseType = rootType;
76
- do {
77
- compatTypes = compatTypes || baseType.getSelfAndSubtypes();
78
- if (compatTypes.indexOf(thisType) > -1) {
79
- rootType = baseType;
80
- return;
81
- }
82
- baseType = baseType.baseEntityType;
83
- compatTypes = null;
84
- } while (baseType);
85
- // does current rootType derives from thisType?
86
- baseType = thisType;
87
- do {
88
- compatTypes = baseType.getSelfAndSubtypes();
89
- if (compatTypes.indexOf(rootType) > -1) {
90
- rootType = baseType;
91
- return;
92
- }
93
- baseType = baseType.baseEntityType;
94
- } while (baseType);
95
- throw getRootErr(ix, "is not EntityType-compatible with other roots");
96
- }
97
- }
98
- function getExpand() {
99
- try {
100
- if (!expand) {
101
- expand = [];
102
- }
103
- else if (typeof expand === 'string') {
104
- // tricky because Breeze expandClause not exposed publically
105
- expand = new EntityQuery().expand(expand).expandClause;
106
- }
107
- if (expand instanceof ExpandClause && expand.propertyPaths) { // expand clause
108
- expand = expand.propertyPaths;
109
- }
110
- else if (Array.isArray(expand)) {
111
- if (!expand.every(function (elem) { return typeof elem === 'string'; })) {
112
- throw '';
113
- }
114
- }
115
- else {
116
- throw '';
117
- }
118
- }
119
- catch (_) {
120
- throw new Error("expand must be an expand string, array of string paths, or a query expand clause");
121
- }
122
- }
123
- function buildGraph() {
124
- if (expand && expand instanceof Array && expand.length) {
125
- let fns = expand.map(makePathFn);
126
- fns.forEach(function (fn) { fn(roots); });
127
- }
128
- }
129
- // Make function to get entities along a single expand path
130
- // such as 'Orders.OrderDetails.Product'
131
- function makePathFn(path) {
132
- let fns = [], segments = path.split('.'), type = rootType;
133
- for (let i = 0, slen = segments.length; i < slen; i++) {
134
- let f = makePathSegmentFn(type, segments[i]);
135
- type = f.navType;
136
- fns.push(f);
137
- }
138
- return function pathFn(entities) {
139
- for (let j = 0, flen = fns.length; j < flen; j++) {
140
- let elen = entities.length;
141
- if (elen === 0) {
142
- return;
143
- } // nothing left to explore
144
- // fn to get related entities for this path segment
145
- let fn = fns[j];
146
- // get entities related by this path segment
147
- let related = [];
148
- for (let k = 0; k < elen; k++) {
149
- related = related.concat(fn(entities[k]));
150
- }
151
- addToGraph(related);
152
- if (j >= flen - 1) {
153
- return;
154
- } // no more path segments
155
- // reset entities to deduped related entities
156
- entities = [];
157
- for (let l = 0, rlen = related.length; l < rlen; l++) {
158
- let r = related[l];
159
- if (entities.indexOf(r) < 0) {
160
- entities.push(r);
161
- }
162
- }
163
- }
164
- };
165
- }
166
- // Make function to get entities along a single expand path segment
167
- // such as the 'OrderDetails' in the 'Orders.OrderDetails.Product' path
168
- function makePathSegmentFn(baseType, segment) {
169
- let baseTypeName, fn = undefined, navType;
170
- try {
171
- baseTypeName = baseType.name;
172
- let nav = baseType.getNavigationProperty(segment);
173
- let fkName = nav.foreignKeyNames[0];
174
- if (!nav) {
175
- throw new Error(segment + " is not a navigation property of " + baseTypeName);
176
- }
177
- navType = nav.entityType;
178
- // add derived types
179
- let navTypes = navType.getSelfAndSubtypes();
180
- let grps = []; // non-empty groups for these types
181
- navTypes.forEach(function (t) {
182
- let grp = entityGroupMap[t.name];
183
- if (grp && grp._entities.length > 0) {
184
- grps.push(grp);
185
- }
186
- });
187
- let grpCount = grps.length;
188
- if (grpCount === 0) {
189
- // no related entities in cache
190
- fn = function () { return []; };
191
- }
192
- else if (fkName) {
193
- fn = function (entity) {
194
- let val = null;
195
- try {
196
- let keyValue = entity.getProperty(fkName);
197
- for (let i = 0; i < grpCount; i += 1) {
198
- val = grps[i]._entities[grps[i]._indexMap[keyValue]];
199
- if (val) {
200
- break;
201
- }
202
- }
203
- }
204
- catch (e) {
205
- rethrow(e);
206
- }
207
- return val;
208
- };
209
- }
210
- else {
211
- fkName = nav.inverse ?
212
- nav.inverse.foreignKeyNames[0] :
213
- nav.invForeignKeyNames[0];
214
- if (!fkName) {
215
- throw new Error("No inverse keys");
216
- }
217
- fn = function (entity) {
218
- let vals = [];
219
- try {
220
- let keyValue = entity.entityAspect.getKey().values[0];
221
- grps.forEach(function (grp) {
222
- vals = vals.concat(grp._entities.filter(function (en) {
223
- return en && en.getProperty(fkName) === keyValue;
224
- }));
225
- });
226
- }
227
- catch (e) {
228
- rethrow(e);
229
- }
230
- return vals;
231
- };
232
- }
233
- fn.navType = navType;
234
- fn.path = segment;
235
- }
236
- catch (err) {
237
- rethrow(err);
238
- }
239
- return fn;
240
- function rethrow(e) {
241
- let typeName = baseTypeName || baseType;
242
- let error = new Error("'getEntityGraph' can't expand '" + segment + "' for " + typeName);
243
- error.innerError = e;
244
- throw error;
245
- }
246
- }
247
- }
248
-
249
- /**
250
- * Generated bundle index. Do not edit.
1
+ //#region Copyright, Version, and Description
2
+ /*
3
+ * Copyright 2015-2026 IdeaBlade, Inc. All Rights Reserved.
4
+ * Use, reproduction, distribution, and modification of this code is subject to the terms and
5
+ * conditions of the IdeaBlade Breeze license, available at http://www.breezejs.com/license
6
+ *
7
+ * Author: Ward Bell
8
+ * Version: 0.9.5 - Steve Schmitt - convert to TypeScript, migrate to breeze-client repo, add HasEntityGraph and mixinEntityGraph
9
+ * Version: 0.9.4 - Marcel Good - fix UMD module name
10
+ * --------------------------------------------------------------------------------
11
+ * Adds getEntityGraph method to Breeze EntityManager prototype.
12
+ * Call mixinEntityGraph(EntityManager) to apply the mixin in a tree-shaking-resistant way.
13
+ * Then (manager as any).getEntityGraph(entity, "child");
14
+ *
15
+ * Depends on Breeze which it patches
16
+ *
17
+ * For discussion, see:
18
+ * http://www.breezejs.com/documentation/getentitygraph
19
+ *
20
+ * For example usage, see:
21
+ * https://github.com/Breeze/breeze.js.samples/tree/master/net/DocCode/DocCode/tests/getEntityGraphTests.js
22
+ */
23
+ //#endregion
24
+ import { EntityManager, EntityQuery, EntityState, ExpandClause } from '../breeze.js';
25
+ /**
26
+ * Adds `getEntityGraph` to `EntityManager.prototype`.
27
+ *
28
+ * Importing this module calls it, so an application only needs the import:
29
+ *
30
+ * ```ts
31
+ * import 'breeze-client/mixin-get-entity-graph';
32
+ * import type { HasEntityGraph } from 'breeze-client/mixin-get-entity-graph';
33
+ *
34
+ * const graph = (em as HasEntityGraph).getEntityGraph(customer, 'orders.orderDetails');
35
+ * ```
36
+ *
37
+ * Calling it yourself is for a bundler aggressive enough to drop a module imported only for its
38
+ * effect. This is the one module in the package that `sideEffects` in package.json names for
39
+ * that reason.
40
+ *
41
+ * @param emclass - Accepted for backwards compatibility and not used: the method always goes on
42
+ * `EntityManager.prototype`. Adding it twice is a no-op.
43
+ *
44
+ * @see {@link HasEntityGraph} for the method it adds.
251
45
  */
252
-
253
- export { mixinEntityGraph };
254
- //# sourceMappingURL=breeze-client-mixin-get-entity-graph.mjs.map
46
+ export function mixinEntityGraph(emclass) {
47
+ const proto = EntityManager.prototype;
48
+ if (!proto.getEntityGraph) {
49
+ proto.getEntityGraph = getEntityGraph;
50
+ }
51
+ }
52
+ mixinEntityGraph(EntityManager);
53
+ function getEntityGraph(roots, expand) {
54
+ if (roots instanceof EntityQuery) {
55
+ let newRoots = this.executeQueryLocally(roots);
56
+ return getEntityGraphCore(newRoots, expand || roots.expandClause);
57
+ }
58
+ else {
59
+ return getEntityGraphCore(roots, expand);
60
+ }
61
+ }
62
+ function getEntityGraphCore(root, expand) {
63
+ let entityGroupMap;
64
+ let graph = [];
65
+ // Membership of `graph`, kept beside it. The graph stays an array because that is what is
66
+ // returned and its order is part of the result; the Set is only how "is it already in there"
67
+ // is answered, which `indexOf` made cost the size of the graph so far - quadratic over an
68
+ // expand that pulls in thousands of entities.
69
+ let inGraph = new Set();
70
+ let rootType;
71
+ let roots = Array.isArray(root) ? root : [root];
72
+ addToGraph(roots); // removes dups & nulls
73
+ roots = graph.slice(); // copy of de-duped roots
74
+ if (roots.length) {
75
+ getRootInfo();
76
+ getExpand();
77
+ buildGraph();
78
+ }
79
+ return graph;
80
+ function addToGraph(entities) {
81
+ entities.forEach(function (entity) {
82
+ if (entity && !inGraph.has(entity)) {
83
+ inGraph.add(entity);
84
+ graph.push(entity);
85
+ }
86
+ });
87
+ }
88
+ function getRootInfo() {
89
+ let compatTypes;
90
+ roots.forEach(function (root, ix) {
91
+ let aspect;
92
+ if (!root || !(aspect = root.entityAspect)) {
93
+ throw getRootErr(ix, 'is not an entity');
94
+ }
95
+ if (aspect.entityState === EntityState.Detached) {
96
+ throw getRootErr(ix, 'is a detached entity');
97
+ }
98
+ // roots are rejected above if Detached, so an attached root always has a manager
99
+ let em = aspect.entityManager;
100
+ if (entityGroupMap) {
101
+ if (entityGroupMap !== em._entityGroupMap) {
102
+ throw getRootErr(ix, "has a different 'EntityManager' than other roots");
103
+ }
104
+ }
105
+ else {
106
+ entityGroupMap = em._entityGroupMap;
107
+ }
108
+ getRootType(root, ix);
109
+ });
110
+ function getRootErr(ix, msg) {
111
+ return new Error("'getEntityGraph' root[" + ix + "] " + msg);
112
+ }
113
+ function getRootType(root, ix) {
114
+ let thisType = root.entityType;
115
+ if (!rootType) {
116
+ rootType = thisType;
117
+ return;
118
+ }
119
+ else if (rootType === thisType) {
120
+ return;
121
+ }
122
+ // Types differs. Look for closest common base type
123
+ // does thisType derive from current rootType?
124
+ let baseType = rootType;
125
+ do {
126
+ compatTypes = compatTypes || baseType.getSelfAndSubtypes();
127
+ if (compatTypes.indexOf(thisType) > -1) {
128
+ rootType = baseType;
129
+ return;
130
+ }
131
+ baseType = baseType.baseEntityType;
132
+ compatTypes = null;
133
+ } while (baseType);
134
+ // does current rootType derives from thisType?
135
+ baseType = thisType;
136
+ do {
137
+ compatTypes = baseType.getSelfAndSubtypes();
138
+ if (compatTypes.indexOf(rootType) > -1) {
139
+ rootType = baseType;
140
+ return;
141
+ }
142
+ baseType = baseType.baseEntityType;
143
+ } while (baseType);
144
+ throw getRootErr(ix, "is not EntityType-compatible with other roots");
145
+ }
146
+ }
147
+ function getExpand() {
148
+ try {
149
+ if (!expand) {
150
+ expand = [];
151
+ }
152
+ else if (typeof expand === 'string') {
153
+ // tricky because Breeze expandClause not exposed publically
154
+ expand = new EntityQuery().expand(expand).expandClause;
155
+ }
156
+ if (expand instanceof ExpandClause && expand.propertyPaths) { // expand clause
157
+ expand = expand.propertyPaths;
158
+ }
159
+ else if (Array.isArray(expand)) {
160
+ if (!expand.every(function (elem) { return typeof elem === 'string'; })) {
161
+ throw '';
162
+ }
163
+ }
164
+ else {
165
+ throw '';
166
+ }
167
+ }
168
+ catch (_) {
169
+ throw new Error("expand must be an expand string, array of string paths, or a query expand clause");
170
+ }
171
+ }
172
+ function buildGraph() {
173
+ if (expand && expand instanceof Array && expand.length) {
174
+ let fns = expand.map(makePathFn);
175
+ fns.forEach(function (fn) { fn(roots); });
176
+ }
177
+ }
178
+ // Make function to get entities along a single expand path
179
+ // such as 'Orders.OrderDetails.Product'
180
+ function makePathFn(path) {
181
+ let fns = [], segments = path.split('.'), type = rootType;
182
+ for (let i = 0, slen = segments.length; i < slen; i++) {
183
+ let f = makePathSegmentFn(type, segments[i]);
184
+ type = f.navType;
185
+ fns.push(f);
186
+ }
187
+ return function pathFn(entities) {
188
+ for (let j = 0, flen = fns.length; j < flen; j++) {
189
+ let elen = entities.length;
190
+ if (elen === 0) {
191
+ return;
192
+ } // nothing left to explore
193
+ // fn to get related entities for this path segment
194
+ let fn = fns[j];
195
+ // get entities related by this path segment
196
+ // `related = related.concat(...)` per source entity copied the whole array each time,
197
+ // which is quadratic in its own right; push into the one array instead.
198
+ let related = [];
199
+ for (let k = 0; k < elen; k++) {
200
+ let next = fn(entities[k]);
201
+ if (Array.isArray(next)) {
202
+ for (let m = 0, nlen = next.length; m < nlen; m++)
203
+ related.push(next[m]);
204
+ }
205
+ else if (next) {
206
+ related.push(next);
207
+ }
208
+ }
209
+ addToGraph(related);
210
+ if (j >= flen - 1) {
211
+ return;
212
+ } // no more path segments
213
+ // reset entities to deduped related entities - by Set, for the same reason as addToGraph
214
+ entities = [];
215
+ let seen = new Set();
216
+ for (let l = 0, rlen = related.length; l < rlen; l++) {
217
+ let r = related[l];
218
+ if (!seen.has(r)) {
219
+ seen.add(r);
220
+ entities.push(r);
221
+ }
222
+ }
223
+ }
224
+ };
225
+ }
226
+ // Make function to get entities along a single expand path segment
227
+ // such as the 'OrderDetails' in the 'Orders.OrderDetails.Product' path
228
+ function makePathSegmentFn(baseType, segment) {
229
+ let baseTypeName, fn = undefined, navType;
230
+ try {
231
+ baseTypeName = baseType.name;
232
+ let nav = baseType.getNavigationProperty(segment);
233
+ let fkName = nav.foreignKeyNames[0];
234
+ if (!nav) {
235
+ throw new Error(segment + " is not a navigation property of " + baseTypeName);
236
+ }
237
+ navType = nav.entityType;
238
+ // add derived types
239
+ let navTypes = navType.getSelfAndSubtypes();
240
+ let grps = []; // non-empty groups for these types
241
+ navTypes.forEach(function (t) {
242
+ let grp = entityGroupMap.get(t.name);
243
+ if (grp && grp._entities.length > 0) {
244
+ grps.push(grp);
245
+ }
246
+ });
247
+ let grpCount = grps.length;
248
+ if (grpCount === 0) {
249
+ // no related entities in cache
250
+ fn = function () { return []; };
251
+ }
252
+ else if (fkName) {
253
+ fn = function (entity) {
254
+ let val = null;
255
+ try {
256
+ // `_indexMap` is keyed by the key *string*; a foreign key value is often a number.
257
+ let keyValue = String(entity.getProperty(fkName));
258
+ for (let i = 0; i < grpCount; i += 1) {
259
+ let ix = grps[i]._indexMap.get(keyValue);
260
+ val = ix === undefined ? null : grps[i]._entities[ix];
261
+ if (val) {
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ catch (e) {
267
+ rethrow(e);
268
+ }
269
+ return val;
270
+ };
271
+ }
272
+ else {
273
+ fkName = nav.inverse ?
274
+ nav.inverse.foreignKeyNames[0] :
275
+ nav.invForeignKeyNames[0];
276
+ if (!fkName) {
277
+ throw new Error("No inverse keys");
278
+ }
279
+ // The children of one parent, indexed by the foreign key that points at it. This used to
280
+ // filter every entity of the navigated type for every parent entity, so an expand over n
281
+ // parents and m children cost n*m: `getEntityGraph(customer, 'orders.orderDetails')` on
282
+ // 8,000 orders and 24,000 details took about 5 s, nearly all of it here.
283
+ //
284
+ // Built on first use, so a path segment with no parents to walk still costs nothing, and
285
+ // in the same order the filter produced: group by group, and index order within a group.
286
+ // The lookup is by the raw property value, which is what the `===` comparison used.
287
+ let byFk;
288
+ fn = function (entity) {
289
+ try {
290
+ if (byFk === undefined) {
291
+ byFk = new Map();
292
+ grps.forEach(function (grp) {
293
+ grp._entities.forEach(function (en) {
294
+ if (!en)
295
+ return;
296
+ let fkValue = en.getProperty(fkName);
297
+ let siblings = byFk.get(fkValue);
298
+ if (siblings) {
299
+ siblings.push(en);
300
+ }
301
+ else {
302
+ byFk.set(fkValue, [en]);
303
+ }
304
+ });
305
+ });
306
+ }
307
+ let keyValue = entity.entityAspect.getKey().values[0];
308
+ return byFk.get(keyValue) ?? [];
309
+ }
310
+ catch (e) {
311
+ rethrow(e);
312
+ }
313
+ return [];
314
+ };
315
+ }
316
+ fn.navType = navType;
317
+ fn.path = segment;
318
+ }
319
+ catch (err) {
320
+ rethrow(err);
321
+ }
322
+ // every path above either assigns fn or rethrows
323
+ return fn;
324
+ function rethrow(e) {
325
+ let typeName = baseTypeName || baseType;
326
+ let error = new Error("'getEntityGraph' can't expand '" + segment + "' for " + typeName);
327
+ error.innerError = e;
328
+ throw error;
329
+ }
330
+ }
331
+ }
332
+ //# sourceMappingURL=mixin-get-entity-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mixin-get-entity-graph.js","sourceRoot":"","sources":["../../src/mixins/mixin-get-entity-graph.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,YAAY;AACZ,OAAO,EAAU,aAAa,EAAE,WAAW,EAAE,WAAW,EAAc,YAAY,EAAE,MAAM,cAAc,CAAC;AAiDzG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAiC;IAChE,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC;IAEtC,IAAI,CAAE,KAAa,CAAC,cAAc,EAAE,CAAC;QAClC,KAAa,CAAC,cAAc,GAAG,cAAc,CAAC;IACjD,CAAC;AACH,CAAC;AAED,gBAAgB,CAAC,aAAa,CAAC,CAAC;AAGhC,SAAS,cAAc,CAAC,KAA2C,EAAE,MAA8C;IACjH,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,IAAI,QAAQ,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC/C,OAAO,kBAAkB,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IACpE,CAAC;SAAM,CAAC;QACN,OAAO,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,IAA4B,EAAE,MAA8C;IACtG,IAAI,cAAwC,CAAC;IAC7C,IAAI,KAAK,GAAG,EAAmB,CAAC;IAChC,0FAA0F;IAC1F,6FAA6F;IAC7F,0FAA0F;IAC1F,8CAA8C;IAC9C,IAAI,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,IAAI,QAAoB,CAAC;IACzB,IAAI,KAAK,GAAG,KAAK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AAI,QAAQ,EAAE,CAAC;wCAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oCAAC,CAAC;yCAAM,CAAC;wCAAC,IAAK,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;oCAAC,CAAC;gCACzE,CAAC,CAAC,CAAC;4BACL,CAAC,CAAC,CAAC;wBACL,CAAC;wBACD,IAAI,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;wBACtD,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAK,EAAoB,CAAC;oBACrD,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBAAC,OAAO,CAAC,CAAC,CAAC,CAAC;oBAAC,CAAC;oBAC3B,OAAO,EAAmB,CAAC;gBAC7B,CAAC,CAAC;YACJ,CAAC;YACA,EAAU,CAAC,OAAO,GAAG,OAAO,CAAC;YAC7B,EAAU,CAAC,IAAI,GAAG,OAAO,CAAC;QAE7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAAC,CAAC;QAC/B,iDAAiD;QACjD,OAAO,EAAG,CAAC;QAEX,SAAS,OAAO,CAAC,CAAQ;YACvB,IAAI,QAAQ,GAAG,YAAY,IAAI,QAAQ,CAAC;YACxC,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC,iCAAiC,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;YACxF,KAAa,CAAC,UAAU,GAAG,CAAC,CAAC;YAC9B,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["//#region Copyright, Version, and Description\r\n/*\r\n * Copyright 2015-2026 IdeaBlade, Inc. All Rights Reserved.\r\n * Use, reproduction, distribution, and modification of this code is subject to the terms and\r\n * conditions of the IdeaBlade Breeze license, available at http://www.breezejs.com/license\r\n *\r\n * Author: Ward Bell\r\n * Version: 0.9.5 - Steve Schmitt - convert to TypeScript, migrate to breeze-client repo, add HasEntityGraph and mixinEntityGraph\r\n * Version: 0.9.4 - Marcel Good - fix UMD module name\r\n * --------------------------------------------------------------------------------\r\n * Adds getEntityGraph method to Breeze EntityManager prototype.\r\n * Call mixinEntityGraph(EntityManager) to apply the mixin in a tree-shaking-resistant way.\r\n * Then (manager as any).getEntityGraph(entity, \"child\");\r\n *\r\n * Depends on Breeze which it patches\r\n *\r\n * For discussion, see:\r\n * http://www.breezejs.com/documentation/getentitygraph\r\n *\r\n * For example usage, see:\r\n * https://github.com/Breeze/breeze.js.samples/tree/master/net/DocCode/DocCode/tests/getEntityGraphTests.js\r\n */\r\n//#endregion\r\nimport { Entity, EntityManager, EntityQuery, EntityState, EntityType, ExpandClause } from '../breeze.js';\r\n\r\ninterface EntityGroup {\r\n _entities: (Entity | null)[];\r\n _indexMap: Map<string, number>;\r\n}\r\n\r\n/**\r\n * An {@link EntityManager} with `getEntityGraph`, which returns entities together with everything\r\n * an expand path reaches from them in the cache, including deleted entities. Importing\r\n * `breeze-client/mixin-get-entity-graph` adds the method to every manager, but changes the\r\n * prototype rather than the `EntityManager` type, so cast to this type to call it:\r\n *\r\n * ```ts\r\n * import 'breeze-client/mixin-get-entity-graph';\r\n * import type { HasEntityGraph } from 'breeze-client/mixin-get-entity-graph';\r\n *\r\n * const graph = (em as HasEntityGraph).getEntityGraph(customer, 'orders.orderDetails');\r\n * ```\r\n */\r\n// module augmentation failed to build with ng-packagr, so we have a separate interface\r\nexport interface HasEntityGraph extends EntityManager {\r\n /**\r\n Get related entities of root entity (or root entities) as specified by expand.\r\n @example\r\n const graph = (em as HasEntityGraph).getEntityGraph(customer, 'orders.orderDetails');\r\n // the customer, all of its orders, and their details - including deleted ones\r\n @param roots {Entity|Array of Entity} The root entity or root entities.\r\n @param expand {String|Array of String|Object} an expand string, a query expand clause, or array of string paths\r\n @returns {Array of Entity} root entities and their related entities, including deleted entities. Duplicates are removed and entity order is indeterminate.\r\n */\r\n getEntityGraph(roots: Entity | Array<Entity>, expand: string | Array<string> | ExpandClause): Array<Entity>;\r\n\r\n /**\r\n Execute query locally and return both the query results and their related entities as specified by the optional expand parameter or the query's expand clause.\r\n @example\r\n const query = EntityQuery.from(Customer)\r\n .where('companyName', 'startsWith', 'Alfred')\r\n .expand('orders.orderDetails');\r\n const graph = (em as HasEntityGraph).getEntityGraph(query);\r\n // the 'Alfred' customers, their orders, and their details - including deleted ones\r\n @param query {EntityQuery} A query to be executed against the manager's local cache.\r\n @param [expand] {String|Array of String|Object} an expand string, a query expand clause, or array of string paths\r\n @returns {Array of Entity} local queried root entities and their related entities, including deleted entities. Duplicates are removed and entity order is indeterminate.\r\n */\r\n getEntityGraph(query: EntityQuery, expand?: string | Array<string> | ExpandClause): Array<Entity>;\r\n\r\n}\r\n\r\n/**\r\n * Adds `getEntityGraph` to `EntityManager.prototype`.\r\n *\r\n * Importing this module calls it, so an application only needs the import:\r\n *\r\n * ```ts\r\n * import 'breeze-client/mixin-get-entity-graph';\r\n * import type { HasEntityGraph } from 'breeze-client/mixin-get-entity-graph';\r\n *\r\n * const graph = (em as HasEntityGraph).getEntityGraph(customer, 'orders.orderDetails');\r\n * ```\r\n *\r\n * Calling it yourself is for a bundler aggressive enough to drop a module imported only for its\r\n * effect. This is the one module in the package that `sideEffects` in package.json names for\r\n * that reason.\r\n *\r\n * @param emclass - Accepted for backwards compatibility and not used: the method always goes on\r\n * `EntityManager.prototype`. Adding it twice is a no-op.\r\n *\r\n * @see {@link HasEntityGraph} for the method it adds.\r\n */\r\nexport function mixinEntityGraph(emclass: { new(): EntityManager }) {\r\n const proto = EntityManager.prototype;\r\n\r\n if (!(proto as any).getEntityGraph) {\r\n (proto as any).getEntityGraph = getEntityGraph;\r\n }\r\n}\r\n\r\nmixinEntityGraph(EntityManager);\r\n\r\n\r\nfunction getEntityGraph(roots: Entity | Array<Entity> | EntityQuery, expand?: string | Array<string> | ExpandClause) {\r\n if (roots instanceof EntityQuery) {\r\n let newRoots = this.executeQueryLocally(roots);\r\n return getEntityGraphCore(newRoots, expand || roots.expandClause);\r\n } else {\r\n return getEntityGraphCore(roots, expand);\r\n }\r\n}\r\n\r\nfunction getEntityGraphCore(root: Entity | Array<Entity>, expand?: string | Array<string> | ExpandClause) {\r\n let entityGroupMap: Map<string, EntityGroup>;\r\n let graph = [] as Array<Entity>;\r\n // Membership of `graph`, kept beside it. The graph stays an array because that is what is\r\n // returned and its order is part of the result; the Set is only how \"is it already in there\"\r\n // is answered, which `indexOf` made cost the size of the graph so far - quadratic over an\r\n // expand that pulls in thousands of entities.\r\n let inGraph = new Set<Entity>();\r\n let rootType: EntityType;\r\n let roots = Array.isArray(root) ? root : [root];\r\n addToGraph(roots); // removes dups & nulls\r\n roots = graph.slice(); // copy of de-duped roots\r\n if (roots.length) {\r\n getRootInfo();\r\n getExpand();\r\n buildGraph();\r\n }\r\n return graph;\r\n\r\n function addToGraph(entities: Array<Entity>) {\r\n entities.forEach(function (entity) {\r\n if (entity && !inGraph.has(entity)) {\r\n inGraph.add(entity);\r\n graph.push(entity);\r\n }\r\n });\r\n }\r\n\r\n function getRootInfo() {\r\n let compatTypes: Array<EntityType> | null;\r\n\r\n roots.forEach(function (root, ix) {\r\n let aspect;\r\n if (!root || !(aspect = root.entityAspect)) {\r\n throw getRootErr(ix, 'is not an entity');\r\n }\r\n if (aspect.entityState === EntityState.Detached) {\r\n throw getRootErr(ix, 'is a detached entity');\r\n }\r\n\r\n // roots are rejected above if Detached, so an attached root always has a manager\r\n let em = aspect.entityManager!;\r\n if (entityGroupMap) {\r\n if (entityGroupMap !== em._entityGroupMap) {\r\n throw getRootErr(ix, \"has a different 'EntityManager' than other roots\");\r\n }\r\n } else {\r\n entityGroupMap = em._entityGroupMap;\r\n }\r\n getRootType(root, ix);\r\n\r\n });\r\n\r\n function getRootErr(ix: number, msg: string) {\r\n return new Error(\"'getEntityGraph' root[\" + ix + \"] \" + msg);\r\n }\r\n\r\n function getRootType(root: Entity, ix: number) {\r\n let thisType = root.entityType;\r\n if (!rootType) {\r\n rootType = thisType;\r\n return;\r\n } else if (rootType === thisType) {\r\n return;\r\n }\r\n // Types differs. Look for closest common base type\r\n // does thisType derive from current rootType?\r\n let baseType = rootType;\r\n do {\r\n compatTypes = compatTypes || baseType.getSelfAndSubtypes();\r\n if (compatTypes.indexOf(thisType) > -1) {\r\n rootType = baseType;\r\n return;\r\n }\r\n baseType = baseType.baseEntityType;\r\n compatTypes = null;\r\n } while (baseType);\r\n\r\n // does current rootType derives from thisType?\r\n baseType = thisType;\r\n do {\r\n compatTypes = baseType.getSelfAndSubtypes();\r\n if (compatTypes.indexOf(rootType) > -1) {\r\n rootType = baseType;\r\n return;\r\n }\r\n baseType = baseType.baseEntityType;\r\n } while (baseType);\r\n\r\n throw getRootErr(ix, \"is not EntityType-compatible with other roots\");\r\n }\r\n }\r\n\r\n function getExpand() {\r\n try {\r\n if (!expand) {\r\n expand = [];\r\n } else if (typeof expand === 'string') {\r\n // tricky because Breeze expandClause not exposed publically\r\n expand = new EntityQuery().expand(expand).expandClause!;\r\n }\r\n if (expand instanceof ExpandClause && expand.propertyPaths) { // expand clause\r\n expand = expand.propertyPaths;\r\n } else if (Array.isArray(expand)) {\r\n if (!expand.every(function (elem) { return typeof elem === 'string'; })) {\r\n throw '';\r\n }\r\n } else {\r\n throw '';\r\n }\r\n } catch (_) {\r\n throw new Error(\r\n \"expand must be an expand string, array of string paths, or a query expand clause\");\r\n }\r\n }\r\n\r\n function buildGraph() {\r\n if (expand && expand instanceof Array && expand.length) {\r\n let fns = expand.map(makePathFn);\r\n fns.forEach(function (fn) { fn(roots); });\r\n }\r\n }\r\n\r\n // Make function to get entities along a single expand path\r\n // such as 'Orders.OrderDetails.Product'\r\n function makePathFn(path: string) {\r\n let fns = [] as Array<Function>,\r\n segments = path.split('.'),\r\n type = rootType;\r\n\r\n for (let i = 0, slen = segments.length; i < slen; i++) {\r\n let f = makePathSegmentFn(type, segments[i]);\r\n type = (f as any).navType;\r\n fns.push(f);\r\n }\r\n\r\n return function pathFn(entities: Array<Entity>) {\r\n for (let j = 0, flen = fns.length; j < flen; j++) {\r\n let elen = entities.length;\r\n if (elen === 0) { return; } // nothing left to explore\r\n // fn to get related entities for this path segment\r\n let fn = fns[j];\r\n // get entities related by this path segment\r\n // `related = related.concat(...)` per source entity copied the whole array each time,\r\n // which is quadratic in its own right; push into the one array instead.\r\n let related = [] as Array<Entity>;\r\n for (let k = 0; k < elen; k++) {\r\n let next = fn(entities[k]);\r\n if (Array.isArray(next)) {\r\n for (let m = 0, nlen = next.length; m < nlen; m++) related.push(next[m]);\r\n } else if (next) {\r\n related.push(next);\r\n }\r\n }\r\n addToGraph(related);\r\n if (j >= flen - 1) { return; } // no more path segments\r\n\r\n // reset entities to deduped related entities - by Set, for the same reason as addToGraph\r\n entities = [];\r\n let seen = new Set<Entity>();\r\n for (let l = 0, rlen = related.length; l < rlen; l++) {\r\n let r = related[l];\r\n if (!seen.has(r)) { seen.add(r); entities.push(r); }\r\n }\r\n }\r\n };\r\n }\r\n\r\n // Make function to get entities along a single expand path segment\r\n // such as the 'OrderDetails' in the 'Orders.OrderDetails.Product' path\r\n function makePathSegmentFn(baseType: EntityType, segment: string) {\r\n let baseTypeName: string, fn = undefined, navType;\r\n try {\r\n baseTypeName = baseType.name;\r\n let nav = baseType.getNavigationProperty(segment);\r\n let fkName = nav.foreignKeyNames[0];\r\n if (!nav) {\r\n throw new Error(segment + \" is not a navigation property of \" + baseTypeName);\r\n }\r\n navType = nav.entityType;\r\n // add derived types\r\n let navTypes = navType.getSelfAndSubtypes();\r\n let grps = [] as Array<EntityGroup>; // non-empty groups for these types\r\n navTypes.forEach(function (t) {\r\n let grp = entityGroupMap.get(t.name);\r\n if (grp && grp._entities.length > 0) {\r\n grps.push(grp);\r\n }\r\n });\r\n let grpCount = grps.length;\r\n if (grpCount === 0) {\r\n // no related entities in cache\r\n fn = function () { return [] as Array<Entity>; };\r\n } else if (fkName) {\r\n fn = function (entity: Entity) {\r\n let val = null;\r\n try {\r\n // `_indexMap` is keyed by the key *string*; a foreign key value is often a number.\r\n let keyValue = String(entity.getProperty(fkName));\r\n for (let i = 0; i < grpCount; i += 1) {\r\n let ix = grps[i]._indexMap.get(keyValue);\r\n val = ix === undefined ? null : grps[i]._entities[ix];\r\n if (val) { break; }\r\n }\r\n } catch (e) { rethrow(e); }\r\n return val;\r\n };\r\n } else {\r\n fkName = nav.inverse ?\r\n nav.inverse.foreignKeyNames[0] :\r\n nav.invForeignKeyNames[0];\r\n if (!fkName) { throw new Error(\"No inverse keys\"); }\r\n // The children of one parent, indexed by the foreign key that points at it. This used to\r\n // filter every entity of the navigated type for every parent entity, so an expand over n\r\n // parents and m children cost n*m: `getEntityGraph(customer, 'orders.orderDetails')` on\r\n // 8,000 orders and 24,000 details took about 5 s, nearly all of it here.\r\n //\r\n // Built on first use, so a path segment with no parents to walk still costs nothing, and\r\n // in the same order the filter produced: group by group, and index order within a group.\r\n // The lookup is by the raw property value, which is what the `===` comparison used.\r\n let byFk: Map<any, Array<Entity>> | undefined;\r\n fn = function (entity: Entity) {\r\n try {\r\n if (byFk === undefined) {\r\n byFk = new Map();\r\n grps.forEach(function (grp) {\r\n grp._entities.forEach(function (en) {\r\n if (!en) return;\r\n let fkValue = en.getProperty(fkName);\r\n let siblings = byFk!.get(fkValue);\r\n if (siblings) { siblings.push(en); } else { byFk!.set(fkValue, [en]); }\r\n });\r\n });\r\n }\r\n let keyValue = entity.entityAspect.getKey().values[0];\r\n return byFk.get(keyValue) ?? ([] as Array<Entity>);\r\n } catch (e) { rethrow(e); }\r\n return [] as Array<Entity>;\r\n };\r\n }\r\n (fn as any).navType = navType;\r\n (fn as any).path = segment;\r\n\r\n } catch (err) { rethrow(err); }\r\n // every path above either assigns fn or rethrows\r\n return fn!;\r\n\r\n function rethrow(e: Error) {\r\n let typeName = baseTypeName || baseType;\r\n let error = new Error(\"'getEntityGraph' can't expand '\" + segment + \"' for \" + typeName);\r\n (error as any).innerError = e;\r\n throw error;\r\n }\r\n }\r\n}\r\n\r\n\r\n"]}