@itwin/core-backend 5.9.0-dev.9 → 5.9.1

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 (286) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/lib/cjs/BriefcaseManager.d.ts +14 -62
  3. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  4. package/lib/cjs/BriefcaseManager.js +29 -159
  5. package/lib/cjs/BriefcaseManager.js.map +1 -1
  6. package/lib/cjs/Category.d.ts +4 -4
  7. package/lib/cjs/Category.js.map +1 -1
  8. package/lib/cjs/ChangesetECAdaptor.d.ts +9 -1
  9. package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
  10. package/lib/cjs/ChangesetECAdaptor.js +7 -1
  11. package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
  12. package/lib/cjs/ChangesetReader.d.ts +186 -0
  13. package/lib/cjs/ChangesetReader.d.ts.map +1 -0
  14. package/lib/cjs/ChangesetReader.js +372 -0
  15. package/lib/cjs/ChangesetReader.js.map +1 -0
  16. package/lib/cjs/ChangesetReaderTypes.d.ts +120 -0
  17. package/lib/cjs/ChangesetReaderTypes.d.ts.map +1 -0
  18. package/lib/cjs/ChangesetReaderTypes.js +23 -0
  19. package/lib/cjs/ChangesetReaderTypes.js.map +1 -0
  20. package/lib/cjs/CloudSqlite.d.ts +1 -1
  21. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  22. package/lib/cjs/CloudSqlite.js +68 -13
  23. package/lib/cjs/CloudSqlite.js.map +1 -1
  24. package/lib/cjs/CodeSpecs.d.ts +3 -3
  25. package/lib/cjs/CodeSpecs.js.map +1 -1
  26. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  27. package/lib/cjs/DevTools.js.map +1 -1
  28. package/lib/cjs/DisplayStyle.d.ts +2 -2
  29. package/lib/cjs/DisplayStyle.js.map +1 -1
  30. package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
  31. package/lib/cjs/ECSqlStatement.js.map +1 -1
  32. package/lib/cjs/EditTxn.d.ts +55 -1
  33. package/lib/cjs/EditTxn.d.ts.map +1 -1
  34. package/lib/cjs/EditTxn.js +43 -1
  35. package/lib/cjs/EditTxn.js.map +1 -1
  36. package/lib/cjs/Element.d.ts +79 -10
  37. package/lib/cjs/Element.d.ts.map +1 -1
  38. package/lib/cjs/Element.js +38 -2
  39. package/lib/cjs/Element.js.map +1 -1
  40. package/lib/cjs/ElementAspect.d.ts +1 -1
  41. package/lib/cjs/ElementAspect.js.map +1 -1
  42. package/lib/cjs/ElementGraphics.js.map +1 -1
  43. package/lib/cjs/ElementTreeWalker.d.ts +5 -5
  44. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  45. package/lib/cjs/ExternalSource.d.ts +2 -2
  46. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  47. package/lib/cjs/ExternalSource.js.map +1 -1
  48. package/lib/cjs/GeographicCRSServices.d.ts +15 -0
  49. package/lib/cjs/GeographicCRSServices.d.ts.map +1 -1
  50. package/lib/cjs/GeographicCRSServices.js +13 -4
  51. package/lib/cjs/GeographicCRSServices.js.map +1 -1
  52. package/lib/cjs/IModelDb.d.ts +31 -23
  53. package/lib/cjs/IModelDb.d.ts.map +1 -1
  54. package/lib/cjs/IModelDb.js +44 -25
  55. package/lib/cjs/IModelDb.js.map +1 -1
  56. package/lib/cjs/IModelIncrementalSchemaLocater.js.map +1 -1
  57. package/lib/cjs/IModelJsFs.d.ts +2 -0
  58. package/lib/cjs/IModelJsFs.d.ts.map +1 -1
  59. package/lib/cjs/IModelJsFs.js +14 -0
  60. package/lib/cjs/IModelJsFs.js.map +1 -1
  61. package/lib/cjs/IpcHost.d.ts.map +1 -1
  62. package/lib/cjs/IpcHost.js +20 -9
  63. package/lib/cjs/IpcHost.js.map +1 -1
  64. package/lib/cjs/LineStyle.d.ts +6 -6
  65. package/lib/cjs/LineStyle.js.map +1 -1
  66. package/lib/cjs/Material.d.ts +1 -1
  67. package/lib/cjs/Material.js.map +1 -1
  68. package/lib/cjs/Model.d.ts +40 -6
  69. package/lib/cjs/Model.d.ts.map +1 -1
  70. package/lib/cjs/Model.js +24 -0
  71. package/lib/cjs/Model.js.map +1 -1
  72. package/lib/cjs/PartialChangeUnifier.d.ts +77 -0
  73. package/lib/cjs/PartialChangeUnifier.d.ts.map +1 -0
  74. package/lib/cjs/PartialChangeUnifier.js +234 -0
  75. package/lib/cjs/PartialChangeUnifier.js.map +1 -0
  76. package/lib/cjs/Relationship.d.ts +10 -10
  77. package/lib/cjs/Relationship.js +6 -6
  78. package/lib/cjs/Relationship.js.map +1 -1
  79. package/lib/cjs/SheetIndex.d.ts +4 -4
  80. package/lib/cjs/SheetIndex.d.ts.map +1 -1
  81. package/lib/cjs/SheetIndex.js.map +1 -1
  82. package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
  83. package/lib/cjs/SqliteChangesetReader.js +1 -1
  84. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  85. package/lib/cjs/Texture.d.ts +1 -1
  86. package/lib/cjs/Texture.js.map +1 -1
  87. package/lib/cjs/TxnManager.d.ts +17 -0
  88. package/lib/cjs/TxnManager.d.ts.map +1 -1
  89. package/lib/cjs/TxnManager.js +120 -13
  90. package/lib/cjs/TxnManager.js.map +1 -1
  91. package/lib/cjs/ViewDefinition.d.ts +25 -13
  92. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  93. package/lib/cjs/ViewDefinition.js +77 -25
  94. package/lib/cjs/ViewDefinition.js.map +1 -1
  95. package/lib/cjs/ViewStore.d.ts.map +1 -1
  96. package/lib/cjs/ViewStore.js +63 -21
  97. package/lib/cjs/ViewStore.js.map +1 -1
  98. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts +1 -1
  99. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  100. package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
  101. package/lib/cjs/core-backend.d.ts +3 -0
  102. package/lib/cjs/core-backend.d.ts.map +1 -1
  103. package/lib/cjs/core-backend.js +3 -0
  104. package/lib/cjs/core-backend.js.map +1 -1
  105. package/lib/cjs/domains/FunctionalElements.d.ts +1 -1
  106. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
  107. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  108. package/lib/cjs/domains/GenericElements.d.ts +2 -2
  109. package/lib/cjs/domains/GenericElements.d.ts.map +1 -1
  110. package/lib/cjs/domains/GenericElements.js.map +1 -1
  111. package/lib/cjs/internal/ChannelAdmin.d.ts +2 -2
  112. package/lib/cjs/internal/ChannelAdmin.d.ts.map +1 -1
  113. package/lib/cjs/internal/ChannelAdmin.js.map +1 -1
  114. package/lib/cjs/internal/IntegrityCheck.d.ts +10 -10
  115. package/lib/cjs/internal/IntegrityCheck.js +22 -22
  116. package/lib/cjs/internal/IntegrityCheck.js.map +1 -1
  117. package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -1
  118. package/lib/cjs/workspace/Settings.d.ts +6 -4
  119. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  120. package/lib/cjs/workspace/Settings.js.map +1 -1
  121. package/lib/esm/BriefcaseManager.d.ts +14 -62
  122. package/lib/esm/BriefcaseManager.d.ts.map +1 -1
  123. package/lib/esm/BriefcaseManager.js +30 -160
  124. package/lib/esm/BriefcaseManager.js.map +1 -1
  125. package/lib/esm/Category.d.ts +4 -4
  126. package/lib/esm/Category.js.map +1 -1
  127. package/lib/esm/ChangesetECAdaptor.d.ts +9 -1
  128. package/lib/esm/ChangesetECAdaptor.d.ts.map +1 -1
  129. package/lib/esm/ChangesetECAdaptor.js +7 -1
  130. package/lib/esm/ChangesetECAdaptor.js.map +1 -1
  131. package/lib/esm/ChangesetReader.d.ts +186 -0
  132. package/lib/esm/ChangesetReader.d.ts.map +1 -0
  133. package/lib/esm/ChangesetReader.js +368 -0
  134. package/lib/esm/ChangesetReader.js.map +1 -0
  135. package/lib/esm/ChangesetReaderTypes.d.ts +120 -0
  136. package/lib/esm/ChangesetReaderTypes.d.ts.map +1 -0
  137. package/lib/esm/ChangesetReaderTypes.js +20 -0
  138. package/lib/esm/ChangesetReaderTypes.js.map +1 -0
  139. package/lib/esm/CloudSqlite.d.ts +1 -1
  140. package/lib/esm/CloudSqlite.d.ts.map +1 -1
  141. package/lib/esm/CloudSqlite.js +69 -14
  142. package/lib/esm/CloudSqlite.js.map +1 -1
  143. package/lib/esm/CodeSpecs.d.ts +3 -3
  144. package/lib/esm/CodeSpecs.js.map +1 -1
  145. package/lib/esm/ConcurrentQuery.js.map +1 -1
  146. package/lib/esm/DevTools.js.map +1 -1
  147. package/lib/esm/DisplayStyle.d.ts +2 -2
  148. package/lib/esm/DisplayStyle.js.map +1 -1
  149. package/lib/esm/ECSqlStatement.d.ts.map +1 -1
  150. package/lib/esm/ECSqlStatement.js.map +1 -1
  151. package/lib/esm/EditTxn.d.ts +55 -1
  152. package/lib/esm/EditTxn.d.ts.map +1 -1
  153. package/lib/esm/EditTxn.js +43 -1
  154. package/lib/esm/EditTxn.js.map +1 -1
  155. package/lib/esm/Element.d.ts +79 -10
  156. package/lib/esm/Element.d.ts.map +1 -1
  157. package/lib/esm/Element.js +38 -2
  158. package/lib/esm/Element.js.map +1 -1
  159. package/lib/esm/ElementAspect.d.ts +1 -1
  160. package/lib/esm/ElementAspect.js.map +1 -1
  161. package/lib/esm/ElementGraphics.js.map +1 -1
  162. package/lib/esm/ElementTreeWalker.d.ts +5 -5
  163. package/lib/esm/ElementTreeWalker.js.map +1 -1
  164. package/lib/esm/ExternalSource.d.ts +2 -2
  165. package/lib/esm/ExternalSource.d.ts.map +1 -1
  166. package/lib/esm/ExternalSource.js.map +1 -1
  167. package/lib/esm/GeographicCRSServices.d.ts +15 -0
  168. package/lib/esm/GeographicCRSServices.d.ts.map +1 -1
  169. package/lib/esm/GeographicCRSServices.js +12 -4
  170. package/lib/esm/GeographicCRSServices.js.map +1 -1
  171. package/lib/esm/IModelDb.d.ts +31 -23
  172. package/lib/esm/IModelDb.d.ts.map +1 -1
  173. package/lib/esm/IModelDb.js +45 -26
  174. package/lib/esm/IModelDb.js.map +1 -1
  175. package/lib/esm/IModelIncrementalSchemaLocater.js.map +1 -1
  176. package/lib/esm/IModelJsFs.d.ts +2 -0
  177. package/lib/esm/IModelJsFs.d.ts.map +1 -1
  178. package/lib/esm/IModelJsFs.js +14 -0
  179. package/lib/esm/IModelJsFs.js.map +1 -1
  180. package/lib/esm/IpcHost.d.ts.map +1 -1
  181. package/lib/esm/IpcHost.js +20 -9
  182. package/lib/esm/IpcHost.js.map +1 -1
  183. package/lib/esm/LineStyle.d.ts +6 -6
  184. package/lib/esm/LineStyle.js.map +1 -1
  185. package/lib/esm/Material.d.ts +1 -1
  186. package/lib/esm/Material.js.map +1 -1
  187. package/lib/esm/Model.d.ts +40 -6
  188. package/lib/esm/Model.d.ts.map +1 -1
  189. package/lib/esm/Model.js +24 -0
  190. package/lib/esm/Model.js.map +1 -1
  191. package/lib/esm/PartialChangeUnifier.d.ts +77 -0
  192. package/lib/esm/PartialChangeUnifier.d.ts.map +1 -0
  193. package/lib/esm/PartialChangeUnifier.js +230 -0
  194. package/lib/esm/PartialChangeUnifier.js.map +1 -0
  195. package/lib/esm/Relationship.d.ts +10 -10
  196. package/lib/esm/Relationship.js +6 -6
  197. package/lib/esm/Relationship.js.map +1 -1
  198. package/lib/esm/SheetIndex.d.ts +4 -4
  199. package/lib/esm/SheetIndex.d.ts.map +1 -1
  200. package/lib/esm/SheetIndex.js.map +1 -1
  201. package/lib/esm/SqliteChangesetReader.d.ts.map +1 -1
  202. package/lib/esm/SqliteChangesetReader.js +1 -1
  203. package/lib/esm/SqliteChangesetReader.js.map +1 -1
  204. package/lib/esm/Texture.d.ts +1 -1
  205. package/lib/esm/Texture.js.map +1 -1
  206. package/lib/esm/TxnManager.d.ts +17 -0
  207. package/lib/esm/TxnManager.d.ts.map +1 -1
  208. package/lib/esm/TxnManager.js +121 -14
  209. package/lib/esm/TxnManager.js.map +1 -1
  210. package/lib/esm/ViewDefinition.d.ts +25 -13
  211. package/lib/esm/ViewDefinition.d.ts.map +1 -1
  212. package/lib/esm/ViewDefinition.js +78 -26
  213. package/lib/esm/ViewDefinition.js.map +1 -1
  214. package/lib/esm/ViewStore.d.ts.map +1 -1
  215. package/lib/esm/ViewStore.js +64 -22
  216. package/lib/esm/ViewStore.js.map +1 -1
  217. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts +1 -1
  218. package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  219. package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
  220. package/lib/esm/core-backend.d.ts +3 -0
  221. package/lib/esm/core-backend.d.ts.map +1 -1
  222. package/lib/esm/core-backend.js +3 -0
  223. package/lib/esm/core-backend.js.map +1 -1
  224. package/lib/esm/domains/FunctionalElements.d.ts +1 -1
  225. package/lib/esm/domains/FunctionalElements.d.ts.map +1 -1
  226. package/lib/esm/domains/FunctionalElements.js.map +1 -1
  227. package/lib/esm/domains/GenericElements.d.ts +2 -2
  228. package/lib/esm/domains/GenericElements.d.ts.map +1 -1
  229. package/lib/esm/domains/GenericElements.js.map +1 -1
  230. package/lib/esm/internal/ChannelAdmin.d.ts +2 -2
  231. package/lib/esm/internal/ChannelAdmin.d.ts.map +1 -1
  232. package/lib/esm/internal/ChannelAdmin.js.map +1 -1
  233. package/lib/esm/internal/IntegrityCheck.d.ts +10 -10
  234. package/lib/esm/internal/IntegrityCheck.js +22 -22
  235. package/lib/esm/internal/IntegrityCheck.js.map +1 -1
  236. package/lib/esm/internal/workspace/WorkspaceImpl.js.map +1 -1
  237. package/lib/esm/test/ElementDrivesElement.test.d.ts.map +1 -1
  238. package/lib/esm/test/ElementDrivesElement.test.js.map +1 -1
  239. package/lib/esm/test/IModelTestUtils.d.ts +1 -0
  240. package/lib/esm/test/IModelTestUtils.d.ts.map +1 -1
  241. package/lib/esm/test/IModelTestUtils.js +5 -0
  242. package/lib/esm/test/IModelTestUtils.js.map +1 -1
  243. package/lib/esm/test/IpcHost.test.js +112 -0
  244. package/lib/esm/test/IpcHost.test.js.map +1 -1
  245. package/lib/esm/test/annotations/LeaderGeometry.test.js +0 -1
  246. package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
  247. package/lib/esm/test/ecsql/dataset/ECSqlDatasets.js.map +1 -1
  248. package/lib/esm/test/ecsql/src/ECSqlTestRunner.test.js.map +1 -1
  249. package/lib/esm/test/element/DeleteDefinitionElements.test.js +819 -26
  250. package/lib/esm/test/element/DeleteDefinitionElements.test.js.map +1 -1
  251. package/lib/esm/test/element/ElementRoundTrip.test.js +144 -3
  252. package/lib/esm/test/element/ElementRoundTrip.test.js.map +1 -1
  253. package/lib/esm/test/element/SheetInformationAspect.test.js.map +1 -1
  254. package/lib/esm/test/hubaccess/Rebase.test.js +1 -1
  255. package/lib/esm/test/hubaccess/Rebase.test.js.map +1 -1
  256. package/lib/esm/test/hubaccess/SemanticRebase.test.js +2242 -68
  257. package/lib/esm/test/hubaccess/SemanticRebase.test.js.map +1 -1
  258. package/lib/esm/test/imodel/IModel.test.js +1 -1
  259. package/lib/esm/test/imodel/IModel.test.js.map +1 -1
  260. package/lib/esm/test/imodel/SchemaXmlImport.test.js +64 -0
  261. package/lib/esm/test/imodel/SchemaXmlImport.test.js.map +1 -1
  262. package/lib/esm/test/misc/GeoServices.test.js +43 -1
  263. package/lib/esm/test/misc/GeoServices.test.js.map +1 -1
  264. package/lib/esm/test/sheetindex/SheetIndex.test.js.map +1 -1
  265. package/lib/esm/test/standalone/ChangesetReader.test.js +4184 -1654
  266. package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
  267. package/lib/esm/test/standalone/DeleteElements.test.d.ts +2 -0
  268. package/lib/esm/test/standalone/DeleteElements.test.d.ts.map +1 -0
  269. package/lib/esm/test/standalone/DeleteElements.test.js +625 -0
  270. package/lib/esm/test/standalone/DeleteElements.test.js.map +1 -0
  271. package/lib/esm/test/standalone/GeometryStream.test.js.map +1 -1
  272. package/lib/esm/test/standalone/IntegrityCheck.test.js +214 -5
  273. package/lib/esm/test/standalone/IntegrityCheck.test.js.map +1 -1
  274. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.d.ts +2 -0
  275. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.d.ts.map +1 -0
  276. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.js +1862 -0
  277. package/lib/esm/test/standalone/SQliteChangesetReaderAndChangesetECAdaptor.test.js.map +1 -0
  278. package/lib/esm/test/standalone/TxnManager.test.js +90 -0
  279. package/lib/esm/test/standalone/TxnManager.test.js.map +1 -1
  280. package/lib/esm/test/standalone/ViewDefinition.test.js +18 -7
  281. package/lib/esm/test/standalone/ViewDefinition.test.js.map +1 -1
  282. package/lib/esm/test/standalone/Workspace.test.js.map +1 -1
  283. package/lib/esm/workspace/Settings.d.ts +6 -4
  284. package/lib/esm/workspace/Settings.d.ts.map +1 -1
  285. package/lib/esm/workspace/Settings.js.map +1 -1
  286. package/package.json +15 -15
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PartialChangeUnifier = exports.ChangeUnifierCache = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ /** @packageDocumentation
9
+ * @module ECDb
10
+ */
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const SQLiteDb_1 = require("./SQLiteDb");
14
+ /** @beta */
15
+ var ChangeUnifierCache;
16
+ (function (ChangeUnifierCache) {
17
+ /**
18
+ * Creates an in-memory cache backed by a `Map`.
19
+ * Fast, but may exhaust memory for very large changesets.
20
+ * @returns An [[ChangeCache]] backed by an in-memory `Map`.
21
+ * @beta
22
+ */
23
+ function createInMemoryCache() {
24
+ return new InMemoryCache();
25
+ }
26
+ ChangeUnifierCache.createInMemoryCache = createInMemoryCache;
27
+ /**
28
+ * Creates a SQLite-backed cache stored in a temporary SQlite database.
29
+ * Slower than in-memory but useful in handling large changesets.
30
+ * Temporary SQlite database is first created in memory and
31
+ * parts of a temporary database might be flushed to disk if the database becomes large or
32
+ * if SQLite comes under memory pressure.
33
+ * @param bufferedReadInstanceSizeInBytes Read-batch size in bytes (default 10 MB).
34
+ * @returns An [[ChangeCache]] backed by a SQLite temp table.
35
+ * @beta
36
+ */
37
+ function createSqliteBackedCache(bufferedReadInstanceSizeInBytes = 1024 * 1024 * 10) {
38
+ return new SqliteBackedCache(bufferedReadInstanceSizeInBytes);
39
+ }
40
+ ChangeUnifierCache.createSqliteBackedCache = createSqliteBackedCache;
41
+ })(ChangeUnifierCache || (exports.ChangeUnifierCache = ChangeUnifierCache = {}));
42
+ // ---------------------------------------------------------------------------
43
+ // Private: InMemoryCache
44
+ // ---------------------------------------------------------------------------
45
+ class InMemoryCache {
46
+ _cache = new Map();
47
+ get(key) {
48
+ return this._cache.get(key);
49
+ }
50
+ set(key, value) {
51
+ // Remove undefined meta keys to keep serialised form compact.
52
+ const meta = value.$meta;
53
+ if (meta) {
54
+ Object.keys(meta).forEach((k) => meta[k] === undefined && delete meta[k]);
55
+ }
56
+ this._cache.set(key, value);
57
+ }
58
+ *all() {
59
+ for (const key of Array.from(this._cache.keys()).sort()) {
60
+ const instance = this._cache.get(key);
61
+ if (instance)
62
+ yield instance;
63
+ }
64
+ }
65
+ count() {
66
+ return this._cache.size;
67
+ }
68
+ [Symbol.dispose]() {
69
+ this._cache.clear();
70
+ }
71
+ }
72
+ // ---------------------------------------------------------------------------
73
+ // Private: NativeSqliteBackedInstanceCache
74
+ // ---------------------------------------------------------------------------
75
+ class SqliteBackedCache {
76
+ bufferedReadInstanceSizeInBytes;
77
+ _cacheTable = `[${core_bentley_1.Guid.createValue()}]`;
78
+ static defaultBufferSize = 1024 * 1024 * 10; // 10 MB
79
+ _db;
80
+ constructor(bufferedReadInstanceSizeInBytes = SqliteBackedCache.defaultBufferSize) {
81
+ this.bufferedReadInstanceSizeInBytes = bufferedReadInstanceSizeInBytes;
82
+ this._db = new SQLiteDb_1.SQLiteDb();
83
+ this._db.openDb("", { skipFileCheck: true, rawSQLite: true, openMode: core_bentley_1.OpenMode.ReadWrite }); // creating temp sqlite db https://sqlite.org/inmemorydb.html#:~:text=Temporary%20Databases,under%20the%20default%20SQLite%20configuration.
84
+ if (bufferedReadInstanceSizeInBytes <= 0)
85
+ throw new Error("bufferedReadInstanceSizeInBytes must be greater than 0");
86
+ this.createTempTable();
87
+ }
88
+ createTempTable() {
89
+ this._db.withSqliteStatement(`CREATE TABLE ${this._cacheTable} ([key] text primary key, [value] text)`, (stmt) => {
90
+ if (core_bentley_1.DbResult.BE_SQLITE_DONE !== stmt.step())
91
+ throw new Error("unable to create temp cache table");
92
+ });
93
+ }
94
+ get(key) {
95
+ return this._db.withPreparedSqliteStatement(`SELECT [value] FROM ${this._cacheTable} WHERE [key]=?`, (stmt) => {
96
+ stmt.reset();
97
+ stmt.clearBindings();
98
+ stmt.bindString(1, key);
99
+ if (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW)
100
+ return JSON.parse(stmt.getValueString(0), core_common_1.Base64EncodedString.reviver);
101
+ return undefined;
102
+ });
103
+ }
104
+ set(key, value) {
105
+ const shallowCopy = Object.assign({}, value);
106
+ this._db.withPreparedSqliteStatement(`INSERT INTO ${this._cacheTable} ([key], [value]) VALUES (?, ?) ON CONFLICT ([key]) DO UPDATE SET [value] = [excluded].[value]`, (stmt) => {
107
+ stmt.reset();
108
+ stmt.clearBindings();
109
+ stmt.bindString(1, key);
110
+ stmt.bindString(2, JSON.stringify(shallowCopy, core_common_1.Base64EncodedString.replacer));
111
+ stmt.step();
112
+ });
113
+ }
114
+ *all() {
115
+ const sql = `
116
+ SELECT JSON_GROUP_ARRAY(JSON([value]))
117
+ FROM (
118
+ SELECT [value],
119
+ SUM(LENGTH([value])) OVER (ORDER BY [key] ROWS UNBOUNDED PRECEDING) / ${this.bufferedReadInstanceSizeInBytes} AS [bucket]
120
+ FROM ${this._cacheTable}
121
+ )
122
+ GROUP BY [bucket]`;
123
+ const stmt = this._db.prepareSqliteStatement(sql);
124
+ try {
125
+ while (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW) {
126
+ const bucket = JSON.parse(stmt.getValueString(0), core_common_1.Base64EncodedString.reviver);
127
+ for (const instance of bucket)
128
+ yield instance;
129
+ }
130
+ }
131
+ finally {
132
+ stmt[Symbol.dispose]();
133
+ }
134
+ }
135
+ count() {
136
+ return this._db.withPreparedSqliteStatement(`SELECT COUNT(*) FROM ${this._cacheTable}`, (stmt) => {
137
+ stmt.reset();
138
+ if (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW)
139
+ return stmt.getValue(0).getInteger();
140
+ return 0;
141
+ });
142
+ }
143
+ [Symbol.dispose]() {
144
+ this._db.closeDb();
145
+ }
146
+ }
147
+ // ---------------------------------------------------------------------------
148
+ // PartialChangeUnifier
149
+ // ---------------------------------------------------------------------------
150
+ /**
151
+ * Combines partial EC change instances (one per SQLite table row) into complete
152
+ * instances that span all tables mapping to a single EC entity.
153
+ *
154
+ * The merge key is derived from the `instanceKey` and `stage` stored in `$meta.instanceKey` and `$meta.stage`.
155
+ *
156
+ * **Usage:**
157
+ * ```ts
158
+ * using reader = ChangesetReader.openFile({ fileName, db });
159
+ * using unifier = new PartialChangeUnifier();
160
+ * while (reader.step()) {
161
+ * unifier.appendFrom(reader);
162
+ * }
163
+ * for (const instance of unifier.instances) { ... }
164
+ * ```
165
+ * @beta
166
+ */
167
+ class PartialChangeUnifier {
168
+ _cache;
169
+ constructor(_cache = new InMemoryCache()) {
170
+ this._cache = _cache;
171
+ }
172
+ /** Releases the underlying cache. */
173
+ [Symbol.dispose]() {
174
+ this._cache[Symbol.dispose]();
175
+ }
176
+ /** Number of complete (merged) instances currently accumulated. */
177
+ get instanceCount() {
178
+ return this._cache.count();
179
+ }
180
+ /**
181
+ * Append partial changes from the current reader row and merge them into the cache.
182
+ *
183
+ * @param source Any [ChangeSource]($backend) positioned on a valid row.
184
+ * @beta
185
+ */
186
+ appendFrom(source) {
187
+ if (source.op === "Updated") {
188
+ if (source.inserted)
189
+ this.combine(source.inserted);
190
+ if (source.deleted)
191
+ this.combine(source.deleted);
192
+ }
193
+ else if (source.op === "Inserted" && source.inserted) {
194
+ this.combine(source.inserted);
195
+ }
196
+ else if (source.op === "Deleted" && source.deleted) {
197
+ this.combine(source.deleted);
198
+ }
199
+ }
200
+ /**
201
+ * Iterator over all fully-merged EC change instances.
202
+ * @beta
203
+ */
204
+ get instances() {
205
+ return this._cache.all();
206
+ }
207
+ // ---------------------------------------------------------------------------
208
+ // Private helpers
209
+ // ---------------------------------------------------------------------------
210
+ buildKey(instance) {
211
+ const { instanceKey, stage } = instance.$meta;
212
+ return `${instanceKey}-${stage}`.toLowerCase();
213
+ }
214
+ combine(rhs) {
215
+ const key = this.buildKey(rhs);
216
+ const lhs = this._cache.get(key);
217
+ if (lhs) {
218
+ // Merge data fields — rhs wins for any overlapping columns.
219
+ const { $meta: _rhsMeta, ...rhsData } = rhs;
220
+ Object.assign(lhs, rhsData);
221
+ // Accumulate per-table metadata lists.
222
+ lhs.$meta.tables = [...lhs.$meta.tables, ...rhs.$meta.tables];
223
+ lhs.$meta.changeIndexes = [...lhs.$meta.changeIndexes, ...rhs.$meta.changeIndexes];
224
+ // ECInstanceId will be part of changeset fetchedProps for every table, so we should not include multiple of those in the final list
225
+ lhs.$meta.changeFetchedPropNames = [...new Set([...lhs.$meta.changeFetchedPropNames, ...rhs.$meta.changeFetchedPropNames])];
226
+ this._cache.set(key, lhs);
227
+ }
228
+ else {
229
+ this._cache.set(key, rhs);
230
+ }
231
+ }
232
+ }
233
+ exports.PartialChangeUnifier = PartialChangeUnifier;
234
+ //# sourceMappingURL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GAAG,CAAC,CAAC;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,GAAG,EAAE,CAAC;YACR,4DAA4D;YAC5D,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,GAAG,GAAG,CAAC;YAC5C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAC5B,uCAAuC;YACvC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAC9D,GAAG,CAAC,KAAK,CAAC,aAAa,GAAG,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACnF,oIAAoI;YACpI,GAAG,CAAC,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;YAC5H,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;CACF;AApED,oDAoEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module ECDb\n */\nimport { DbResult, Guid, OpenMode } from \"@itwin/core-bentley\";\nimport { Base64EncodedString } from \"@itwin/core-common\";\nimport { SqliteStatement } from \"./SqliteStatement\";\nimport { ChangeInstance, ChangeSource } from \"./ChangesetReaderTypes\";\nimport { _nativeDb } from \"./internal/Symbols\";\nimport { SQLiteDb } from \"./SQLiteDb\";\n\n// ---------------------------------------------------------------------------\n// ChangeCache — interface + factory\n// ---------------------------------------------------------------------------\n\n/**\n * Cache used by [[PartialChangeUnifier]] to accumulate and merge\n * partial EC change instances.\n * @beta\n */\nexport interface ChangeCache extends Disposable {\n /** Retrieve a cached instance by key, or `undefined` if absent. */\n get(key: string): ChangeInstance | undefined;\n /** Insert or replace a cached instance. */\n set(key: string, value: ChangeInstance): void;\n /** Iterate over all cached instances. */\n all(): IterableIterator<ChangeInstance>;\n /** Number of instances currently in the cache. */\n count(): number;\n}\n\n/** @beta */\nexport namespace ChangeUnifierCache {\n /**\n * Creates an in-memory cache backed by a `Map`.\n * Fast, but may exhaust memory for very large changesets.\n * @returns An [[ChangeCache]] backed by an in-memory `Map`.\n * @beta\n */\n export function createInMemoryCache(): ChangeCache {\n return new InMemoryCache();\n }\n\n /**\n * Creates a SQLite-backed cache stored in a temporary SQlite database.\n * Slower than in-memory but useful in handling large changesets.\n * Temporary SQlite database is first created in memory and\n * parts of a temporary database might be flushed to disk if the database becomes large or\n * if SQLite comes under memory pressure.\n * @param bufferedReadInstanceSizeInBytes Read-batch size in bytes (default 10 MB).\n * @returns An [[ChangeCache]] backed by a SQLite temp table.\n * @beta\n */\n export function createSqliteBackedCache(\n bufferedReadInstanceSizeInBytes = 1024 * 1024 * 10,\n ): ChangeCache {\n return new SqliteBackedCache(bufferedReadInstanceSizeInBytes);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Private: InMemoryCache\n// ---------------------------------------------------------------------------\n\nclass InMemoryCache implements ChangeCache {\n private readonly _cache = new Map<string, ChangeInstance>();\n\n public get(key: string): ChangeInstance | undefined {\n return this._cache.get(key);\n }\n\n public set(key: string, value: ChangeInstance): void {\n // Remove undefined meta keys to keep serialised form compact.\n const meta = value.$meta as any;\n if (meta) {\n Object.keys(meta).forEach((k) => meta[k] === undefined && delete meta[k]);\n }\n this._cache.set(key, value);\n }\n\n public *all(): IterableIterator<ChangeInstance> {\n for (const key of Array.from(this._cache.keys()).sort()) {\n const instance = this._cache.get(key);\n if (instance)\n yield instance;\n }\n }\n\n public count(): number {\n return this._cache.size;\n }\n\n public [Symbol.dispose](): void {\n this._cache.clear();\n }\n}\n\n// ---------------------------------------------------------------------------\n// Private: NativeSqliteBackedInstanceCache\n// ---------------------------------------------------------------------------\n\nclass SqliteBackedCache implements ChangeCache {\n private readonly _cacheTable = `[${Guid.createValue()}]`;\n public static readonly defaultBufferSize = 1024 * 1024 * 10; // 10 MB\n private _db: SQLiteDb;\n public constructor(\n public readonly bufferedReadInstanceSizeInBytes: number = SqliteBackedCache.defaultBufferSize,\n ) {\n this._db = new SQLiteDb();\n this._db.openDb(\"\", { skipFileCheck: true, rawSQLite: true, openMode: OpenMode.ReadWrite }); // creating temp sqlite db https://sqlite.org/inmemorydb.html#:~:text=Temporary%20Databases,under%20the%20default%20SQLite%20configuration.\n if (bufferedReadInstanceSizeInBytes <= 0)\n throw new Error(\"bufferedReadInstanceSizeInBytes must be greater than 0\");\n this.createTempTable();\n }\n\n private createTempTable(): void {\n this._db.withSqliteStatement(`CREATE TABLE ${this._cacheTable} ([key] text primary key, [value] text)`, (stmt: SqliteStatement) => {\n if (DbResult.BE_SQLITE_DONE !== stmt.step())\n throw new Error(\"unable to create temp cache table\");\n });\n }\n\n public get(key: string): ChangeInstance | undefined {\n return this._db.withPreparedSqliteStatement(\n `SELECT [value] FROM ${this._cacheTable} WHERE [key]=?`,\n (stmt: SqliteStatement) => {\n stmt.reset();\n stmt.clearBindings();\n stmt.bindString(1, key);\n if (stmt.step() === DbResult.BE_SQLITE_ROW)\n return JSON.parse(stmt.getValueString(0), Base64EncodedString.reviver) as ChangeInstance;\n return undefined;\n },\n );\n }\n\n public set(key: string, value: ChangeInstance): void {\n const shallowCopy = Object.assign({}, value);\n this._db.withPreparedSqliteStatement(\n `INSERT INTO ${this._cacheTable} ([key], [value]) VALUES (?, ?) ON CONFLICT ([key]) DO UPDATE SET [value] = [excluded].[value]`,\n (stmt: SqliteStatement) => {\n stmt.reset();\n stmt.clearBindings();\n stmt.bindString(1, key);\n stmt.bindString(2, JSON.stringify(shallowCopy, Base64EncodedString.replacer));\n stmt.step();\n },\n );\n }\n\n public *all(): IterableIterator<ChangeInstance> {\n const sql = `\n SELECT JSON_GROUP_ARRAY(JSON([value]))\n FROM (\n SELECT [value],\n SUM(LENGTH([value])) OVER (ORDER BY [key] ROWS UNBOUNDED PRECEDING) / ${this.bufferedReadInstanceSizeInBytes} AS [bucket]\n FROM ${this._cacheTable}\n )\n GROUP BY [bucket]`;\n\n const stmt = this._db.prepareSqliteStatement(sql);\n try {\n while (stmt.step() === DbResult.BE_SQLITE_ROW) {\n const bucket = JSON.parse(stmt.getValueString(0), Base64EncodedString.reviver) as ChangeInstance[];\n for (const instance of bucket)\n yield instance;\n }\n } finally {\n stmt[Symbol.dispose]();\n }\n }\n\n public count(): number {\n return this._db.withPreparedSqliteStatement(\n `SELECT COUNT(*) FROM ${this._cacheTable}`,\n (stmt: SqliteStatement) => {\n stmt.reset();\n if (stmt.step() === DbResult.BE_SQLITE_ROW)\n return stmt.getValue(0).getInteger();\n return 0;\n },\n );\n }\n\n public [Symbol.dispose](): void {\n this._db.closeDb();\n }\n}\n\n// ---------------------------------------------------------------------------\n// PartialChangeUnifier\n// ---------------------------------------------------------------------------\n\n/**\n * Combines partial EC change instances (one per SQLite table row) into complete\n * instances that span all tables mapping to a single EC entity.\n *\n * The merge key is derived from the `instanceKey` and `stage` stored in `$meta.instanceKey` and `$meta.stage`.\n *\n * **Usage:**\n * ```ts\n * using reader = ChangesetReader.openFile({ fileName, db });\n * using unifier = new PartialChangeUnifier();\n * while (reader.step()) {\n * unifier.appendFrom(reader);\n * }\n * for (const instance of unifier.instances) { ... }\n * ```\n * @beta\n */\nexport class PartialChangeUnifier implements Disposable {\n public constructor(\n private readonly _cache: ChangeCache = new InMemoryCache(),\n ) { }\n\n /** Releases the underlying cache. */\n public [Symbol.dispose](): void {\n this._cache[Symbol.dispose]();\n }\n\n /** Number of complete (merged) instances currently accumulated. */\n public get instanceCount(): number {\n return this._cache.count();\n }\n\n /**\n * Append partial changes from the current reader row and merge them into the cache.\n *\n * @param source Any [ChangeSource]($backend) positioned on a valid row.\n * @beta\n */\n public appendFrom(source: ChangeSource): void {\n if (source.op === \"Updated\") {\n if (source.inserted)\n this.combine(source.inserted);\n if (source.deleted)\n this.combine(source.deleted);\n } else if (source.op === \"Inserted\" && source.inserted) {\n this.combine(source.inserted);\n } else if (source.op === \"Deleted\" && source.deleted) {\n this.combine(source.deleted);\n }\n }\n\n /**\n * Iterator over all fully-merged EC change instances.\n * @beta\n */\n public get instances(): IterableIterator<ChangeInstance> {\n return this._cache.all();\n }\n\n // ---------------------------------------------------------------------------\n // Private helpers\n // ---------------------------------------------------------------------------\n\n private buildKey(instance: ChangeInstance): string {\n const { instanceKey, stage } = instance.$meta;\n return `${instanceKey}-${stage}`.toLowerCase();\n }\n\n private combine(rhs: ChangeInstance): void {\n const key = this.buildKey(rhs);\n const lhs = this._cache.get(key);\n if (lhs) {\n // Merge data fields — rhs wins for any overlapping columns.\n const { $meta: _rhsMeta, ...rhsData } = rhs;\n Object.assign(lhs, rhsData);\n // Accumulate per-table metadata lists.\n lhs.$meta.tables = [...lhs.$meta.tables, ...rhs.$meta.tables];\n lhs.$meta.changeIndexes = [...lhs.$meta.changeIndexes, ...rhs.$meta.changeIndexes];\n // ECInstanceId will be part of changeset fetchedProps for every table, so we should not include multiple of those in the final list\n lhs.$meta.changeFetchedPropNames = [...new Set([...lhs.$meta.changeFetchedPropNames, ...rhs.$meta.changeFetchedPropNames])];\n this._cache.set(key, lhs);\n } else {\n this._cache.set(key, rhs);\n }\n }\n}\n"]}
@@ -43,7 +43,7 @@ export declare class Relationship extends Entity {
43
43
  * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.
44
44
  * @param _props The ElementDrivesElement relationship instance.
45
45
  * @param _iModel The iModel
46
- * @deprecated Use onRootChangedArg instead.
46
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use onRootChangedArg instead.
47
47
  */
48
48
  static onRootChanged(_props: RelationshipProps, _iModel: IModelDb): void;
49
49
  /**
@@ -57,7 +57,7 @@ export declare class Relationship extends Entity {
57
57
  * A subclass of ElementDrivesElement can re-implement this static method to take some action.
58
58
  * @param _props The deleted ElementDrivesElement relationship instance.
59
59
  * @param _iModel The iModel
60
- * @deprecated Use onDeletedDependencyArg instead.
60
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use onDeletedDependencyArg instead.
61
61
  */
62
62
  static onDeletedDependency(_props: RelationshipProps, _iModel: IModelDb): void;
63
63
  /**
@@ -67,7 +67,7 @@ export declare class Relationship extends Entity {
67
67
  insert(txn: EditTxn): Id64String;
68
68
  /**
69
69
  * Insert this Relationship into the iModel.
70
- * @deprecated Use Relationship.insert(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
70
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use Relationship.insert(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
71
71
  */
72
72
  insert(): Id64String;
73
73
  /**
@@ -77,7 +77,7 @@ export declare class Relationship extends Entity {
77
77
  update(txn: EditTxn): void;
78
78
  /**
79
79
  * Update this Relationship in the iModel.
80
- * @deprecated Use Relationship.update(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
80
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use Relationship.update(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
81
81
  */
82
82
  update(): void;
83
83
  /**
@@ -87,7 +87,7 @@ export declare class Relationship extends Entity {
87
87
  delete(txn: EditTxn): void;
88
88
  /**
89
89
  * Delete this Relationship from the iModel.
90
- * @deprecated Use Relationship.delete(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
90
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use Relationship.delete(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
91
91
  */
92
92
  delete(): void;
93
93
  static getInstance<T extends Relationship>(iModel: IModelDb, criteria: Id64String | SourceAndTarget): T;
@@ -117,7 +117,7 @@ export declare class ElementRefersToElements extends Relationship {
117
117
  * @param sourceId The sourceId of the relationship, that is, the driver element.
118
118
  * @param targetId The targetId of the relationship, that is, the driven element.
119
119
  * @return The Id of the inserted Relationship.
120
- * @deprecated Use ElementRefersToElements.insert(txn, ...) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
120
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use ElementRefersToElements.insert(txn, ...) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.
121
121
  */
122
122
  static insert(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): Id64String;
123
123
  protected collectReferenceIds(referenceIds: EntityReferenceSet): void;
@@ -420,22 +420,22 @@ export declare class Relationships {
420
420
  * @param props The properties of the new relationship.
421
421
  * @returns The Id of the newly inserted relationship.
422
422
  * @note The id property of the props object is set as a side effect of this function.
423
- * @deprecated Use EditTxn.insertRelationship instead.
423
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.insertRelationship instead.
424
424
  */
425
425
  insertInstance(props: RelationshipProps): Id64String;
426
426
  /** Update the properties of an existing relationship instance in the iModel.
427
427
  * @param props the properties of the relationship instance to update. Any properties that are not present will be left unchanged.
428
- * @deprecated Use EditTxn.updateRelationship instead.
428
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.updateRelationship instead.
429
429
  */
430
430
  updateInstance(props: RelationshipProps): void;
431
431
  /** Delete an Relationship instance from this iModel.
432
- * @deprecated Use EditTxn.deleteRelationship instead.
432
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.deleteRelationship instead.
433
433
  */
434
434
  deleteInstance(props: RelationshipProps): void;
435
435
  /** Delete multiple Relationship instances from this iModel.
436
436
  * @param props The properties of the relationship instances to delete.
437
437
  * @remarks This method handles bulk deletion of relationships and supports mixed collections containing instances from different relationship classes.
438
- * @deprecated Use EditTxn.deleteRelationships instead.
438
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.deleteRelationships instead.
439
439
  */
440
440
  deleteInstances(props: ReadonlyArray<RelationshipProps>): void;
441
441
  /** Get the props of a Relationship instance
@@ -62,7 +62,7 @@ class Relationship extends Entity_1.Entity {
62
62
  * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.
63
63
  * @param _props The ElementDrivesElement relationship instance.
64
64
  * @param _iModel The iModel
65
- * @deprecated Use onRootChangedArg instead.
65
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use onRootChangedArg instead.
66
66
  */
67
67
  static onRootChanged(_props, _iModel) { }
68
68
  /**
@@ -79,7 +79,7 @@ class Relationship extends Entity_1.Entity {
79
79
  * A subclass of ElementDrivesElement can re-implement this static method to take some action.
80
80
  * @param _props The deleted ElementDrivesElement relationship instance.
81
81
  * @param _iModel The iModel
82
- * @deprecated Use onDeletedDependencyArg instead.
82
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use onDeletedDependencyArg instead.
83
83
  */
84
84
  static onDeletedDependency(_props, _iModel) { }
85
85
  insert(txn) { return this.id = (txn ?? this.iModel[Symbols_1._implicitTxn]).insertRelationship(this.toJSON()); }
@@ -439,20 +439,20 @@ class Relationships {
439
439
  * @param props The properties of the new relationship.
440
440
  * @returns The Id of the newly inserted relationship.
441
441
  * @note The id property of the props object is set as a side effect of this function.
442
- * @deprecated Use EditTxn.insertRelationship instead.
442
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.insertRelationship instead.
443
443
  */
444
444
  insertInstance(props) {
445
445
  return this._iModel[Symbols_1._implicitTxn].insertRelationship(props);
446
446
  }
447
447
  /** Update the properties of an existing relationship instance in the iModel.
448
448
  * @param props the properties of the relationship instance to update. Any properties that are not present will be left unchanged.
449
- * @deprecated Use EditTxn.updateRelationship instead.
449
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.updateRelationship instead.
450
450
  */
451
451
  updateInstance(props) {
452
452
  this._iModel[Symbols_1._implicitTxn].updateRelationship(props);
453
453
  }
454
454
  /** Delete an Relationship instance from this iModel.
455
- * @deprecated Use EditTxn.deleteRelationship instead.
455
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.deleteRelationship instead.
456
456
  */
457
457
  deleteInstance(props) {
458
458
  this._iModel[Symbols_1._implicitTxn].deleteRelationship(props);
@@ -460,7 +460,7 @@ class Relationships {
460
460
  /** Delete multiple Relationship instances from this iModel.
461
461
  * @param props The properties of the relationship instances to delete.
462
462
  * @remarks This method handles bulk deletion of relationships and supports mixed collections containing instances from different relationship classes.
463
- * @deprecated Use EditTxn.deleteRelationships instead.
463
+ * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.deleteRelationships instead.
464
464
  */
465
465
  deleteInstances(props) {
466
466
  this._iModel[Symbols_1._implicitTxn].deleteRelationships(props);
@@ -1 +1 @@
1
- {"version":3,"file":"Relationship.js","sourceRoot":"","sources":["../../src/Relationship.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA+E;AAC/E,oDAAyG;AAEzG,qCAAkC;AAClC,uCAAoC;AAEpC,gDAA6D;AAC7D,gEAA6D;AAgB7D;;GAEG;AACH,MAAa,YAAa,SAAQ,eAAM;IAC/B,MAAM,KAAc,SAAS,KAAa,OAAO,cAAc,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAa;IACrB,QAAQ,CAAa;IAErC,YAAsB,KAAwB,EAAE,MAAgB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AM,EAAO,CAAC,CAAC,CAAC,SAAS,CAAC;YACjF,CAAC,CAAC,CAAC;QACL,CAAC;QACD,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YACxB,KAAK,CAAC,aAAa,GAAI,KAAa,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,WAAW,CAAyB,eAAuB,EAAE,QAAsC;QACxG,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAyB,gBAAwB,EAAE,QAAsC;QAC5G,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,CAAoB,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAClG,OAAO,SAAS,KAAK,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1G,CAAC;CACF;AArHD,sCAqHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Relationships\n */\n\nimport { DbResult, Id64, Id64String, IModelStatus } from \"@itwin/core-bentley\";\nimport { EntityReferenceSet, IModelError, RelationshipProps, SourceAndTarget } from \"@itwin/core-common\";\nimport { ECSqlStatement } from \"./ECSqlStatement\";\nimport { Entity } from \"./Entity\";\nimport { EditTxn } from \"./EditTxn\";\nimport { IModelDb } from \"./IModelDb\";\nimport { _implicitTxn, _nativeDb } from \"./internal/Symbols\";\nimport { RelationshipClass } from \"@itwin/ecschema-metadata\";\n\nexport type { SourceAndTarget, RelationshipProps } from \"@itwin/core-common\"; // for backwards compatibility\n\n/** Argument for relationship dependency callbacks.\n * @beta\n */\nexport interface OnDependencyArg {\n /** The iModel for the relationship affected by this method. */\n iModel: IModelDb;\n /** The ElementDrivesElement relationship instance affected by this method. */\n props: RelationshipProps;\n /** The transaction for indirect processing. */\n indirectEditTxn: EditTxn;\n}\n\n/** Base class for all link table ECRelationships\n * @public\n */\nexport class Relationship extends Entity {\n public static override get className(): string { return \"Relationship\"; }\n public readonly sourceId: Id64String;\n public readonly targetId: Id64String;\n\n protected constructor(props: RelationshipProps, iModel: IModelDb) {\n super(props, iModel);\n this.sourceId = Id64.fromJSON(props.sourceId);\n this.targetId = Id64.fromJSON(props.targetId);\n }\n\n public override toJSON(): RelationshipProps {\n const val = super.toJSON() as RelationshipProps;\n val.sourceId = this.sourceId;\n val.targetId = this.targetId;\n return val;\n }\n\n /** Query metadata for this relationship class from the iModel's schema. Returns cached metadata if available.*/\n public override async getMetaData(): Promise<RelationshipClass> {\n if (this._metadata && RelationshipClass.isRelationshipClass(this._metadata)) {\n return this._metadata;\n }\n\n const relationship = await this.iModel.schemaContext.getSchemaItem(this.schemaItemKey, RelationshipClass);\n if (relationship !== undefined) {\n this._metadata = relationship;\n return this._metadata;\n } else {\n throw new Error(`Cannot get metadata for ${this.classFullName}`);\n }\n }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when its input has changed or is the output of some upstream relationship whose input has changed.\n * This callback is invoked after the input element has been processed by upstream relationships.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.\n * @beta\n */\n public static onRootChangedArg(arg: OnDependencyArg): void {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n this.onRootChanged(arg.props, arg.iModel);\n }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when its input has changed or is the output of some upstream relationship whose input has changed.\n * This callback is invoked after the input element has been processed by upstream relationships.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.\n * @param _props The ElementDrivesElement relationship instance.\n * @param _iModel The iModel\n * @deprecated Use onRootChangedArg instead.\n */\n public static onRootChanged(_props: RelationshipProps, _iModel: IModelDb): void { }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when the relationship instance has been deleted.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action.\n * @beta\n */\n public static onDeletedDependencyArg(arg: OnDependencyArg): void {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n this.onDeletedDependency(arg.props, arg.iModel);\n }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when the relationship instance has been deleted.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action.\n * @param _props The deleted ElementDrivesElement relationship instance.\n * @param _iModel The iModel\n * @deprecated Use onDeletedDependencyArg instead.\n */\n public static onDeletedDependency(_props: RelationshipProps, _iModel: IModelDb): void { }\n\n /**\n * Insert this Relationship into the iModel using the supplied EditTxn.\n * @beta\n */\n public insert(txn: EditTxn): Id64String;\n /**\n * Insert this Relationship into the iModel.\n * @deprecated Use Relationship.insert(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public insert(): Id64String;\n public insert(txn?: EditTxn): Id64String { return this.id = (txn ?? this.iModel[_implicitTxn]).insertRelationship(this.toJSON()); }\n\n /**\n * Update this Relationship in the iModel using the supplied EditTxn.\n * @beta\n */\n public update(txn: EditTxn): void;\n /**\n * Update this Relationship in the iModel.\n * @deprecated Use Relationship.update(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public update(): void;\n public update(txn?: EditTxn) { (txn ?? this.iModel[_implicitTxn]).updateRelationship(this.toJSON()); }\n\n /**\n * Delete this Relationship from the iModel using the supplied EditTxn.\n * @beta\n */\n public delete(txn: EditTxn): void;\n /**\n * Delete this Relationship from the iModel.\n * @deprecated Use Relationship.delete(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public delete(): void;\n public delete(txn?: EditTxn) { (txn ?? this.iModel[_implicitTxn]).deleteRelationship(this.toJSON()); }\n\n public static getInstance<T extends Relationship>(iModel: IModelDb, criteria: Id64String | SourceAndTarget): T { return iModel.relationships.getInstance(this.classFullName, criteria); }\n}\n\n/** A Relationship where one Element refers to another Element\n * @public\n */\nexport class ElementRefersToElements extends Relationship {\n public static override get className(): string { return \"ElementRefersToElements\"; }\n /** Create an instance of the Relationship.\n * @param iModel The iModel that will contain the relationship\n * @param sourceId The sourceId of the relationship, that is, the driver element\n * @param targetId The targetId of the relationship, that is, the driven element\n * @return an instance of the specified class.\n */\n public static create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): T {\n return iModel.relationships.createInstance({ sourceId, targetId, classFullName: this.classFullName }) as T;\n }\n\n /** Insert a new instance of the Relationship using an explicit transaction.\n * @param txn The EditTxn used to perform the insert.\n * @param sourceId The sourceId of the relationship, that is, the driver element\n * @param targetId The targetId of the relationship, that is, the driven element\n * @return The Id of the inserted Relationship.\n * @beta\n */\n public static insert(txn: EditTxn, sourceId: Id64String, targetId: Id64String): Id64String;\n /** Insert a new instance of the Relationship.\n * @param iModel The iModel that will contain the relationship.\n * @param sourceId The sourceId of the relationship, that is, the driver element.\n * @param targetId The targetId of the relationship, that is, the driven element.\n * @return The Id of the inserted Relationship.\n * @deprecated Use ElementRefersToElements.insert(txn, ...) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public static insert(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): Id64String;\n public static insert(txnOrIModel: EditTxn | IModelDb, sourceId: Id64String, targetId: Id64String): Id64String {\n const txn = txnOrIModel instanceof EditTxn ? txnOrIModel : txnOrIModel[_implicitTxn];\n const relationship = this.create(txn.iModel, sourceId, targetId);\n return txn.insertRelationship(relationship.toJSON());\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addElement(this.targetId);\n }\n}\n\n/** Relates a [[DrawingGraphic]] to the [[Element]] that it represents\n * @public\n */\nexport class DrawingGraphicRepresentsElement extends ElementRefersToElements {\n public static override get className(): string { return \"DrawingGraphicRepresentsElement\"; }\n}\n\n/** Relates a [[GraphicalElement3d]] to the [[Element]] that it represents\n * @public\n */\nexport class GraphicalElement3dRepresentsElement extends ElementRefersToElements {\n public static override get className(): string { return \"GraphicalElement3dRepresentsElement\"; }\n}\n\n/** Relates a [[SynchronizationConfigLink]] to N [[ExternalSource]] instances.\n * Each relationship instance represents an external source processed by the synchronization configuration.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class SynchronizationConfigProcessesSources extends ElementRefersToElements {\n public static override get className(): string { return \"SynchronizationConfigProcessesSources\"; }\n}\n\n/** Relates a [[SynchronizationConfigLink]] to *root* [[ExternalSource]] instances.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class SynchronizationConfigSpecifiesRootSources extends SynchronizationConfigProcessesSources {\n public static override get className(): string { return \"SynchronizationConfigSpecifiesRootSources\"; }\n}\n\n/** Properties that are common to all types of link table ECRelationships\n * @public\n */\nexport interface ElementGroupsMembersProps extends RelationshipProps {\n memberPriority: number;\n}\n\n/** An ElementRefersToElements relationship where one Element *groups* a set of other Elements.\n * @public\n */\nexport class ElementGroupsMembers extends ElementRefersToElements {\n public static override get className(): string { return \"ElementGroupsMembers\"; }\n public memberPriority: number;\n\n constructor(props: ElementGroupsMembersProps, iModel: IModelDb) {\n super(props, iModel);\n this.memberPriority = props.memberPriority;\n }\n\n public static override create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, memberPriority: number = 0): T {\n const props: ElementGroupsMembersProps = { sourceId, targetId, memberPriority, classFullName: this.classFullName };\n return iModel.relationships.createInstance(props) as T;\n }\n}\n\n/** Relates a [[DefinitionGroup]] to its [[DefinitionElement]] members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.10\n * @public\n */\nexport class DefinitionGroupGroupsDefinitions extends ElementGroupsMembers {\n public static override get className(): string { return \"DefinitionGroupGroupsDefinitions\"; }\n}\n\n/** Represents group membership where the group Element (and its properties) impart information about the member Elements above mere membership.\n * Implies that properties of the group should be considered as properties of its members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.11\n * @public\n */\nexport class GroupImpartsToMembers extends ElementGroupsMembers {\n public static override get className(): string { return \"GroupImpartsToMembers\"; }\n}\n\n/** Relates an [[ExternalSourceGroup]] to its [[ExternalSource]] members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class ExternalSourceGroupGroupsSources extends ElementGroupsMembers {\n public static override get className(): string { return \"ExternalSourceGroupGroupsSources\"; }\n}\n\n/** Properties that are common to all types of ElementDrivesElements\n * @beta\n */\nexport interface ElementDrivesElementProps extends RelationshipProps {\n status: number;\n priority: number;\n}\n\n/** A Relationship indicating that one Element *drives* another Element.\n * An ElementDrivesElement relationship defines a one-way \"driving\" relationship from the source to the target.\n * When the source of an ElementDrivesElement relationship changes, the ElementDrivesElement itself can get a callback, and both the source and target elements can get callbacks.\n * By inserting ElementDrivesElement relationships, an app can create and store an acyclic directed graph of dependencies between elements.\n *\n * # Defining dependencies\n * Create an ElementDrivesElement relationship to specify that the source element drives the target element.\n * For example, to specify that element e1 drives element e2, create a relationship between them like this:\n * ```ts\n * const ede = ElementDrivesElement.create(iModel, e1id, e2id);\n * ede.insert();\n * ```\n * This creates a persistent relationship. The fact that e1 drives e2 is persisted in the iModel.\n *\n * # Defining dependency graphs\n * When you create multiple ElementDrivesElement relationships, you create a network of dependencies. The target of one may be the source of another.\n * A change in the content of an DgnElement can therefore trigger changes to many downstream elements.\n *\n * For example, to make element e1 drive element e2 and e2 drive another element, e3, create two relationships like this:\n * ```ts\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\n * ede12.insert();\n * ede23.insert();\n * ```\n * Those two relationships create this graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n * Where the \"-->\" is meant to represent a driving relationship.\n *\n * The order in which you create the relationships does not matter.\n * The graph indicates that e3 depends on e2 and e2 depends on e1.\n *\n * An ElementDrivesElement relationship is between one source element and one target element.\n * Many ElementDrivesElement relationships can point to a given element, and many can point out of it.\n * Thus, you can define many:many relationships.\n * For example:\n * ```ts\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\n * const ede112 = ElementDrivesElement.create(iModel, e11id, e2id);\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\n * const ede231 = ElementDrivesElement.create(iModel, e2id, e31id);\n * ede12.insert();\n * ede112.insert();\n * ede23.insert();\n * ede231.insert();\n * ```\n * Creates this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * e2 depends on both e1 and e11. e2 then drives e3 and e31.\n *\n * In an ElementDrivesElement dependency graph, the relationships are the \"edges\" and the Elements are the \"nodes\".\n * The following terms are used when referring to the elements (nodes) in a dependency graph:\n * * Inputs - The sources of all edges that point to the element. This includes all upstream elements that flow into the element.\n * * Outputs - The targets of all edges that point out of the element. This includes all downstream elements.\n *\n * # Subgraph Processing\n * When changes are made, only the part of the overall graph that is affected will be processed. So, for example,\n * suppose we have this graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n * If e1 changes, then the subgraph to be processed is equal to the full graph, as shown.\n *\n * If only e2 changes, then the subgraph to be processed is just:\n * ```\n * e2 --> e3\n * ```\n * If only e3 changes, then the subgraph consists of e3 by itself.\n *\n * Returning to the second example above, suppose we have this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * If e1 is changed, the affected subgraph is:\n * ```\n * e1 e3\n * \\ /\n * e2\n * \\\n * e31\n * ```\n * If e2 is changed, the affected subgraph is:\n * ```\n * e3\n * /\n * e2\n * \\\n * e31\n * ```\n * # Callbacks\n * Once the affected subgraph to process is found, it propagates changes through it by making callbacks.\n * Classes for both elements (nodes) and ElementDrivesElements relationships (edges) can receive callbacks.\n *\n * ## ElementDrivesElement Callbacks\n * The following callbacks are invoked on ElementDrivesElement relationship classes (edges):\n * * onRootChanged\n * * onDeletedDependency\n *\n * Note that these are static methods. Their default implementations do nothing.\n * To receive and act on these callbacks, a domain should define a subclass of ElementDrivesElement and use that to create relationships.\n * The subclass should then implement the callbacks that it would like to act on.\n *\n * A ElementDrivesElement subclass callback is expected to make changes to the output element only!\n *\n * ## Element Callbacks\n * The following callbacks are invoked on Element classes (nodes):\n * * Element.onBeforeOutputsHandled\n * * Element.onAllInputsHandled\n *\n * ## Order\n * Callbacks are invoked by BriefcaseDb.saveChanges.\n * They are invoked in dependency (topological) order: driving elements first, then driven elements.\n *\n * Each callback is invoked only once. No matter how many times a given element was changed during the transaction,\n * a callback such as ElementDrivesElement.onRootChanged will be invoked only once.\n * In the same way, no matter how many of its inputs were changed, a callback such as Element.onAllInputsHandled will be\n * invoked only once.\n *\n * For example, suppose we have a graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n *\n * Suppose that e1 is directly modified. No callbacks are made at that time.\n * Later, when BriefcaseDb.saveChanges is called, the following callbacks are made, in order:\n * 1. Element.onBeforeOutputsHandled e1\n * 1. ElementDrivesElement.onRootChanged e1->e2\n * 1. Element.onAllInputsHandled e2\n * 1. ElementDrivesElement.onRootChanged e2->e3\n * 1. Element.onAllInputsHandled e3\n *\n * Suppose that e3 is modified directly and BriefcaseDb.saveChanges is called.\n * Since no input to a relationship was changed, the sub-graph will be empty, and no callbacks will be made.\n *\n * Returning to the second example above, suppose we have this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * If e1 is changed and BriefcaseDb.saveChanges is called, the subgraph is:\n * ```\n * e1 e3\n * \\ /\n * e2\n * \\\n * e31\n * ```\n * The callbacks are:\n * 1. Element.onBeforeOutputsHandled e1\n * 1. ElementDrivesElement.onRootChanged e1->e2\n * 1. Element.onAllInputsHandled e2\n * 1. ElementDrivesElement.onRootChanged e2->e3\n * 1. Element.onAllInputsHandled e3\n * 1. ElementDrivesElement.onRootChanged e2->e31\n * 1. Element.onAllInputsHandled e31\n *\n * (The ElementDrivesElement.)\n *\n * #Errors\n * Circular dependencies are not permitted. If a cycle is detected, that is treated as a fatal error. All ElementDrivesElement relationships\n * involved in a cycle will have their status set to 1, indicating a failure.\n *\n * A callback may call txnManager.reportError to reject an invalid change. It can classify the error as fatal or just a warning.\n * A callback make set the status value of an ElementDrivesElement instance to 1 to indicate a processing failure in that edge.\n *\n * After BriefcaseDb.saveChanges is called, an app should check db.txns.validationErrors and db.txns.hasFatalError to find out if graph-evaluation failed.\n *\n * @beta\n */\nexport class ElementDrivesElement extends Relationship {\n public static override get className(): string { return \"ElementDrivesElement\"; }\n /** Relationship status\n * * 0 indicates no errors. Set after a successful evaluation.\n * * 1 indicates that this driving relationship could not be evaluated. The callback itself can set this to indicate that it failed to process the input changes. Also, it is set if the relationship is part of a circular dependency.\n * * 0x80 The app or callback can set this to indicate to not propagate changes through this relationship.\n */\n public status: number;\n /** Affects the order in which relationships are processed in the case where two relationships have the same output. */\n public priority: number;\n\n protected constructor(props: ElementDrivesElementProps, iModel: IModelDb) {\n super(props, iModel);\n this.status = props.status;\n this.priority = props.priority;\n }\n\n public static create<T extends ElementDrivesElement>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, priority: number = 0): T {\n const props: ElementDrivesElementProps = { sourceId, targetId, priority, status: 0, classFullName: this.classFullName };\n return iModel.relationships.createInstance(props) as T;\n }\n\n public override toJSON(): ElementDrivesElementProps {\n const props = super.toJSON() as ElementDrivesElementProps;\n props.status = this.status;\n props.priority = this.priority;\n return props;\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addElement(this.targetId);\n }\n}\n\n/** The third (and last) possible link-table relationship base class in an iModel.\n * Has no external use, but is included for completeness of the [Entity.collectReferenceIds]($backend)\n * implementations for link-table relationships. Generating the types of the source and target automatically would require\n * coupling this package with ecschema-metadata which we do not want to do.\n * @internal\n */\nexport class ModelSelectorRefersToModels extends Relationship {\n public static override get className(): string { return \"ModelSelectorRefersToModels\"; }\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addModel(this.targetId);\n }\n}\n\n/** Manages [[Relationship]]s.\n * @public\n */\nexport class Relationships {\n private _iModel: IModelDb;\n\n /** @internal */\n public constructor(iModel: IModelDb) { this._iModel = iModel; }\n\n /** Create a new instance of a Relationship.\n * @param props The properties of the new Relationship.\n * @throws [[IModelError]] if there is a problem creating the Relationship.\n */\n public createInstance(props: RelationshipProps): Relationship { return this._iModel.constructEntity<Relationship>(props); }\n\n /** Check classFullName to ensure it is a link table relationship class. */\n private checkRelationshipClass(classFullName: string) {\n if (!this._iModel[_nativeDb].isLinkTableRelationship(classFullName.replace(\".\", \":\"))) {\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Class '${classFullName}' must be a relationship class and it should be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.`);\n }\n }\n\n /** Insert a new relationship instance into the iModel. The relationship provided must be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.\n * @param props The properties of the new relationship.\n * @returns The Id of the newly inserted relationship.\n * @note The id property of the props object is set as a side effect of this function.\n * @deprecated Use EditTxn.insertRelationship instead.\n */\n public insertInstance(props: RelationshipProps): Id64String {\n return this._iModel[_implicitTxn].insertRelationship(props);\n }\n\n /** Update the properties of an existing relationship instance in the iModel.\n * @param props the properties of the relationship instance to update. Any properties that are not present will be left unchanged.\n * @deprecated Use EditTxn.updateRelationship instead.\n */\n public updateInstance(props: RelationshipProps): void {\n this._iModel[_implicitTxn].updateRelationship(props);\n }\n\n /** Delete an Relationship instance from this iModel.\n * @deprecated Use EditTxn.deleteRelationship instead.\n */\n public deleteInstance(props: RelationshipProps): void {\n this._iModel[_implicitTxn].deleteRelationship(props);\n }\n\n /** Delete multiple Relationship instances from this iModel.\n * @param props The properties of the relationship instances to delete.\n * @remarks This method handles bulk deletion of relationships and supports mixed collections containing instances from different relationship classes.\n * @deprecated Use EditTxn.deleteRelationships instead.\n */\n public deleteInstances(props: ReadonlyArray<RelationshipProps>): void {\n this._iModel[_implicitTxn].deleteRelationships(props);\n }\n\n /** Get the props of a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\n * @see tryGetInstanceProps\n */\n public getInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T {\n const relationshipProps = this.tryGetInstanceProps<T>(relClassFullName, criteria);\n if (undefined === relationshipProps) {\n throw new IModelError(IModelStatus.NotFound, \"Relationship not found\");\n }\n return relationshipProps;\n }\n\n /** Get the props of a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @returns The RelationshipProps or `undefined` if the relationship is not found.\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\n * @see getInstanceProps\n */\n public tryGetInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\n let props: T | undefined;\n if (typeof criteria === \"string\") {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE ecinstanceid=?`, (stmt: ECSqlStatement) => {\n stmt.bindId(1, criteria);\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE SourceECInstanceId=? AND TargetECInstanceId=?`, (stmt: ECSqlStatement) => {\n stmt.bindId(1, criteria.sourceId);\n stmt.bindId(2, criteria.targetId);\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\n });\n }\n if (undefined !== props) {\n props.classFullName = (props as any).className.replace(\".\", \":\");\n }\n return props;\n }\n\n /** Get a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\n * @see tryGetInstance\n */\n public getInstance<T extends Relationship>(relClassSqlName: string, criteria: Id64String | SourceAndTarget): T {\n return this._iModel.constructEntity<T>(this.getInstanceProps(relClassSqlName, criteria));\n }\n\n /** Get a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @returns The relationship or `undefined` if the relationship is not found.\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\n * @see getInstance\n */\n public tryGetInstance<T extends Relationship>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\n const relationshipProps = this.tryGetInstanceProps<RelationshipProps>(relClassFullName, criteria);\n return undefined !== relationshipProps ? this._iModel.constructEntity<T>(relationshipProps) : undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"Relationship.js","sourceRoot":"","sources":["../../src/Relationship.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA+E;AAC/E,oDAAyG;AAEzG,qCAAkC;AAClC,uCAAoC;AAEpC,gDAA6D;AAC7D,gEAA6D;AAgB7D;;GAEG;AACH,MAAa,YAAa,SAAQ,eAAM;IAC/B,MAAM,KAAc,SAAS,KAAa,OAAO,cAAc,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAa;IACrB,QAAQ,CAAa;IAErC,YAAsB,KAAwB,EAAE,MAAgB;QAC9D,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,QAAQ,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ACD,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YACxB,KAAK,CAAC,aAAa,GAAI,KAAa,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,WAAW,CAAyB,eAAuB,EAAE,QAAsC;QACxG,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAyB,gBAAwB,EAAE,QAAsC;QAC5G,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,CAAoB,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAClG,OAAO,SAAS,KAAK,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1G,CAAC;CACF;AArHD,sCAqHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Relationships\n */\n\nimport { DbResult, Id64, Id64String, IModelStatus } from \"@itwin/core-bentley\";\nimport { EntityReferenceSet, IModelError, RelationshipProps, SourceAndTarget } from \"@itwin/core-common\";\nimport { ECSqlStatement } from \"./ECSqlStatement\";\nimport { Entity } from \"./Entity\";\nimport { EditTxn } from \"./EditTxn\";\nimport { IModelDb } from \"./IModelDb\";\nimport { _implicitTxn, _nativeDb } from \"./internal/Symbols\";\nimport { RelationshipClass } from \"@itwin/ecschema-metadata\";\n\nexport type { SourceAndTarget, RelationshipProps } from \"@itwin/core-common\"; // for backwards compatibility\n\n/** Argument for relationship dependency callbacks.\n * @beta\n */\nexport interface OnDependencyArg {\n /** The iModel for the relationship affected by this method. */\n iModel: IModelDb;\n /** The ElementDrivesElement relationship instance affected by this method. */\n props: RelationshipProps;\n /** The transaction for indirect processing. */\n indirectEditTxn: EditTxn;\n}\n\n/** Base class for all link table ECRelationships\n * @public\n */\nexport class Relationship extends Entity {\n public static override get className(): string { return \"Relationship\"; }\n public readonly sourceId: Id64String;\n public readonly targetId: Id64String;\n\n protected constructor(props: RelationshipProps, iModel: IModelDb) {\n super(props, iModel);\n this.sourceId = Id64.fromJSON(props.sourceId);\n this.targetId = Id64.fromJSON(props.targetId);\n }\n\n public override toJSON(): RelationshipProps {\n const val = super.toJSON() as RelationshipProps;\n val.sourceId = this.sourceId;\n val.targetId = this.targetId;\n return val;\n }\n\n /** Query metadata for this relationship class from the iModel's schema. Returns cached metadata if available.*/\n public override async getMetaData(): Promise<RelationshipClass> {\n if (this._metadata && RelationshipClass.isRelationshipClass(this._metadata)) {\n return this._metadata;\n }\n\n const relationship = await this.iModel.schemaContext.getSchemaItem(this.schemaItemKey, RelationshipClass);\n if (relationship !== undefined) {\n this._metadata = relationship;\n return this._metadata;\n } else {\n throw new Error(`Cannot get metadata for ${this.classFullName}`);\n }\n }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when its input has changed or is the output of some upstream relationship whose input has changed.\n * This callback is invoked after the input element has been processed by upstream relationships.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.\n * @beta\n */\n public static onRootChangedArg(arg: OnDependencyArg): void {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n this.onRootChanged(arg.props, arg.iModel);\n }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when its input has changed or is the output of some upstream relationship whose input has changed.\n * This callback is invoked after the input element has been processed by upstream relationships.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.\n * @param _props The ElementDrivesElement relationship instance.\n * @param _iModel The iModel\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use onRootChangedArg instead.\n */\n public static onRootChanged(_props: RelationshipProps, _iModel: IModelDb): void { }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when the relationship instance has been deleted.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action.\n * @beta\n */\n public static onDeletedDependencyArg(arg: OnDependencyArg): void {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n this.onDeletedDependency(arg.props, arg.iModel);\n }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when the relationship instance has been deleted.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action.\n * @param _props The deleted ElementDrivesElement relationship instance.\n * @param _iModel The iModel\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use onDeletedDependencyArg instead.\n */\n public static onDeletedDependency(_props: RelationshipProps, _iModel: IModelDb): void { }\n\n /**\n * Insert this Relationship into the iModel using the supplied EditTxn.\n * @beta\n */\n public insert(txn: EditTxn): Id64String;\n /**\n * Insert this Relationship into the iModel.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use Relationship.insert(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public insert(): Id64String;\n public insert(txn?: EditTxn): Id64String { return this.id = (txn ?? this.iModel[_implicitTxn]).insertRelationship(this.toJSON()); }\n\n /**\n * Update this Relationship in the iModel using the supplied EditTxn.\n * @beta\n */\n public update(txn: EditTxn): void;\n /**\n * Update this Relationship in the iModel.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use Relationship.update(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public update(): void;\n public update(txn?: EditTxn) { (txn ?? this.iModel[_implicitTxn]).updateRelationship(this.toJSON()); }\n\n /**\n * Delete this Relationship from the iModel using the supplied EditTxn.\n * @beta\n */\n public delete(txn: EditTxn): void;\n /**\n * Delete this Relationship from the iModel.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use Relationship.delete(txn) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public delete(): void;\n public delete(txn?: EditTxn) { (txn ?? this.iModel[_implicitTxn]).deleteRelationship(this.toJSON()); }\n\n public static getInstance<T extends Relationship>(iModel: IModelDb, criteria: Id64String | SourceAndTarget): T { return iModel.relationships.getInstance(this.classFullName, criteria); }\n}\n\n/** A Relationship where one Element refers to another Element\n * @public\n */\nexport class ElementRefersToElements extends Relationship {\n public static override get className(): string { return \"ElementRefersToElements\"; }\n /** Create an instance of the Relationship.\n * @param iModel The iModel that will contain the relationship\n * @param sourceId The sourceId of the relationship, that is, the driver element\n * @param targetId The targetId of the relationship, that is, the driven element\n * @return an instance of the specified class.\n */\n public static create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): T {\n return iModel.relationships.createInstance({ sourceId, targetId, classFullName: this.classFullName }) as T;\n }\n\n /** Insert a new instance of the Relationship using an explicit transaction.\n * @param txn The EditTxn used to perform the insert.\n * @param sourceId The sourceId of the relationship, that is, the driver element\n * @param targetId The targetId of the relationship, that is, the driven element\n * @return The Id of the inserted Relationship.\n * @beta\n */\n public static insert(txn: EditTxn, sourceId: Id64String, targetId: Id64String): Id64String;\n /** Insert a new instance of the Relationship.\n * @param iModel The iModel that will contain the relationship.\n * @param sourceId The sourceId of the relationship, that is, the driver element.\n * @param targetId The targetId of the relationship, that is, the driven element.\n * @return The Id of the inserted Relationship.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use ElementRefersToElements.insert(txn, ...) instead, within an explicit EditTxn scope (or via withEditTxn). See EditTxn documentation for migration help.\n */\n public static insert(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): Id64String;\n public static insert(txnOrIModel: EditTxn | IModelDb, sourceId: Id64String, targetId: Id64String): Id64String {\n const txn = txnOrIModel instanceof EditTxn ? txnOrIModel : txnOrIModel[_implicitTxn];\n const relationship = this.create(txn.iModel, sourceId, targetId);\n return txn.insertRelationship(relationship.toJSON());\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addElement(this.targetId);\n }\n}\n\n/** Relates a [[DrawingGraphic]] to the [[Element]] that it represents\n * @public\n */\nexport class DrawingGraphicRepresentsElement extends ElementRefersToElements {\n public static override get className(): string { return \"DrawingGraphicRepresentsElement\"; }\n}\n\n/** Relates a [[GraphicalElement3d]] to the [[Element]] that it represents\n * @public\n */\nexport class GraphicalElement3dRepresentsElement extends ElementRefersToElements {\n public static override get className(): string { return \"GraphicalElement3dRepresentsElement\"; }\n}\n\n/** Relates a [[SynchronizationConfigLink]] to N [[ExternalSource]] instances.\n * Each relationship instance represents an external source processed by the synchronization configuration.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class SynchronizationConfigProcessesSources extends ElementRefersToElements {\n public static override get className(): string { return \"SynchronizationConfigProcessesSources\"; }\n}\n\n/** Relates a [[SynchronizationConfigLink]] to *root* [[ExternalSource]] instances.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class SynchronizationConfigSpecifiesRootSources extends SynchronizationConfigProcessesSources {\n public static override get className(): string { return \"SynchronizationConfigSpecifiesRootSources\"; }\n}\n\n/** Properties that are common to all types of link table ECRelationships\n * @public\n */\nexport interface ElementGroupsMembersProps extends RelationshipProps {\n memberPriority: number;\n}\n\n/** An ElementRefersToElements relationship where one Element *groups* a set of other Elements.\n * @public\n */\nexport class ElementGroupsMembers extends ElementRefersToElements {\n public static override get className(): string { return \"ElementGroupsMembers\"; }\n public memberPriority: number;\n\n constructor(props: ElementGroupsMembersProps, iModel: IModelDb) {\n super(props, iModel);\n this.memberPriority = props.memberPriority;\n }\n\n public static override create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, memberPriority: number = 0): T {\n const props: ElementGroupsMembersProps = { sourceId, targetId, memberPriority, classFullName: this.classFullName };\n return iModel.relationships.createInstance(props) as T;\n }\n}\n\n/** Relates a [[DefinitionGroup]] to its [[DefinitionElement]] members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.10\n * @public\n */\nexport class DefinitionGroupGroupsDefinitions extends ElementGroupsMembers {\n public static override get className(): string { return \"DefinitionGroupGroupsDefinitions\"; }\n}\n\n/** Represents group membership where the group Element (and its properties) impart information about the member Elements above mere membership.\n * Implies that properties of the group should be considered as properties of its members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.11\n * @public\n */\nexport class GroupImpartsToMembers extends ElementGroupsMembers {\n public static override get className(): string { return \"GroupImpartsToMembers\"; }\n}\n\n/** Relates an [[ExternalSourceGroup]] to its [[ExternalSource]] members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class ExternalSourceGroupGroupsSources extends ElementGroupsMembers {\n public static override get className(): string { return \"ExternalSourceGroupGroupsSources\"; }\n}\n\n/** Properties that are common to all types of ElementDrivesElements\n * @beta\n */\nexport interface ElementDrivesElementProps extends RelationshipProps {\n status: number;\n priority: number;\n}\n\n/** A Relationship indicating that one Element *drives* another Element.\n * An ElementDrivesElement relationship defines a one-way \"driving\" relationship from the source to the target.\n * When the source of an ElementDrivesElement relationship changes, the ElementDrivesElement itself can get a callback, and both the source and target elements can get callbacks.\n * By inserting ElementDrivesElement relationships, an app can create and store an acyclic directed graph of dependencies between elements.\n *\n * # Defining dependencies\n * Create an ElementDrivesElement relationship to specify that the source element drives the target element.\n * For example, to specify that element e1 drives element e2, create a relationship between them like this:\n * ```ts\n * const ede = ElementDrivesElement.create(iModel, e1id, e2id);\n * ede.insert();\n * ```\n * This creates a persistent relationship. The fact that e1 drives e2 is persisted in the iModel.\n *\n * # Defining dependency graphs\n * When you create multiple ElementDrivesElement relationships, you create a network of dependencies. The target of one may be the source of another.\n * A change in the content of an DgnElement can therefore trigger changes to many downstream elements.\n *\n * For example, to make element e1 drive element e2 and e2 drive another element, e3, create two relationships like this:\n * ```ts\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\n * ede12.insert();\n * ede23.insert();\n * ```\n * Those two relationships create this graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n * Where the \"-->\" is meant to represent a driving relationship.\n *\n * The order in which you create the relationships does not matter.\n * The graph indicates that e3 depends on e2 and e2 depends on e1.\n *\n * An ElementDrivesElement relationship is between one source element and one target element.\n * Many ElementDrivesElement relationships can point to a given element, and many can point out of it.\n * Thus, you can define many:many relationships.\n * For example:\n * ```ts\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\n * const ede112 = ElementDrivesElement.create(iModel, e11id, e2id);\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\n * const ede231 = ElementDrivesElement.create(iModel, e2id, e31id);\n * ede12.insert();\n * ede112.insert();\n * ede23.insert();\n * ede231.insert();\n * ```\n * Creates this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * e2 depends on both e1 and e11. e2 then drives e3 and e31.\n *\n * In an ElementDrivesElement dependency graph, the relationships are the \"edges\" and the Elements are the \"nodes\".\n * The following terms are used when referring to the elements (nodes) in a dependency graph:\n * * Inputs - The sources of all edges that point to the element. This includes all upstream elements that flow into the element.\n * * Outputs - The targets of all edges that point out of the element. This includes all downstream elements.\n *\n * # Subgraph Processing\n * When changes are made, only the part of the overall graph that is affected will be processed. So, for example,\n * suppose we have this graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n * If e1 changes, then the subgraph to be processed is equal to the full graph, as shown.\n *\n * If only e2 changes, then the subgraph to be processed is just:\n * ```\n * e2 --> e3\n * ```\n * If only e3 changes, then the subgraph consists of e3 by itself.\n *\n * Returning to the second example above, suppose we have this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * If e1 is changed, the affected subgraph is:\n * ```\n * e1 e3\n * \\ /\n * e2\n * \\\n * e31\n * ```\n * If e2 is changed, the affected subgraph is:\n * ```\n * e3\n * /\n * e2\n * \\\n * e31\n * ```\n * # Callbacks\n * Once the affected subgraph to process is found, it propagates changes through it by making callbacks.\n * Classes for both elements (nodes) and ElementDrivesElements relationships (edges) can receive callbacks.\n *\n * ## ElementDrivesElement Callbacks\n * The following callbacks are invoked on ElementDrivesElement relationship classes (edges):\n * * onRootChanged\n * * onDeletedDependency\n *\n * Note that these are static methods. Their default implementations do nothing.\n * To receive and act on these callbacks, a domain should define a subclass of ElementDrivesElement and use that to create relationships.\n * The subclass should then implement the callbacks that it would like to act on.\n *\n * A ElementDrivesElement subclass callback is expected to make changes to the output element only!\n *\n * ## Element Callbacks\n * The following callbacks are invoked on Element classes (nodes):\n * * Element.onBeforeOutputsHandled\n * * Element.onAllInputsHandled\n *\n * ## Order\n * Callbacks are invoked by BriefcaseDb.saveChanges.\n * They are invoked in dependency (topological) order: driving elements first, then driven elements.\n *\n * Each callback is invoked only once. No matter how many times a given element was changed during the transaction,\n * a callback such as ElementDrivesElement.onRootChanged will be invoked only once.\n * In the same way, no matter how many of its inputs were changed, a callback such as Element.onAllInputsHandled will be\n * invoked only once.\n *\n * For example, suppose we have a graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n *\n * Suppose that e1 is directly modified. No callbacks are made at that time.\n * Later, when BriefcaseDb.saveChanges is called, the following callbacks are made, in order:\n * 1. Element.onBeforeOutputsHandled e1\n * 1. ElementDrivesElement.onRootChanged e1->e2\n * 1. Element.onAllInputsHandled e2\n * 1. ElementDrivesElement.onRootChanged e2->e3\n * 1. Element.onAllInputsHandled e3\n *\n * Suppose that e3 is modified directly and BriefcaseDb.saveChanges is called.\n * Since no input to a relationship was changed, the sub-graph will be empty, and no callbacks will be made.\n *\n * Returning to the second example above, suppose we have this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * If e1 is changed and BriefcaseDb.saveChanges is called, the subgraph is:\n * ```\n * e1 e3\n * \\ /\n * e2\n * \\\n * e31\n * ```\n * The callbacks are:\n * 1. Element.onBeforeOutputsHandled e1\n * 1. ElementDrivesElement.onRootChanged e1->e2\n * 1. Element.onAllInputsHandled e2\n * 1. ElementDrivesElement.onRootChanged e2->e3\n * 1. Element.onAllInputsHandled e3\n * 1. ElementDrivesElement.onRootChanged e2->e31\n * 1. Element.onAllInputsHandled e31\n *\n * (The ElementDrivesElement.)\n *\n * #Errors\n * Circular dependencies are not permitted. If a cycle is detected, that is treated as a fatal error. All ElementDrivesElement relationships\n * involved in a cycle will have their status set to 1, indicating a failure.\n *\n * A callback may call txnManager.reportError to reject an invalid change. It can classify the error as fatal or just a warning.\n * A callback make set the status value of an ElementDrivesElement instance to 1 to indicate a processing failure in that edge.\n *\n * After BriefcaseDb.saveChanges is called, an app should check db.txns.validationErrors and db.txns.hasFatalError to find out if graph-evaluation failed.\n *\n * @beta\n */\nexport class ElementDrivesElement extends Relationship {\n public static override get className(): string { return \"ElementDrivesElement\"; }\n /** Relationship status\n * * 0 indicates no errors. Set after a successful evaluation.\n * * 1 indicates that this driving relationship could not be evaluated. The callback itself can set this to indicate that it failed to process the input changes. Also, it is set if the relationship is part of a circular dependency.\n * * 0x80 The app or callback can set this to indicate to not propagate changes through this relationship.\n */\n public status: number;\n /** Affects the order in which relationships are processed in the case where two relationships have the same output. */\n public priority: number;\n\n protected constructor(props: ElementDrivesElementProps, iModel: IModelDb) {\n super(props, iModel);\n this.status = props.status;\n this.priority = props.priority;\n }\n\n public static create<T extends ElementDrivesElement>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, priority: number = 0): T {\n const props: ElementDrivesElementProps = { sourceId, targetId, priority, status: 0, classFullName: this.classFullName };\n return iModel.relationships.createInstance(props) as T;\n }\n\n public override toJSON(): ElementDrivesElementProps {\n const props = super.toJSON() as ElementDrivesElementProps;\n props.status = this.status;\n props.priority = this.priority;\n return props;\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addElement(this.targetId);\n }\n}\n\n/** The third (and last) possible link-table relationship base class in an iModel.\n * Has no external use, but is included for completeness of the [Entity.collectReferenceIds]($backend)\n * implementations for link-table relationships. Generating the types of the source and target automatically would require\n * coupling this package with ecschema-metadata which we do not want to do.\n * @internal\n */\nexport class ModelSelectorRefersToModels extends Relationship {\n public static override get className(): string { return \"ModelSelectorRefersToModels\"; }\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addModel(this.targetId);\n }\n}\n\n/** Manages [[Relationship]]s.\n * @public\n */\nexport class Relationships {\n private _iModel: IModelDb;\n\n /** @internal */\n public constructor(iModel: IModelDb) { this._iModel = iModel; }\n\n /** Create a new instance of a Relationship.\n * @param props The properties of the new Relationship.\n * @throws [[IModelError]] if there is a problem creating the Relationship.\n */\n public createInstance(props: RelationshipProps): Relationship { return this._iModel.constructEntity<Relationship>(props); }\n\n /** Check classFullName to ensure it is a link table relationship class. */\n private checkRelationshipClass(classFullName: string) {\n if (!this._iModel[_nativeDb].isLinkTableRelationship(classFullName.replace(\".\", \":\"))) {\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Class '${classFullName}' must be a relationship class and it should be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.`);\n }\n }\n\n /** Insert a new relationship instance into the iModel. The relationship provided must be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.\n * @param props The properties of the new relationship.\n * @returns The Id of the newly inserted relationship.\n * @note The id property of the props object is set as a side effect of this function.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.insertRelationship instead.\n */\n public insertInstance(props: RelationshipProps): Id64String {\n return this._iModel[_implicitTxn].insertRelationship(props);\n }\n\n /** Update the properties of an existing relationship instance in the iModel.\n * @param props the properties of the relationship instance to update. Any properties that are not present will be left unchanged.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.updateRelationship instead.\n */\n public updateInstance(props: RelationshipProps): void {\n this._iModel[_implicitTxn].updateRelationship(props);\n }\n\n /** Delete an Relationship instance from this iModel.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.deleteRelationship instead.\n */\n public deleteInstance(props: RelationshipProps): void {\n this._iModel[_implicitTxn].deleteRelationship(props);\n }\n\n /** Delete multiple Relationship instances from this iModel.\n * @param props The properties of the relationship instances to delete.\n * @remarks This method handles bulk deletion of relationships and supports mixed collections containing instances from different relationship classes.\n * @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use EditTxn.deleteRelationships instead.\n */\n public deleteInstances(props: ReadonlyArray<RelationshipProps>): void {\n this._iModel[_implicitTxn].deleteRelationships(props);\n }\n\n /** Get the props of a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\n * @see tryGetInstanceProps\n */\n public getInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T {\n const relationshipProps = this.tryGetInstanceProps<T>(relClassFullName, criteria);\n if (undefined === relationshipProps) {\n throw new IModelError(IModelStatus.NotFound, \"Relationship not found\");\n }\n return relationshipProps;\n }\n\n /** Get the props of a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @returns The RelationshipProps or `undefined` if the relationship is not found.\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\n * @see getInstanceProps\n */\n public tryGetInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\n let props: T | undefined;\n if (typeof criteria === \"string\") {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE ecinstanceid=?`, (stmt: ECSqlStatement) => {\n stmt.bindId(1, criteria);\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE SourceECInstanceId=? AND TargetECInstanceId=?`, (stmt: ECSqlStatement) => {\n stmt.bindId(1, criteria.sourceId);\n stmt.bindId(2, criteria.targetId);\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\n });\n }\n if (undefined !== props) {\n props.classFullName = (props as any).className.replace(\".\", \":\");\n }\n return props;\n }\n\n /** Get a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\n * @see tryGetInstance\n */\n public getInstance<T extends Relationship>(relClassSqlName: string, criteria: Id64String | SourceAndTarget): T {\n return this._iModel.constructEntity<T>(this.getInstanceProps(relClassSqlName, criteria));\n }\n\n /** Get a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @returns The relationship or `undefined` if the relationship is not found.\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\n * @see getInstance\n */\n public tryGetInstance<T extends Relationship>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\n const relationshipProps = this.tryGetInstanceProps<RelationshipProps>(relClassFullName, criteria);\n return undefined !== relationshipProps ? this._iModel.constructEntity<T>(relationshipProps) : undefined;\n }\n}\n"]}
@@ -65,7 +65,7 @@ export declare class SheetIndex extends InformationReferenceElement {
65
65
  * @throws [[IModelError]] if there is a problem inserting the SheetIndex
66
66
  */
67
67
  static insert(txn: EditTxn, modelId: Id64String, name: string): Id64String;
68
- /** @deprecated Use SheetIndex.insert(txn, ...) instead. */
68
+ /** @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use SheetIndex.insert(txn, ...) instead. */
69
69
  static insert(iModelDb: IModelDb, modelId: Id64String, name: string): Id64String;
70
70
  }
71
71
  /** The base class for all elements that can participate in a [[SheetIndex]] hierarchy.
@@ -101,7 +101,7 @@ export declare class SheetIndexFolder extends SheetIndexEntry {
101
101
  * @throws [[IModelError]] if unable to create the element.
102
102
  */
103
103
  static insert(txn: EditTxn, arg: Omit<SheetIndexEntryCreateArgs, "iModelDb">): Id64String;
104
- /** @deprecated Use SheetIndexFolder.insert(txn, ...) instead. */
104
+ /** @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use SheetIndexFolder.insert(txn, ...) instead. */
105
105
  static insert(arg: SheetIndexEntryCreateArgs): Id64String;
106
106
  }
107
107
  /** A node within one [[SheetIndex]] that incorporates another [[SheetIndex]] as a sub-tree.
@@ -124,7 +124,7 @@ export declare class SheetIndexReference extends SheetIndexEntry {
124
124
  * @throws [[IModelError]] if unable to create the element.
125
125
  */
126
126
  static insert(txn: EditTxn, arg: Omit<SheetIndexReferenceCreateArgs, "iModelDb">): Id64String;
127
- /** @deprecated Use SheetIndexReference.insert(txn, ...) instead. */
127
+ /** @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use SheetIndexReference.insert(txn, ...) instead. */
128
128
  static insert(arg: SheetIndexReferenceCreateArgs): Id64String;
129
129
  /** @alpha */
130
130
  protected collectReferenceIds(referenceIds: EntityReferenceSet): void;
@@ -149,7 +149,7 @@ export declare class SheetReference extends SheetIndexEntry {
149
149
  * @throws [[IModelError]] if unable to create the element.
150
150
  */
151
151
  static insert(txn: EditTxn, arg: Omit<SheetReferenceCreateArgs, "iModelDb">): Id64String;
152
- /** @deprecated Use SheetReference.insert(txn, ...) instead. */
152
+ /** @deprecated in 5.1.9 - will not be removed until after 2027-05-04. Use SheetReference.insert(txn, ...) instead. */
153
153
  static insert(arg: SheetReferenceCreateArgs): Id64String;
154
154
  /** @alpha */
155
155
  protected collectReferenceIds(referenceIds: EntityReferenceSet): void;