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
@@ -0,0 +1,801 @@
1
+ import { DataServiceAdapter } from '../config/interface-registry.js';
2
+ import { Callback, ErrorCallback } from '../core/core.js';
3
+ import { BreezeEvent } from '../core/event.js';
4
+ import { Entity, ComplexObject, StructuralObject, PropertyChangedEventArgs } from '../entity/entity-aspect.js';
5
+ import type { RelationArray } from '../entity/relation-array.js';
6
+ import { MetadataStore, EntityType, DataProperty } from '../metadata/entity-metadata.js';
7
+ import { EntityKey } from '../entity/entity-key.js';
8
+ import { EntityAction } from '../entity/entity-action.js';
9
+ import { EntityState } from '../entity/entity-state.js';
10
+ import { DataService } from '../metadata/data-service.js';
11
+ import { ValidationError } from '../validation/validate.js';
12
+ import { ValidationOptions } from '../validation/validation-options.js';
13
+ import { QueryOptions, MergeStrategy } from '../query/query-options.js';
14
+ import { SaveOptions } from './save-options.js';
15
+ import { KeyGenerator } from '../entity/key-generator.js';
16
+ import { EntityQuery } from '../query/entity-query.js';
17
+ import type { KeyValues } from '../query/property-path.js';
18
+ /** The response to one HTTP request Breeze made, as its data service adapter received it. Found on
19
+ {@link ServerError.httpResponse}, {@link QueryResult.httpResponse} and {@link SaveResult.httpResponse}. */
20
+ export interface HttpResponse {
21
+ /** The request that was sent: its {@link AjaxConfig} without the callbacks - `url`, `type` (the
22
+ HTTP method), `params`, `data`, `headers` and so on. */
23
+ config: any;
24
+ /** The response body: the parsed JSON of a successful response, or the text of a failed one.
25
+ Null when the request failed before any response arrived, or its body could not be read. */
26
+ data: any;
27
+ /** Set only when the request failed: the error the transport threw if the request could not be
28
+ completed or its body could not be read, otherwise the status text. */
29
+ error?: any;
30
+ /** Set by Breeze on the response to a save request, where it is used to turn the server's
31
+ per-entity errors into {@link EntityError}s. Undefined for queries and metadata requests.
32
+ Applications do not normally need it. */
33
+ saveContext?: any;
34
+ /** The HTTP status code. `0` when the request failed before any response arrived: offline, DNS,
35
+ CORS, a server that is down, or an aborted request. */
36
+ status: number;
37
+ /** The HTTP status text, such as "Not Found". Empty when the server sent none (HTTP/2 never does), and set to
38
+ the transport's error message when the request failed before any response arrived. May be absent with a custom ajax adapter. */
39
+ statusText?: string;
40
+ /** Returns the value of the named response header, or `null` if the response did not include it.
41
+ Called with an empty name, returns an object holding every header, keyed by lower-case name.
42
+ When no response arrived, returns `""` for a name and `{}` without one. */
43
+ getHeaders(headerName: string): string;
44
+ }
45
+ /** What {@link EntityManager.importEntities} returns. */
46
+ export interface ImportResult {
47
+ /** The entities in the bundle as they now are in this manager: the ones newly attached, and the
48
+ cached ones they were merged into - including any the {@link ImportConfig.mergeStrategy} left
49
+ unchanged. */
50
+ entities: Entity[];
51
+ /** The temporary keys in the bundle, each mapped to the temporary key its entity has in this
52
+ manager. See {@link ITempKeyMap}. */
53
+ tempKeyMapping: ITempKeyMap;
54
+ }
55
+ /** Base shape of any errors returned from the server. */
56
+ export interface ServerError extends Error {
57
+ /** The failed response, for anything the other members do not cover. */
58
+ httpResponse: HttpResponse;
59
+ /** The HTTP status code - see {@link HttpResponse.status}. `0` when the request failed before any
60
+ response arrived. */
61
+ status: number;
62
+ /** The best description Breeze could find: the message in the response body (a .NET exception's
63
+ message, or the `message`, `detail` or `title` of a JSON error), otherwise the transport's error
64
+ text. When the status is `0`, it also says the server was probably not reached. */
65
+ message: string;
66
+ /** The status text of the failed response - see {@link HttpResponse.statusText}. */
67
+ statusText?: string;
68
+ /** The body of the failed response, as the adapter received it (`httpResponse.data`); null if there was none. */
69
+ body?: any;
70
+ /** The URL the request was sent to (`httpResponse.config.url`). Query parameters added with
71
+ `EntityQuery.withParameters` are not included. */
72
+ url?: string;
73
+ /** The RFC 9457 `type` member of the problem document, when the server sent one: a URI naming
74
+ what kind of problem this is.
75
+
76
+ Read it rather than the message when the recovery depends on the kind of failure. The status
77
+ code is often not enough on its own - an optimistic concurrency conflict and a duplicate key are
78
+ both `409`, and they are recovered from differently - and message text is not something to match
79
+ on, since it varies by ORM, database and server version.
80
+
81
+ Undefined when the server sent no `type`, which is every pre-3.0 Breeze server and most
82
+ non-Breeze ones. See {@link ProblemTypes} and {@link isConcurrencyError}. */
83
+ problemType?: string;
84
+ }
85
+ /** The RFC 9457 `type` URIs a Breeze server sends on {@link ServerError.problemType}.
86
+
87
+ A problem type is a stable identifier for a *kind* of failure, which is what a status code often
88
+ is not: `409` covers both a concurrency conflict and a duplicate key, and the two call for
89
+ different recovery. */
90
+ export declare const ProblemTypes: {
91
+ /** A row was changed or deleted by someone else after this client read it. */
92
+ readonly concurrencyConflict: "https://breeze.github.io/problems/concurrency-conflict";
93
+ /** The save was rejected by validation; see `entityErrors`. */
94
+ readonly entityErrors: "https://breeze.github.io/problems/entity-errors";
95
+ /** An unhandled exception on the server. */
96
+ readonly serverError: "https://breeze.github.io/problems/server-error";
97
+ };
98
+ /** Whether an error is an optimistic concurrency conflict - a row changed or deleted by someone
99
+ else after this client read it.
100
+
101
+ ```ts
102
+ try {
103
+ await em.saveChanges();
104
+ } catch (e) {
105
+ if (isConcurrencyError(e)) {
106
+ // re-read and let the user decide; retrying the same save would fail the same way
107
+ }
108
+ }
109
+ ```
110
+
111
+ This is exact rather than approximate: it is true only when the server said so with
112
+ {@link ProblemTypes.concurrencyConflict}, never inferred from the status code or the message. A
113
+ `409` from a duplicate key is not a concurrency conflict, and matching on message text breaks
114
+ when the ORM, database or server version changes.
115
+
116
+ A Breeze .NET server sends this for EF Core's `DbUpdateConcurrencyException` and NHibernate's
117
+ `StaleObjectStateException`. A server that does not send a `type` - any pre-3.0 Breeze server, and
118
+ most non-Breeze ones - returns false here, and there is nothing reliable to use instead.
119
+
120
+ When the conflict names the rows involved, they are on `entityErrors` with the entities attached:
121
+
122
+ ```ts
123
+ const stale = (e.entityErrors ?? [])
124
+ .filter(ee => ee.errorName === "ConcurrencyError")
125
+ .map(ee => ee.entity);
126
+ ```
127
+ @param error The rejection value from a Breeze call - typically a {@link SaveError}.
128
+ @returns true if the server identified this as a concurrency conflict. */
129
+ export declare function isConcurrencyError(error: any): boolean;
130
+ /** Shape of a save error when returned to the client. */
131
+ export interface SaveError extends ServerError {
132
+ /** The errors the server reported on particular entities. Undefined when it named none - after a
133
+ network failure or a server exception, say - which is how to tell a rejected save from those.
134
+ Breeze also adds each one to its entity's validation errors.
135
+
136
+ When client-side validation stops a save before it is sent, the rejection is a plain `Error` with
137
+ `entityErrors` built from the entities' validation errors, and no HTTP members. */
138
+ entityErrors?: EntityError[];
139
+ }
140
+ /** Shape of an error on a specific entity. Part of a {@link SaveError} */
141
+ export interface EntityError {
142
+ /** The entity the error is about. `null` when the server named an entity that is not in this
143
+ manager's cache. */
144
+ entity: Entity | null;
145
+ /** What kind of error this is. From the server, the name it gave the error, such as
146
+ `"ConcurrencyError"`; from client-side validation, the validator's name, or the error's key if it
147
+ was added without a validator. */
148
+ errorName: string;
149
+ /** The error message. */
150
+ errorMessage: string;
151
+ /** The client-side name of the property the error is about; empty or null when it is about the
152
+ whole entity. */
153
+ propertyName: string;
154
+ /** `true` for an error the server reported, `false` for one from client-side validation. */
155
+ isServerError: boolean;
156
+ /** Whatever extra information the server attached to the error. Undefined for client-side
157
+ errors. */
158
+ custom?: any;
159
+ }
160
+ /**
161
+ * Anything the type-taking APIs accept in place of an {@link EntityType}: the type itself, its
162
+ * name, or a constructor registered for it with {@link MetadataStore.registerEntityTypeCtor}.
163
+ */
164
+ export type EntityTypeArg = EntityType | string | (new () => Entity);
165
+ /** What {@link EntityManager.exportEntities} exports: particular entities, or every entity of the
166
+ given types - as registered classes, {@link EntityType}s or type names. */
167
+ export type ExportEntitiesArg = Entity[] | (new () => Entity)[] | EntityType[] | string[];
168
+ /**
169
+ The values {@link EntityManager.createEntity} can be given for an entity of class `T`: any of its
170
+ data and navigation properties, each optional.
171
+
172
+ - A collection navigation property takes a plain array of entities, and a complex property a plain
173
+ object of its own values - both are what `createEntity` accepts at runtime.
174
+ - The members every entity has - `entityAspect`, `entityType`, `getProperty`, `setProperty` - are
175
+ not initial values, and passing one fails inside Breeze. Methods are left out too.
176
+
177
+ A property the class does not declare is a compile error, which is the point: at runtime
178
+ `createEntity` ignores it without a word, so a misspelt or server-cased name (`ShipName` for
179
+ `shipName`) would otherwise create the entity without it.
180
+
181
+ Only the constructor overload is checked. Pass the type's name or its `EntityType` to create one
182
+ from values the compiler cannot see.
183
+ */
184
+ export type InitialValues<T> = {
185
+ [K in keyof T as K extends keyof Entity | keyof ComplexObject ? never : T[K] extends Function ? never : K]?: T[K] extends RelationArray<infer U> ? U[] | T[K] : T[K] extends ReadonlyArray<infer U> ? (U extends ComplexObject ? InitialValues<U> | U : U)[] | T[K] : T[K] extends ComplexObject ? InitialValues<T[K]> | T[K] : T[K];
186
+ };
187
+ /** What an {@link EntityManager.executeQuery} call resolves with - as do `EntityQuery.execute` and
188
+ `RelationArray.load`. `T` is what the query was built for: `EntityQuery.from(Customer)` gives a
189
+ `QueryResult<Customer>`, whose `results` is `Customer[]`. It defaults to `any`. */
190
+ export interface QueryResult<T = any> {
191
+ /** Top level entities returned. Excludes entities that are Deleted. */
192
+ results: T[];
193
+ /** Query that was executed */
194
+ query: EntityQuery | string;
195
+ /** EntityManager that executed the query */
196
+ entityManager?: EntityManager;
197
+ /** Total number of results available on the server */
198
+ inlineCount?: number;
199
+ /** All entities returned by the query. Differs from `results` when an expand is used. Includes entities that are Deleted. */
200
+ retrievedEntities?: Entity[];
201
+ /** Raw response from the server */
202
+ httpResponse?: HttpResponse;
203
+ }
204
+ /** The success callback accepted by the deprecated callback form of {@link EntityManager.executeQuery}.
205
+ @deprecated Await the returned promise instead of passing callbacks. */
206
+ export interface QuerySuccessCallback {
207
+ (data: QueryResult): void;
208
+ }
209
+ /** The failure callback accepted by the deprecated callback form of {@link EntityManager.executeQuery}.
210
+ @deprecated Await the returned promise instead of passing callbacks. */
211
+ export interface QueryErrorCallback {
212
+ (error: {
213
+ query: EntityQuery;
214
+ httpResponse: HttpResponse;
215
+ entityManager: EntityManager;
216
+ message?: string;
217
+ stack?: string;
218
+ }): void;
219
+ }
220
+ /** Key mapping information returned as part of an {@link SaveResult}. */
221
+ export interface KeyMapping {
222
+ /** The qualified name of the entity's type, such as `"Order:#Northwind.Models"`. */
223
+ entityTypeName: string;
224
+ /** The temporary key value the entity had on the client. */
225
+ tempValue: any;
226
+ /** The permanent key value the server assigned. */
227
+ realValue: any;
228
+ }
229
+ /** Maps each temporary key in a bundle imported by {@link EntityManager.importEntities} to the
230
+ temporary key its entity was given in the importing manager. Returned as
231
+ {@link ImportResult.tempKeyMapping}.
232
+
233
+ Each property name is an old key in its {@link EntityKey.toString} form - the entity type's
234
+ qualified name, a hyphen and the key value, such as `"Order:#Northwind.Models--1"` for the key
235
+ `-1` - and its value is the new {@link EntityKey}. Both are temporary: the entity is still unsaved,
236
+ and gets its permanent key when it is saved. The new key keeps the old value unless this manager's
237
+ {@link KeyGenerator} has already handed that value out.
238
+
239
+ With {@link ImportConfig.mergeAdds} set, imported entities keep their old keys and this map does not
240
+ describe them. */
241
+ export interface ITempKeyMap {
242
+ [index: string]: EntityKey;
243
+ }
244
+ /** Configuration info to be passed to the {@link EntityManager.importEntities} method */
245
+ export interface ImportConfig {
246
+ /** If true, merge Added entities (with temp keys) as well. This can be dangerous. */
247
+ mergeAdds?: boolean;
248
+ /** How to merge an imported entity into one with the same key already in this manager. Defaults
249
+ to the manager's `queryOptions.mergeStrategy`. With {@link MergeStrategy.Disallowed} the import
250
+ throws on such an entity. Added entities with temporary keys are never merged unless `mergeAdds`
251
+ is set. */
252
+ mergeStrategy?: MergeStrategy;
253
+ /** Called before anything is imported when the bundle was exported without metadata, with the
254
+ `MetadataStore.metadataVersion` of the Breeze that exported it and the name of the exporting
255
+ manager's `MetadataStore`. Throw from it to stop the import if the bundle does not match this
256
+ manager's metadata. Not called when the bundle includes metadata. */
257
+ metadataVersionFn?: (arg: {
258
+ metadataVersion: any;
259
+ metadataStoreName: any;
260
+ }) => void;
261
+ }
262
+ /** The shape of the Promise returned by an {@link EntityManager.saveChanges} call. */
263
+ export interface SaveResult {
264
+ /** The entities the server returned for the save, as merged into this manager's cache. Empty
265
+ when there was nothing to save. */
266
+ entities: Entity[];
267
+ /** For each entity saved with a temporary key, the permanent key the server assigned. Breeze has
268
+ already applied them - to the entities and to the foreign keys that pointed at them - by the time
269
+ the save resolves. */
270
+ keyMappings: KeyMapping[];
271
+ /** The entities the server reports it deleted during the save, by type name and key values. This
272
+ can include entities the client did not send, such as ones deleted by server-side logic. Breeze
273
+ detaches any of them that are in the cache. */
274
+ deletedKeys?: {
275
+ /** The name of the deleted entity's type, as the server sent it. */
276
+ entityTypeName: string;
277
+ /** The deleted entity's key values, one per key property. */
278
+ keyValues: any[];
279
+ }[];
280
+ /** The raw response to the save request. Undefined when there was nothing to save, and so no
281
+ request. */
282
+ httpResponse?: HttpResponse;
283
+ }
284
+ /** For use by breeze plugin authors only. The class is for use in building a {@link DataServiceAdapter} implementation.
285
+ @adapter (see {@link DataServiceAdapter})
286
+ @hidden
287
+ */
288
+ export interface SaveContext {
289
+ entityManager: EntityManager;
290
+ dataService: DataService;
291
+ processSavedEntities: (saveResult: SaveResult) => Entity[];
292
+ resourceName: string;
293
+ adapter?: DataServiceAdapter;
294
+ routePrefix?: string;
295
+ }
296
+ /** For use by breeze plugin authors only. The class is for use in building a {@link DataServiceAdapter} implementation.
297
+ @adapter (see {@link DataServiceAdapter})
298
+ @hidden
299
+ */
300
+ export interface SaveBundle {
301
+ entities: Entity[];
302
+ saveOptions: SaveOptions;
303
+ }
304
+ /** Configuration info to be passed to the {@link EntityManager} constructor */
305
+ export interface EntityManagerConfig {
306
+ /** The service name associated with this EntityManager. */
307
+ serviceName?: string;
308
+ /** The DataService associated with this EntityManager. */
309
+ dataService?: DataService;
310
+ /** The {@link QueryOptions} associated with this EntityManager. */
311
+ queryOptions?: QueryOptions;
312
+ /** The {@link SaveOptions} associated with this EntityManager. */
313
+ saveOptions?: SaveOptions;
314
+ /** The {@link ValidationOptions} associated with this EntityManager. */
315
+ validationOptions?: ValidationOptions;
316
+ /** The {@link KeyGenerator} constructor associated with this EntityManager. The manager creates its own
317
+ instance, and a new one whenever it is cleared, so a generator cannot be passed in as an instance. */
318
+ keyGeneratorCtor?: {
319
+ new (): KeyGenerator;
320
+ };
321
+ /** The {@link MetadataStore} associated with this EntityManager. */
322
+ metadataStore?: MetadataStore;
323
+ }
324
+ /** The shape returned by callbacks registered with {@link EntityManager.entityChanged} event */
325
+ export interface EntityChangedEventArgs {
326
+ /** What happened - see {@link EntityAction}. */
327
+ entityAction: EntityAction;
328
+ /** The entity the action happened to. Undefined for {@link EntityAction.Clear}, which affects every
329
+ entity in the manager. */
330
+ entity?: Entity;
331
+ /** Set only for {@link EntityAction.PropertyChange}: the same {@link PropertyChangedEventArgs} the
332
+ entity's `propertyChanged` event receives. Undefined for every other action. */
333
+ args?: PropertyChangedEventArgs;
334
+ }
335
+ /** The argument to the `validationErrorsChanged` event of an {@link EntityManager} and of an
336
+ {@link EntityAspect}. Raised once per operation - a validation, or a call that adds, removes or
337
+ clears errors - that added or removed at least one error. */
338
+ export interface ValidationErrorsChangedEventArgs {
339
+ /** The entity whose validation errors changed. */
340
+ entity: Entity;
341
+ /** The errors the operation added. An error found again when the entity is re-validated appears
342
+ here again, replacing the one with the same key. */
343
+ added: ValidationError[];
344
+ /** The errors the operation removed: ones that no longer fail validation, and ones removed with
345
+ {@link EntityAspect.removeValidationError} or {@link EntityAspect.clearValidationErrors}. */
346
+ removed: ValidationError[];
347
+ }
348
+ /** The argument to the {@link EntityManager.hasChangesChanged} event. */
349
+ export interface HasChangesChangedEventArgs {
350
+ /** The manager whose `hasChanges` state changed. */
351
+ entityManager: EntityManager;
352
+ /** Whether the manager now has changes - see {@link EntityManager.hasChanges}. */
353
+ hasChanges: boolean;
354
+ }
355
+ /**
356
+ Instances of the EntityManager contain and manage collections of entities, either retrieved from a backend datastore or created on the client.
357
+ */
358
+ export declare class EntityManager {
359
+ /** The service name associated with this EntityManager. __Read Only__ */
360
+ serviceName: string;
361
+ /** The DataService associated with this EntityManager. __Read Only__ */
362
+ dataService: DataService;
363
+ /** The {@link QueryOptions} associated with this EntityManager. __Read Only__ */
364
+ queryOptions: QueryOptions;
365
+ /** The {@link SaveOptions} associated with this EntityManager. __Read Only__ */
366
+ saveOptions: SaveOptions;
367
+ /** The {@link ValidationOptions} associated with this EntityManager. __Read Only__ */
368
+ validationOptions: ValidationOptions;
369
+ /** The {@link KeyGenerator} associated with this EntityManager. __Read Only__ */
370
+ keyGenerator: KeyGenerator;
371
+ /** The {@link KeyGenerator} constructor associated with this EntityManager. __Read Only__ */
372
+ keyGeneratorCtor: {
373
+ new (): KeyGenerator;
374
+ };
375
+ /** The {@link MetadataStore} associated with this EntityManager. __Read Only__ */
376
+ metadataStore: MetadataStore;
377
+ /** True while Breeze is loading entities into this manager - merging query or save results, or
378
+ attaching or creating entities. While it is set, property changes do not mark entities Modified,
379
+ are not validated, and raise no property-change events. Used by Breeze; applications do not
380
+ normally need it. */
381
+ isLoading: boolean;
382
+ /** True while {@link EntityAspect.rejectChanges} restores an entity's original values, so that
383
+ restoring them raises no property-change events. Used by Breeze; applications do not normally need
384
+ it. */
385
+ isRejectingChanges: boolean;
386
+ /**
387
+ A {@link BreezeEvent} that fires whenever a change to any entity in this EntityManager occurs. __Read Only__
388
+
389
+ @eventArgs -
390
+ - entityAction - The {@link EntityAction} that occured.
391
+ - entity - The entity that changed. Undefined for {@link EntityAction.Clear}, which affects every entity in the manager.
392
+ - args - Additional information about this event. This will differ based on the entityAction.
393
+
394
+ ```ts
395
+ const em = new EntityManager({ serviceName: "breeze/NorthwindIBModel" });
396
+ em.entityChanged.subscribe(changeArgs => {
397
+ // This code will be executed any time any entity within the entityManager
398
+ // is added, modified, deleted or detached for any reason.
399
+ const action = changeArgs.entityAction;
400
+ const entity = changeArgs.entity;
401
+ // .. do something to this entity when it is changed.
402
+ });
403
+ ```
404
+ @event
405
+ */
406
+ entityChanged: BreezeEvent<EntityChangedEventArgs>;
407
+ /**
408
+ An {@link BreezeEvent} that fires whenever validationErrors change for any entity in this EntityManager. __Read Only__
409
+ @eventArgs -
410
+ - entity - The entity on which the validation errors have been added or removed.
411
+ - added - An array containing any newly added {@link ValidationError}s
412
+ - removed - An array containing any newly removed {@link ValidationError}s. This is those errors that have been 'fixed'
413
+
414
+ ```ts
415
+ const em = new EntityManager({ serviceName: "breeze/NorthwindIBModel" });
416
+ em.validationErrorsChanged.subscribe(changeArgs => {
417
+ // This code will be executed any time any entity within the entityManager
418
+ // experiences a change to its validationErrors collection.
419
+ const entity = changeArgs.entity;
420
+ const errorsAdded = changeArgs.added;
421
+ const errorsCleared = changeArgs.removed;
422
+ // ... do something interesting with the entity.
423
+ });
424
+ ```
425
+ @event
426
+ */
427
+ validationErrorsChanged: BreezeEvent<ValidationErrorsChangedEventArgs>;
428
+ /**
429
+ A {@link BreezeEvent} that fires whenever an EntityManager transitions to or from having changes. __Read Only__
430
+ @eventArgs -
431
+ - entityManager - The EntityManager whose 'hasChanges' status has changed.
432
+ - hasChanges - Whether or not this EntityManager has changes.
433
+
434
+ ```ts
435
+ const em = new EntityManager({ serviceName: "breeze/NorthwindIBModel" });
436
+ em.hasChangesChanged.subscribe(args => {
437
+ const hasChanges = args.hasChanges;
438
+ const entityManager = args.entityManager;
439
+ });
440
+ ```
441
+ @event
442
+ */
443
+ hasChangesChanged: BreezeEvent<HasChangesChangedEventArgs>;
444
+ /** Functions a {@link DataServiceAdapter} uses to build the save request: `unwrapInstance` turns an
445
+ entity or complex object into a plain object with server property names, `unwrapOriginalValues`
446
+ does the same for its original values, and `unwrapChangedValues` for the current values of its
447
+ changed properties. For adapter authors; applications do not normally need it. */
448
+ helper: {
449
+ /** Turns an entity or complex object into a plain object keyed by server property names. */
450
+ unwrapInstance: typeof unwrapInstance;
451
+ /** The same, for the original values of an entity's changed properties. */
452
+ unwrapOriginalValues: typeof unwrapOriginalValues;
453
+ /** The same, for the current values of an entity's changed properties. */
454
+ unwrapChangedValues: typeof unwrapChangedValues;
455
+ };
456
+ /**
457
+ EntityManager constructor.
458
+
459
+ At its most basic an EntityManager can be constructed with just a service name
460
+ ```ts
461
+ const entityManager = new EntityManager("breeze/NorthwindIBModel");
462
+ ```
463
+
464
+ This is the same as calling it with the following configuration object
465
+ ```ts
466
+ const entityManager = new EntityManager({ serviceName: "breeze/NorthwindIBModel" });
467
+ ```
468
+
469
+ Usually however, configuration objects will contain more than just the 'serviceName';
470
+ ```ts
471
+ const metadataStore = new MetadataStore();
472
+ const entityManager = new EntityManager({
473
+ serviceName: "breeze/NorthwindIBModel",
474
+ metadataStore: metadataStore
475
+ });
476
+ ```
477
+
478
+ or
479
+ ```ts
480
+ const queryOptions = new QueryOptions({
481
+ mergeStrategy: MergeStrategy.OverwriteChanges,
482
+ fetchStrategy: FetchStrategy.FromServer
483
+ });
484
+ const validationOptions = new ValidationOptions({
485
+ validateOnAttach: true,
486
+ validateOnSave: true,
487
+ validateOnQuery: false
488
+ });
489
+ const entityManager = new EntityManager({
490
+ serviceName: "breeze/NorthwindIBModel",
491
+ queryOptions: queryOptions,
492
+ validationOptions: validationOptions
493
+ });
494
+ ```
495
+ @param emConfig - Configuration settings or a service name.
496
+ */
497
+ constructor(emConfig?: EntityManagerConfig | string);
498
+ /**
499
+ General purpose property set method. Any of the properties in the {@link EntityManagerConfig}
500
+ may be set.
501
+ ```ts
502
+ // assume em1 is a previously created EntityManager
503
+ // where we want to change some of its settings.
504
+ em1.setProperties( {
505
+ serviceName: "breeze/foo"
506
+ });
507
+ ```
508
+ @param config - An object containing the selected properties and values to set.
509
+ */
510
+ setProperties(config: EntityManagerConfig): void;
511
+ createEntity<T extends Entity>(entityCtor: new () => T, initialValues?: InitialValues<T>, entityState?: EntityState, mergeStrategy?: MergeStrategy): T;
512
+ createEntity(typeName: string, initialValues?: Object, entityState?: EntityState, mergeStrategy?: MergeStrategy): Entity;
513
+ createEntity(entityType: EntityType, initialValues?: Object, entityState?: EntityState, mergeStrategy?: MergeStrategy): Entity;
514
+ static importEntities(exportedString: string, config?: ImportConfig): EntityManager;
515
+ static importEntities(exportedData: Object, config?: ImportConfig): EntityManager;
516
+ /**
517
+ Calls {@link EntityAspect.acceptChanges} on every changed entity in this EntityManager.
518
+ */
519
+ acceptChanges(): void;
520
+ exportEntities(entities?: ExportEntitiesArg, exportConfig?: {
521
+ asString?: true;
522
+ includeMetadata?: boolean;
523
+ } | boolean): string;
524
+ exportEntities(entities: ExportEntitiesArg | undefined, exportConfig: {
525
+ asString: false;
526
+ includeMetadata?: boolean;
527
+ }): Object;
528
+ exportEntities(entities?: ExportEntitiesArg, exportConfig?: {
529
+ asString?: boolean;
530
+ includeMetadata?: boolean;
531
+ } | boolean): string | Object;
532
+ importEntities(exportedString: string, config?: ImportConfig): ImportResult;
533
+ importEntities(exportedData: Object, config?: ImportConfig): ImportResult;
534
+ /**
535
+ Clears this EntityManager's cache but keeps all other settings. Note that this
536
+ method is not as fast as creating a new EntityManager via 'new EntityManager'.
537
+ This is because clear actually detaches all of the entities from the EntityManager.
538
+ ```ts
539
+ // assume em1 is an EntityManager containing a number of existing entities.
540
+ em1.clear();
541
+ // em1 is will now contain no entities, but all other setting will be maintained.
542
+ ```
543
+ */
544
+ clear(): void;
545
+ /**
546
+ Creates an empty copy of this EntityManager but with the same DataService, MetadataStore, QueryOptions, SaveOptions, ValidationOptions, etc.
547
+ ```ts
548
+ // assume em1 is an EntityManager containing a number of existing entities.
549
+ const em2 = em1.createEmptyCopy();
550
+ // em2 is a new EntityManager with all of em1's settings
551
+ // but no entities.
552
+ ```
553
+ @returns A new EntityManager.
554
+ */
555
+ createEmptyCopy(): EntityManager;
556
+ /**
557
+ Attaches an entity to this EntityManager with an {@link EntityState} of 'Added'.
558
+ ```ts
559
+ // assume em1 is an EntityManager containing a number of existing entities.
560
+ const cust1 = em1.createEntity(Customer, { companyName: "Acme" }, EntityState.Detached);
561
+ em1.addEntity(cust1); // returns cust1, a Customer
562
+ ```
563
+
564
+ Note that this is the same as using 'attachEntity' with an {@link EntityState} of 'Added'.
565
+
566
+ ```ts
567
+ // assume em1 is an EntityManager containing a number of existing entities.
568
+ const cust1 = em1.createEntity(Customer, { companyName: "Acme" }, EntityState.Detached);
569
+ em1.attachEntity(cust1, EntityState.Added);
570
+ ```
571
+ @param entity - The entity to add.
572
+ @returns The added entity.
573
+ */
574
+ addEntity<T extends Entity>(entity: T): T;
575
+ /**
576
+ Attaches an entity to this EntityManager with a specified {@link EntityState}.
577
+ ```ts
578
+ // assume em1 is an EntityManager containing a number of existing entities.
579
+ const cust1 = em1.createEntity(Customer, { companyName: "Acme" }, EntityState.Detached);
580
+ em1.attachEntity(cust1, EntityState.Added); // returns cust1, a Customer
581
+ ```
582
+ @param entity - The entity to add.
583
+ @param entityState - (default=EntityState.Unchanged) The EntityState of the newly attached entity. If omitted this defaults to EntityState.Unchanged.
584
+ @param mergeStrategy - (default = MergeStrategy.Disallowed) How the specified entity should be merged into the EntityManager if this EntityManager already contains an entity with the same key.
585
+ @returns The attached entity.
586
+ */
587
+ attachEntity<T extends Entity>(entity: T, entityState?: EntityState, mergeStrategy?: MergeStrategy): T;
588
+ /**
589
+ Detaches an entity from this EntityManager.
590
+ ```ts
591
+ // assume em1 is an EntityManager containing a number of existing entities.
592
+ // assume cust1 is a customer Entity previously attached to em1
593
+ em1.detachEntity(cust1);
594
+ // em1 will now no longer contain cust1 and cust1 will have an
595
+ // entityAspect.entityState of EntityState.Detached
596
+ ```
597
+ @param entity - The entity to detach.
598
+ @returns Whether the entity could be detached. This will return false if the entity is already detached or was never attached.
599
+ */
600
+ detachEntity(entity: Entity): any;
601
+ fetchMetadata(dataService?: DataService): Promise<any>;
602
+ /** @deprecated Await the returned promise instead of passing callbacks. */
603
+ fetchMetadata(dataService: DataService | undefined, callback?: Callback, errorCallback?: ErrorCallback): Promise<any>;
604
+ executeQuery<T>(query: EntityQuery<T>): Promise<QueryResult<T>>;
605
+ executeQuery(query: string): Promise<QueryResult>;
606
+ /** @deprecated Await the returned promise instead of passing callbacks. */
607
+ executeQuery<T>(query: EntityQuery<T>, callback?: QuerySuccessCallback, errorCallback?: QueryErrorCallback): Promise<QueryResult<T>>;
608
+ /** @deprecated Await the returned promise instead of passing callbacks. */
609
+ executeQuery(query: string, callback?: QuerySuccessCallback, errorCallback?: QueryErrorCallback): Promise<QueryResult>;
610
+ /**
611
+ Executes the specified query against this EntityManager's local cache.
612
+
613
+ Because this method is executed immediately there is no need for a promise or a callback
614
+ ```ts
615
+ const em = new EntityManager(serviceName);
616
+ const query = EntityQuery.from(Order);
617
+ const orders = em.executeQueryLocally(query); // Order[]
618
+ ```
619
+
620
+ Note that this can also be accomplished using the 'executeQuery' method with
621
+ a FetchStrategy of FromLocalCache and making use of the Promise or callback
622
+ ```ts
623
+ const em = new EntityManager(serviceName);
624
+ const query = EntityQuery.from(Order).using(FetchStrategy.FromLocalCache);
625
+ const data = await em.executeQuery(query);
626
+ const orders = data.results; // Order[]
627
+ ```
628
+ @param query - The {@link EntityQuery} to execute.
629
+ @returns {Array of Entity} Array of entities from cache that satisfy the query
630
+ */
631
+ executeQueryLocally<T>(query: EntityQuery<T>): T[];
632
+ saveChanges(entities?: Entity[] | null, saveOptions?: SaveOptions): Promise<SaveResult>;
633
+ /** @deprecated Await the returned promise instead of passing callbacks. */
634
+ saveChanges(entities: Entity[] | null | undefined, saveOptions: SaveOptions | undefined, callback?: Function, errorCallback?: Function): Promise<SaveResult>;
635
+ /**
636
+ Run the "saveChanges" pre-save client validation logic.
637
+
638
+ This is NOT a general purpose validation method.
639
+ It is intended for utilities that must know if saveChanges
640
+ would reject the save due to client validation errors.
641
+
642
+ It only validates entities if the EntityManager's
643
+ {@link ValidationOptions}.validateOnSave is true.
644
+
645
+ @param entitiesToSave {Array of Entity} The list of entities to save (to validate).
646
+ @returns {Error} Validation error or null if no error
647
+ */
648
+ saveChangesValidateOnClient(entitiesToSave: Entity[]): Error | null;
649
+ /**
650
+ The check {@link EntityManager.saveChangesValidateOnClient} makes, with async validators run too:
651
+ each entity is validated with {@link EntityAspect.validateEntityAsync}. `saveChanges` uses this
652
+ in its place when any of the entities it saves has an async validator.
653
+ @param entitiesToSave - The entities to validate.
654
+ @returns A promise of the error `saveChanges` would reject with, or null.
655
+ */
656
+ saveChangesValidateOnClientAsync(entitiesToSave: Entity[]): Promise<Error | null>;
657
+ /**
658
+ Returns the entity in this manager's cache with this key, or `null` if there is none. It does
659
+ not query the server; see {@link EntityManager.fetchEntityByKey} for that. Given the constructor of a class registered with the
660
+ {@link MetadataStore}, the result has that class's type.
661
+ ```ts
662
+ // assume em1 is an EntityManager containing a number of preexisting entities,
663
+ // and that Employee is registered with its MetadataStore.
664
+ const employee = em1.getEntityByKey(Employee, 1); // Employee | null
665
+ ```
666
+ A key of more than one property is clearest given by name - see {@link KeyValues}:
667
+ ```ts
668
+ const detail = em1.getEntityByKey(OrderDetail, { orderID: 10248, productID: 11 });
669
+ ```
670
+ */
671
+ getEntityByKey<T extends Entity>(entityCtor: new () => T, keyValues: KeyValues<T> | KeyValue | any[]): T | null;
672
+ /**
673
+ Returns the entity in this manager's cache with this key, or `null` if there is none. It does
674
+ not query the server; see {@link EntityManager.fetchEntityByKey} for that.
675
+ ```ts
676
+ // assume em1 is an EntityManager containing a number of preexisting entities.
677
+ const employeeType = em1.metadataStore.getAsEntityType("Employee");
678
+ const employeeKey = new EntityKey(employeeType, 1);
679
+ const employee = em1.getEntityByKey(employeeKey);
680
+ // employee will either be an entity or null.
681
+ ```
682
+ */
683
+ getEntityByKey(entityKey: EntityKey): Entity | null;
684
+ /**
685
+ Returns the entity in this manager's cache with this key, or `null` if there is none. It does
686
+ not query the server; see {@link EntityManager.fetchEntityByKey} for that.
687
+ ```ts
688
+ // assume em1 is an EntityManager containing a number of preexisting entities.
689
+ const employee = em1.getEntityByKey("Employee", 1);
690
+ // employee will either be an entity or null.
691
+ ```
692
+ */
693
+ getEntityByKey(typeName: string, keyValues: any | any[]): Entity | null;
694
+ /**
695
+ Returns the entity in this manager's cache with this key, or `null` if there is none. It does
696
+ not query the server; see {@link EntityManager.fetchEntityByKey} for that.
697
+ ```ts
698
+ // assume em1 is an EntityManager containing a number of preexisting entities.
699
+ const employeeType = em1.metadataStore.getAsEntityType("Employee");
700
+ const employee = em1.getEntityByKey(employeeType, 1);
701
+ // employee will either be an entity or null.
702
+ ```
703
+ */
704
+ getEntityByKey(type: EntityType, keyValues: any | any[]): Entity | null;
705
+ fetchEntityByKey<T extends Entity>(entityCtor: new () => T, keyValues: KeyValues<T> | KeyValue | any[], checkLocalCacheFirst?: boolean): Promise<EntityByKeyResult<T>>;
706
+ fetchEntityByKey(typeName: string, keyValues: any | any[], checkLocalCacheFirst?: boolean): Promise<IEntityByKeyResult>;
707
+ fetchEntityByKey(entityType: EntityType, keyValues: any | any[], checkLocalCacheFirst?: boolean): Promise<IEntityByKeyResult>;
708
+ fetchEntityByKey(entityKey: EntityKey, checkLocalCacheFirst?: boolean): Promise<IEntityByKeyResult>;
709
+ /**
710
+ [Deprecated] - Attempts to locate an entity within this EntityManager by its {@link EntityKey}.
711
+ ```ts
712
+ // assume em1 is an EntityManager containing a number of preexisting entities.
713
+ const employeeType = em1.metadataStore.getAsEntityType("Employee");
714
+ const employeeKey = new EntityKey(employeeType, 1);
715
+ const employee = em1.findEntityByKey(employeeKey);
716
+ // employee will either be an entity or null.
717
+ ```
718
+ @deprecated Use getEntityByKey instead
719
+ @param entityKey - The {@link EntityKey} of the Entity to be located.
720
+ @returns An Entity or null;
721
+ */
722
+ findEntityByKey(entityKey: EntityKey): Entity | null;
723
+ /**
724
+ Generates a temporary key for the specified entity. This is used to insure that newly
725
+ created entities have unique keys and to register that these keys are temporary and
726
+ need to be automatically replaced with 'real' key values once these entities are saved.
727
+
728
+ The {@link EntityManager.keyGeneratorCtor} property is used internally by this method to actually generate
729
+ the keys - See the KeyGenerator interface interface description to see
730
+ how a custom key generator can be plugged in.
731
+ ```ts
732
+ // assume em1 is an EntityManager containing a number of preexisting entities.
733
+ const customer = em1.createEntity(Customer, { companyName: "Acme" }, EntityState.Detached);
734
+ const customerId = em1.generateTempKeyValue(customer);
735
+ // customer.customerID is now set to a newly generated unique id value.
736
+ // This property will change again after a successful save of the customer.
737
+ em1.addEntity(customer);
738
+ await em1.saveChanges();
739
+ // customer.customerID !== customerId, because the server will have generated
740
+ // a new id and the client will have been updated with this new id.
741
+ ```
742
+ @param entity - The Entity to generate a key for.
743
+ @returns The new key value
744
+ */
745
+ generateTempKeyValue(entity: Entity): any;
746
+ hasChanges<T extends Entity>(entityCtor: new () => T): boolean;
747
+ hasChanges(entityCtors: (new () => Entity)[]): boolean;
748
+ hasChanges(): boolean;
749
+ hasChanges(entityTypeNames: string | string[]): boolean;
750
+ hasChanges(entityTypes: EntityType | EntityType[]): boolean;
751
+ getChanges<T extends Entity>(entityCtor: new () => T): T[];
752
+ /** Several types at once: `getChanges([Customer, Order])` is `(Customer | Order)[]`. */
753
+ getChanges<C extends (new () => Entity)[]>(entityCtors: [...C]): InstanceType<C[number]>[];
754
+ getChanges(): Entity[];
755
+ getChanges(entityTypeNames: string | string[]): Entity[];
756
+ getChanges(entityTypes: EntityType | EntityType[]): Entity[];
757
+ /**
758
+ Rejects (reverses the effects) all of the additions, modifications and deletes from this EntityManager.
759
+ Calls {@link EntityAspect.rejectChanges} on every changed entity in this EntityManager.
760
+ ```ts
761
+ // assume em1 is an EntityManager containing a number of preexisting entities.
762
+ const entities = em1.rejectChanges();
763
+ ```
764
+ @returns The entities whose changes were rejected. These entities will all have EntityStates of
765
+ either 'Unchanged' or 'Detached'
766
+ */
767
+ rejectChanges(): Entity[];
768
+ getEntities<T extends Entity>(entityCtor: new () => T, entityStates?: EntityState | EntityState[]): T[];
769
+ /** Several types at once: `getEntities([Customer, Order])` is `(Customer | Order)[]`. */
770
+ getEntities<C extends (new () => Entity)[]>(entityCtors: [...C], entityStates?: EntityState | EntityState[]): InstanceType<C[number]>[];
771
+ getEntities(entityTypeNames?: string | string[], entityStates?: EntityState | EntityState[]): Entity[];
772
+ getEntities(entityTypes?: EntityType | EntityType[], entityStates?: EntityState | EntityState[]): Entity[];
773
+ }
774
+ /** What an {@link EntityManager.fetchEntityByKey} call resolves with. */
775
+ export interface IEntityByKeyResult {
776
+ /** The entity, or `null` if there is none.
777
+
778
+ `null` rather than `undefined`, because that is what absence means everywhere else in Breeze:
779
+ a scalar navigation property with nothing cached is `null`, a nullable data property is `null`,
780
+ and {@link EntityManager.getEntityByKey} returns `null`. Before 3.0 this one property was the
781
+ exception. See UPGRADE.md. */
782
+ entity: Entity | null;
783
+ /** The key that was looked up. */
784
+ entityKey: EntityKey;
785
+ /** True if the answer came from the local cache, which is only checked when `checkLocalCacheFirst`
786
+ is true; false if the server was queried. It can be true with a null `entity`: the cached entity is
787
+ Deleted, and the manager's `queryOptions` exclude deleted entities and do not use
788
+ {@link MergeStrategy.OverwriteChanges}. */
789
+ fromCache: boolean;
790
+ }
791
+ /** {@link IEntityByKeyResult} for a known entity type - what the constructor overload of
792
+ {@link EntityManager.fetchEntityByKey} returns. */
793
+ export interface EntityByKeyResult<T extends Entity> extends IEntityByKeyResult {
794
+ entity: T | null;
795
+ }
796
+ /** A single key value: what a one-property key's value can be. */
797
+ type KeyValue = string | number | boolean | Date;
798
+ declare function unwrapInstance(structObj: StructuralObject, transformFn?: (dp: DataProperty, val: any) => any): any;
799
+ declare function unwrapOriginalValues(target: StructuralObject, metadataStore: MetadataStore, transformFn?: (dp: DataProperty, val: any) => any): Record<string, any>;
800
+ declare function unwrapChangedValues(entity: Entity, metadataStore: MetadataStore, transformFn: (dp: DataProperty, val: any) => any): Record<string, any>;
801
+ export {};