@itwin/core-backend 3.4.0-dev.9 → 3.4.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 (270) hide show
  1. package/CHANGELOG.md +97 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -17
  3. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
  4. package/lib/cjs/AliCloudStorageService.js +71 -68
  5. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  6. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  7. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  8. package/lib/cjs/BackendHubAccess.js +41 -41
  9. package/lib/cjs/BackendHubAccess.js.map +1 -1
  10. package/lib/cjs/BackendLoggerCategory.d.ts +91 -87
  11. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  12. package/lib/cjs/BackendLoggerCategory.js +99 -95
  13. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  14. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  15. package/lib/cjs/BisCoreSchema.js +60 -60
  16. package/lib/cjs/BisCoreSchema.js.map +1 -1
  17. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  18. package/lib/cjs/BriefcaseManager.js +405 -405
  19. package/lib/cjs/BriefcaseManager.js.map +1 -1
  20. package/lib/cjs/Category.d.ts +153 -153
  21. package/lib/cjs/Category.js +243 -243
  22. package/lib/cjs/Category.js.map +1 -1
  23. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  24. package/lib/cjs/ChangeSummaryManager.js +445 -445
  25. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  26. package/lib/cjs/ChangedElementsDb.d.ts +99 -98
  27. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  28. package/lib/cjs/ChangedElementsDb.js +165 -165
  29. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  30. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  31. package/lib/cjs/ChangedElementsManager.js +88 -88
  32. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  33. package/lib/cjs/CheckpointManager.d.ts +120 -122
  34. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  35. package/lib/cjs/CheckpointManager.js +343 -354
  36. package/lib/cjs/CheckpointManager.js.map +1 -1
  37. package/lib/cjs/ClassRegistry.d.ts +72 -71
  38. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  39. package/lib/cjs/ClassRegistry.js +243 -213
  40. package/lib/cjs/ClassRegistry.js.map +1 -1
  41. package/lib/cjs/CloudSqlite.d.ts +350 -0
  42. package/lib/cjs/CloudSqlite.d.ts.map +1 -0
  43. package/lib/cjs/CloudSqlite.js +152 -0
  44. package/lib/cjs/CloudSqlite.js.map +1 -0
  45. package/lib/cjs/CloudStorageBackend.d.ts +58 -46
  46. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
  47. package/lib/cjs/CloudStorageBackend.js +173 -164
  48. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  49. package/lib/cjs/CodeService.d.ts +397 -0
  50. package/lib/cjs/CodeService.d.ts.map +1 -0
  51. package/lib/cjs/CodeService.js +64 -0
  52. package/lib/cjs/CodeService.js.map +1 -0
  53. package/lib/cjs/CodeSpecs.d.ts +50 -50
  54. package/lib/cjs/CodeSpecs.js +112 -112
  55. package/lib/cjs/CodeSpecs.js.map +1 -1
  56. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  57. package/lib/cjs/ConcurrentQuery.js +30 -30
  58. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  59. package/lib/cjs/CustomViewState3dCreator.d.ts +32 -32
  60. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  61. package/lib/cjs/CustomViewState3dCreator.js +113 -98
  62. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  63. package/lib/cjs/DevTools.d.ts +71 -71
  64. package/lib/cjs/DevTools.d.ts.map +1 -1
  65. package/lib/cjs/DevTools.js +154 -154
  66. package/lib/cjs/DevTools.js.map +1 -1
  67. package/lib/cjs/DisplayStyle.d.ts +106 -106
  68. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  69. package/lib/cjs/DisplayStyle.js +256 -256
  70. package/lib/cjs/DisplayStyle.js.map +1 -1
  71. package/lib/cjs/ECDb.d.ts +191 -191
  72. package/lib/cjs/ECDb.js +350 -350
  73. package/lib/cjs/ECDb.js.map +1 -1
  74. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  75. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  76. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  77. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  78. package/lib/cjs/ECSqlStatement.js +791 -791
  79. package/lib/cjs/ECSqlStatement.js.map +1 -1
  80. package/lib/cjs/Element.d.ts +1120 -1109
  81. package/lib/cjs/Element.d.ts.map +1 -1
  82. package/lib/cjs/Element.js +1438 -1417
  83. package/lib/cjs/Element.js.map +1 -1
  84. package/lib/cjs/ElementAspect.d.ts +158 -156
  85. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  86. package/lib/cjs/ElementAspect.js +186 -178
  87. package/lib/cjs/ElementAspect.js.map +1 -1
  88. package/lib/cjs/ElementGraphics.d.ts +9 -9
  89. package/lib/cjs/ElementGraphics.js +41 -41
  90. package/lib/cjs/ElementGraphics.js.map +1 -1
  91. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  92. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  93. package/lib/cjs/ElementTreeWalker.js +409 -409
  94. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  95. package/lib/cjs/Entity.d.ts +106 -76
  96. package/lib/cjs/Entity.d.ts.map +1 -1
  97. package/lib/cjs/Entity.js +134 -82
  98. package/lib/cjs/Entity.js.map +1 -1
  99. package/lib/cjs/EntityReferences.d.ts +46 -0
  100. package/lib/cjs/EntityReferences.d.ts.map +1 -0
  101. package/lib/cjs/EntityReferences.js +92 -0
  102. package/lib/cjs/EntityReferences.js.map +1 -0
  103. package/lib/cjs/ExportGraphics.d.ts +317 -317
  104. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  105. package/lib/cjs/ExportGraphics.js +208 -208
  106. package/lib/cjs/ExportGraphics.js.map +1 -1
  107. package/lib/cjs/ExternalSource.d.ts +96 -94
  108. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  109. package/lib/cjs/ExternalSource.js +131 -125
  110. package/lib/cjs/ExternalSource.js.map +1 -1
  111. package/lib/cjs/GeoCoordConfig.d.ts +19 -13
  112. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  113. package/lib/cjs/GeoCoordConfig.js +82 -73
  114. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  115. package/lib/cjs/GeometrySummary.d.ts +4 -4
  116. package/lib/cjs/GeometrySummary.js +380 -380
  117. package/lib/cjs/GeometrySummary.js.map +1 -1
  118. package/lib/cjs/HubMock.d.ts +93 -93
  119. package/lib/cjs/HubMock.d.ts.map +1 -1
  120. package/lib/cjs/HubMock.js +190 -190
  121. package/lib/cjs/HubMock.js.map +1 -1
  122. package/lib/cjs/IModelCloneContext.d.ts +89 -85
  123. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  124. package/lib/cjs/IModelCloneContext.js +159 -150
  125. package/lib/cjs/IModelCloneContext.js.map +1 -1
  126. package/lib/cjs/IModelDb.d.ts +1164 -1151
  127. package/lib/cjs/IModelDb.d.ts.map +1 -1
  128. package/lib/cjs/IModelDb.js +2324 -2286
  129. package/lib/cjs/IModelDb.js.map +1 -1
  130. package/lib/cjs/IModelHost.d.ts +361 -347
  131. package/lib/cjs/IModelHost.d.ts.map +1 -1
  132. package/lib/cjs/IModelHost.js +489 -455
  133. package/lib/cjs/IModelHost.js.map +1 -1
  134. package/lib/cjs/IModelJsFs.d.ts +62 -62
  135. package/lib/cjs/IModelJsFs.d.ts.map +1 -1
  136. package/lib/cjs/IModelJsFs.js +140 -140
  137. package/lib/cjs/IModelJsFs.js.map +1 -1
  138. package/lib/cjs/IpcHost.d.ts +98 -98
  139. package/lib/cjs/IpcHost.js +234 -234
  140. package/lib/cjs/IpcHost.js.map +1 -1
  141. package/lib/cjs/LineStyle.d.ts +311 -311
  142. package/lib/cjs/LineStyle.js +295 -295
  143. package/lib/cjs/LineStyle.js.map +1 -1
  144. package/lib/cjs/LocalHub.d.ts +162 -162
  145. package/lib/cjs/LocalHub.js +587 -587
  146. package/lib/cjs/LocalHub.js.map +1 -1
  147. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  148. package/lib/cjs/LocalhostIpcHost.js +81 -81
  149. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  150. package/lib/cjs/Material.d.ts +103 -101
  151. package/lib/cjs/Material.d.ts.map +1 -1
  152. package/lib/cjs/Material.js +147 -145
  153. package/lib/cjs/Material.js.map +1 -1
  154. package/lib/cjs/Model.d.ts +388 -386
  155. package/lib/cjs/Model.d.ts.map +1 -1
  156. package/lib/cjs/Model.js +479 -468
  157. package/lib/cjs/Model.js.map +1 -1
  158. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  159. package/lib/cjs/NativeAppStorage.js +202 -202
  160. package/lib/cjs/NativeAppStorage.js.map +1 -1
  161. package/lib/cjs/NativeHost.d.ts +52 -52
  162. package/lib/cjs/NativeHost.js +168 -168
  163. package/lib/cjs/NativeHost.js.map +1 -1
  164. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  165. package/lib/cjs/NavigationRelationship.js +225 -225
  166. package/lib/cjs/NavigationRelationship.js.map +1 -1
  167. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  168. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  169. package/lib/cjs/PromiseMemoizer.js +101 -95
  170. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  171. package/lib/cjs/PropertyStore.d.ts +133 -0
  172. package/lib/cjs/PropertyStore.d.ts.map +1 -0
  173. package/lib/cjs/PropertyStore.js +12 -0
  174. package/lib/cjs/PropertyStore.js.map +1 -0
  175. package/lib/cjs/Relationship.d.ts +416 -400
  176. package/lib/cjs/Relationship.d.ts.map +1 -1
  177. package/lib/cjs/Relationship.js +494 -465
  178. package/lib/cjs/Relationship.js.map +1 -1
  179. package/lib/cjs/RpcBackend.d.ts +28 -28
  180. package/lib/cjs/RpcBackend.js +126 -126
  181. package/lib/cjs/RpcBackend.js.map +1 -1
  182. package/lib/cjs/SQLiteDb.d.ts +219 -173
  183. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  184. package/lib/cjs/SQLiteDb.js +214 -211
  185. package/lib/cjs/SQLiteDb.js.map +1 -1
  186. package/lib/cjs/Schema.d.ts +55 -55
  187. package/lib/cjs/Schema.js +83 -83
  188. package/lib/cjs/Schema.js.map +1 -1
  189. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  190. package/lib/cjs/ServerBasedLocks.js +168 -168
  191. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  192. package/lib/cjs/SqliteStatement.d.ts +283 -271
  193. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  194. package/lib/cjs/SqliteStatement.js +448 -426
  195. package/lib/cjs/SqliteStatement.js.map +1 -1
  196. package/lib/cjs/Texture.d.ts +58 -58
  197. package/lib/cjs/Texture.js +82 -82
  198. package/lib/cjs/Texture.js.map +1 -1
  199. package/lib/cjs/TileStorage.d.ts +19 -0
  200. package/lib/cjs/TileStorage.d.ts.map +1 -0
  201. package/lib/cjs/TileStorage.js +91 -0
  202. package/lib/cjs/TileStorage.js.map +1 -0
  203. package/lib/cjs/TxnManager.d.ts +202 -202
  204. package/lib/cjs/TxnManager.d.ts.map +1 -1
  205. package/lib/cjs/TxnManager.js +356 -353
  206. package/lib/cjs/TxnManager.js.map +1 -1
  207. package/lib/cjs/ViewDefinition.d.ts +439 -435
  208. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  209. package/lib/cjs/ViewDefinition.js +646 -629
  210. package/lib/cjs/ViewDefinition.js.map +1 -1
  211. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  212. package/lib/cjs/ViewStateHydrator.js +103 -103
  213. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  214. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  215. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  216. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -21
  217. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  218. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  219. package/lib/cjs/core-backend.d.ts +183 -175
  220. package/lib/cjs/core-backend.d.ts.map +1 -1
  221. package/lib/cjs/core-backend.js +203 -195
  222. package/lib/cjs/core-backend.js.map +1 -1
  223. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  224. package/lib/cjs/domains/FunctionalElements.js +145 -145
  225. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  226. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  227. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  228. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  229. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  230. package/lib/cjs/domains/GenericElements.js +263 -263
  231. package/lib/cjs/domains/GenericElements.js.map +1 -1
  232. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  233. package/lib/cjs/domains/GenericSchema.js +28 -28
  234. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  235. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  236. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  237. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  238. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +45 -45
  239. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +262 -262
  240. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  241. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -20
  242. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  243. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +204 -195
  244. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  245. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  246. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  247. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -165
  248. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  249. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  250. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  251. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  252. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  253. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  254. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  255. package/lib/cjs/workspace/Settings.d.ts +186 -186
  256. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  257. package/lib/cjs/workspace/Settings.js +155 -152
  258. package/lib/cjs/workspace/Settings.js.map +1 -1
  259. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  260. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  261. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  262. package/lib/cjs/workspace/Workspace.d.ts +414 -401
  263. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  264. package/lib/cjs/workspace/Workspace.js +543 -534
  265. package/lib/cjs/workspace/Workspace.js.map +1 -1
  266. package/package.json +20 -20
  267. package/lib/cjs/IModelSchemaLoader.d.ts +0 -26
  268. package/lib/cjs/IModelSchemaLoader.d.ts.map +0 -1
  269. package/lib/cjs/IModelSchemaLoader.js +0 -122
  270. package/lib/cjs/IModelSchemaLoader.js.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AAE,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;AAvGD,sCAuGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Relationships\r\n */\r\n\r\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { IModelError, IModelStatus, RelationshipProps, SourceAndTarget } from \"@itwin/core-common\";\r\nimport { ECSqlStatement } from \"./ECSqlStatement\";\r\nimport { Entity } from \"./Entity\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\nexport type { SourceAndTarget, RelationshipProps } from \"@itwin/core-common\"; // for backwards compatibility\r\n\r\n/** Base class for all link table ECRelationships\r\n * @public\r\n */\r\nexport class Relationship extends Entity {\r\n /** @internal */\r\n public static override get className(): string { return \"Relationship\"; }\r\n public readonly sourceId: Id64String;\r\n public readonly targetId: Id64String;\r\n\r\n /** @internal */\r\n constructor(props: RelationshipProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.sourceId = Id64.fromJSON(props.sourceId);\r\n this.targetId = Id64.fromJSON(props.targetId);\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): RelationshipProps {\r\n const val = super.toJSON() as RelationshipProps;\r\n val.sourceId = this.sourceId;\r\n val.targetId = this.targetId;\r\n return val;\r\n }\r\n\r\n /**\r\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.\r\n * This callback is invoked after the input element has been processed by upstream relationships.\r\n * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.\r\n * @param _props The ElementDrivesElement relationship instance.\r\n * @param _iModel The iModel\r\n */\r\n public static onRootChanged(_props: RelationshipProps, _iModel: IModelDb): void { }\r\n\r\n /**\r\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when the relationship instance has been deleted.\r\n * A subclass of ElementDrivesElement can re-implement this static method to take some action.\r\n * @param _props The deleted ElementDrivesElement relationship instance.\r\n * @param _iModel The iModel\r\n */\r\n public static onDeletedDependency(_props: RelationshipProps, _iModel: IModelDb): void { }\r\n\r\n /** Insert this Relationship into the iModel. */\r\n public insert(): Id64String { return this.id = this.iModel.relationships.insertInstance(this.toJSON()); }\r\n /** Update this Relationship in the iModel. */\r\n public update() { this.iModel.relationships.updateInstance(this.toJSON()); }\r\n /** Delete this Relationship from the iModel. */\r\n public delete() { this.iModel.relationships.deleteInstance(this.toJSON()); }\r\n\r\n public static getInstance<T extends Relationship>(iModel: IModelDb, criteria: Id64String | SourceAndTarget): T { return iModel.relationships.getInstance(this.classFullName, criteria); }\r\n}\r\n\r\n/** A Relationship where one Element refers to another Element\r\n * @public\r\n */\r\nexport class ElementRefersToElements extends Relationship {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementRefersToElements\"; }\r\n /** Create an instance of the Relationship.\r\n * @param iModel The iModel that will contain the relationship\r\n * @param sourceId The sourceId of the relationship, that is, the driver element\r\n * @param targetId The targetId of the relationship, that is, the driven element\r\n * @return an instance of the specified class.\r\n */\r\n public static create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): T {\r\n return iModel.relationships.createInstance({ sourceId, targetId, classFullName: this.classFullName }) as T;\r\n }\r\n /** Insert a new instance of the Relationship.\r\n * @param iModel The iModel that will contain the relationship\r\n * @param sourceId The sourceId of the relationship, that is, the driver element\r\n * @param targetId The targetId of the relationship, that is, the driven element\r\n * @return The Id of the inserted Relationship.\r\n */\r\n public static insert<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): Id64String {\r\n const relationship: T = this.create(iModel, sourceId, targetId);\r\n return iModel.relationships.insertInstance(relationship.toJSON());\r\n }\r\n}\r\n\r\n/** Relates a [[DrawingGraphic]] to the [[Element]] that it represents\r\n * @public\r\n */\r\nexport class DrawingGraphicRepresentsElement extends ElementRefersToElements {\r\n /** @internal */\r\n public static override get className(): string { return \"DrawingGraphicRepresentsElement\"; }\r\n}\r\n\r\n/** Relates a [[GraphicalElement3d]] to the [[Element]] that it represents\r\n * @public\r\n */\r\nexport class GraphicalElement3dRepresentsElement extends ElementRefersToElements {\r\n /** @internal */\r\n public static override get className(): string { return \"GraphicalElement3dRepresentsElement\"; }\r\n}\r\n\r\n/** Relates a [[SynchronizationConfigLink]] to N [[ExternalSource]] instances.\r\n * Each relationship instance represents an external source processed by the synchronization configuration.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\r\n * @beta\r\n */\r\nexport class SynchronizationConfigProcessesSources extends ElementRefersToElements {\r\n /** @internal */\r\n public static override get className(): string { return \"SynchronizationConfigProcessesSources\"; }\r\n}\r\n\r\n/** Relates a [[SynchronizationConfigLink]] to *root* [[ExternalSource]] instances.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\r\n * @beta\r\n */\r\nexport class SynchronizationConfigSpecifiesRootSources extends SynchronizationConfigProcessesSources {\r\n /** @internal */\r\n public static override get className(): string { return \"SynchronizationConfigSpecifiesRootSources\"; }\r\n}\r\n\r\n/** Properties that are common to all types of link table ECRelationships\r\n * @public\r\n */\r\nexport interface ElementGroupsMembersProps extends RelationshipProps {\r\n memberPriority: number;\r\n}\r\n\r\n/** An ElementRefersToElements relationship where one Element *groups* a set of other Elements.\r\n * @public\r\n */\r\nexport class ElementGroupsMembers extends ElementRefersToElements {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementGroupsMembers\"; }\r\n public memberPriority: number;\r\n\r\n constructor(props: ElementGroupsMembersProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.memberPriority = props.memberPriority;\r\n }\r\n\r\n public static override create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, memberPriority: number = 0): T {\r\n const props: ElementGroupsMembersProps = { sourceId, targetId, memberPriority, classFullName: this.classFullName };\r\n return iModel.relationships.createInstance(props) as T;\r\n }\r\n}\r\n\r\n/** Relates a [[DefinitionGroup]] to its [[DefinitionElement]] members.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.10\r\n * @public\r\n */\r\nexport class DefinitionGroupGroupsDefinitions extends ElementGroupsMembers {\r\n /** @internal */\r\n public static override get className(): string { return \"DefinitionGroupGroupsDefinitions\"; }\r\n}\r\n\r\n/** Represents group membership where the group Element (and its properties) impart information about the member Elements above mere membership.\r\n * Implies that properties of the group should be considered as properties of its members.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.11\r\n * @public\r\n */\r\nexport class GroupImpartsToMembers extends ElementGroupsMembers {\r\n /** @internal */\r\n public static override get className(): string { return \"GroupImpartsToMembers\"; }\r\n}\r\n\r\n/** Relates an [[ExternalSourceGroup]] to its [[ExternalSource]] members.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\r\n * @beta\r\n */\r\nexport class ExternalSourceGroupGroupsSources extends ElementGroupsMembers {\r\n /** @internal */\r\n public static override get className(): string { return \"ExternalSourceGroupGroupsSources\"; }\r\n}\r\n\r\n/** Properties that are common to all types of ElementDrivesElements\r\n * @beta\r\n */\r\nexport interface ElementDrivesElementProps extends RelationshipProps {\r\n status: number;\r\n priority: number;\r\n}\r\n\r\n/** A Relationship indicating that one Element *drives* another Element.\r\n * An ElementDrivesElement relationship defines a one-way \"driving\" relationship from the source to the target.\r\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.\r\n * By inserting ElementDrivesElement relationships, an app can create and store an acyclic directed graph of dependencies between elements.\r\n *\r\n * # Defining dependencies\r\n * Create an ElementDrivesElement relationship to specify that the source element drives the target element.\r\n * For example, to specify that element e1 drives element e2, create a relationship between them like this:\r\n * ```ts\r\n * const ede = ElementDrivesElement.create(iModel, e1id, e2id);\r\n * ede.insert();\r\n * ```\r\n * This creates a persistent relationship. The fact that e1 drives e2 is persisted in the iModel.\r\n *\r\n * # Defining dependency graphs\r\n * When you create multiple ElementDrivesElement relationships, you create a network of dependencies. The target of one may be the source of another.\r\n * A change in the content of an DgnElement can therefore trigger changes to many downstream elements.\r\n *\r\n * For example, to make element e1 drive element e2 and e2 drive another element, e3, create two relationships like this:\r\n * ```ts\r\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\r\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\r\n * ede12.insert();\r\n * ede23.insert();\r\n * ```\r\n * Those two relationships create this graph:\r\n * ```\r\n * e1 --> e2 --> e3\r\n * ```\r\n * Where the \"-->\" is meant to represent a driving relationship.\r\n *\r\n * The order in which you create the relationships does not matter.\r\n * The graph indicates that e3 depends on e2 and e2 depends on e1.\r\n *\r\n * An ElementDrivesElement relationship is between one source element and one target element.\r\n * Many ElementDrivesElement relationships can point to a given element, and many can point out of it.\r\n * Thus, you can define many:many relationships.\r\n * For example:\r\n * ```ts\r\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\r\n * const ede112 = ElementDrivesElement.create(iModel, e11id, e2id);\r\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\r\n * const ede231 = ElementDrivesElement.create(iModel, e2id, e31id);\r\n * ede12.insert();\r\n * ede112.insert();\r\n * ede23.insert();\r\n * ede231.insert();\r\n * ```\r\n * Creates this graph:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * / \\\r\n * e11 e31\r\n * ```\r\n * e2 depends on both e1 and e11. e2 then drives e3 and e31.\r\n *\r\n * In an ElementDrivesElement dependency graph, the relationships are the \"edges\" and the Elements are the \"nodes\".\r\n * The following terms are used when referring to the elements (nodes) in a dependency graph:\r\n * * Inputs - The sources of all edges that point to the element. This includes all upstream elements that flow into the element.\r\n * * Outputs - The targets of all edges that point out of the element. This includes all downstream elements.\r\n *\r\n * # Subgraph Processing\r\n * When changes are made, only the part of the overall graph that is affected will be processed. So, for example,\r\n * suppose we have this graph:\r\n * ```\r\n * e1 --> e2 --> e3\r\n * ```\r\n * If e1 changes, then the subgraph to be processed is equal to the full graph, as shown.\r\n *\r\n * If only e2 changes, then the subgraph to be processed is just:\r\n * ```\r\n * e2 --> e3\r\n * ```\r\n * If only e3 changes, then the subgraph consists of e3 by itself.\r\n *\r\n * Returning to the second example above, suppose we have this graph:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * / \\\r\n * e11 e31\r\n * ```\r\n * If e1 is changed, the affected subgraph is:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * \\\r\n * e31\r\n * ```\r\n * If e2 is changed, the affected subgraph is:\r\n * ```\r\n * e3\r\n * /\r\n * e2\r\n * \\\r\n * e31\r\n * ```\r\n * # Callbacks\r\n * Once the affected subgraph to process is found, it propagates changes through it by making callbacks.\r\n * Classes for both elements (nodes) and ElementDrivesElements relationships (edges) can receive callbacks.\r\n *\r\n * ## ElementDrivesElement Callbacks\r\n * The following callbacks are invoked on ElementDrivesElement relationship classes (edges):\r\n * * onRootChanged\r\n * * onDeletedDependency\r\n *\r\n * Note that these are static methods. Their default implementations do nothing.\r\n * To receive and act on these callbacks, a domain should define a subclass of ElementDrivesElement and use that to create relationships.\r\n * The subclass should then implement the callbacks that it would like to act on.\r\n *\r\n * A ElementDrivesElement subclass callback is expected to make changes to the output element only!\r\n *\r\n * ## Element Callbacks\r\n * The following callbacks are invoked on Element classes (nodes):\r\n * * Element.onBeforeOutputsHandled\r\n * * Element.onAllInputsHandled\r\n *\r\n * ## Order\r\n * Callbacks are invoked by BriefcaseDb.saveChanges.\r\n * They are invoked in dependency (topological) order: driving elements first, then driven elements.\r\n *\r\n * Each callback is invoked only once. No matter how many times a given element was changed during the transaction,\r\n * a callback such as ElementDrivesElement.onRootChanged will be invoked only once.\r\n * In the same way, no matter how many of its inputs were changed, a callback such as Element.onAllInputsHandled will be\r\n * invoked only once.\r\n *\r\n * For example, suppose we have a graph:\r\n * ```\r\n * e1 --> e2 --> e3\r\n * ```\r\n *\r\n * Suppose that e1 is directly modified. No callbacks are made at that time.\r\n * Later, when BriefcaseDb.saveChanges is called, the following callbacks are made, in order:\r\n * 1. Element.onBeforeOutputsHandled e1\r\n * 1. ElementDrivesElement.onRootChanged e1->e2\r\n * 1. Element.onAllInputsHandled e2\r\n * 1. ElementDrivesElement.onRootChanged e2->e3\r\n * 1. Element.onAllInputsHandled e3\r\n *\r\n * Suppose that e3 is modified directly and BriefcaseDb.saveChanges is called.\r\n * Since no input to a relationship was changed, the sub-graph will be empty, and no callbacks will be made.\r\n *\r\n * Returning to the second example above, suppose we have this graph:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * / \\\r\n * e11 e31\r\n * ```\r\n * If e1 is changed and BriefcaseDb.saveChanges is called, the subgraph is:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * \\\r\n * e31\r\n * ```\r\n * The callbacks are:\r\n * 1. Element.onBeforeOutputsHandled e1\r\n * 1. ElementDrivesElement.onRootChanged e1->e2\r\n * 1. Element.onAllInputsHandled e2\r\n * 1. ElementDrivesElement.onRootChanged e2->e3\r\n * 1. Element.onAllInputsHandled e3\r\n * 1. ElementDrivesElement.onRootChanged e2->e31\r\n * 1. Element.onAllInputsHandled e31\r\n *\r\n * (The ElementDrivesElement.)\r\n *\r\n * #Errors\r\n * Circular dependencies are not permitted. If a cycle is detected, that is treated as a fatal error. All ElementDrivesElement relationships\r\n * involved in a cycle will have their status set to 1, indicating a failure.\r\n *\r\n * A callback may call txnManager.reportError to reject an invalid change. It can classify the error as fatal or just a warning.\r\n * A callback make set the status value of an ElementDrivesElement instance to 1 to indicate a processing failure in that edge.\r\n *\r\n * After BriefcaseDb.saveChanges is called, an app should check db.txns.validationErrors and db.txns.hasFatalError to find out if graph-evaluation failed.\r\n *\r\n * @beta\r\n */\r\nexport class ElementDrivesElement extends Relationship {\r\n /** @internal */\r\n public static override get className(): string { return \"ElementDrivesElement\"; }\r\n /** Relationship status\r\n * * 0 indicates no errors. Set after a successful evaluation.\r\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.\r\n * * 0x80 The app or callback can set this to indicate to not propagate changes through this relationship.\r\n */\r\n public status: number;\r\n /** Affects the order in which relationships are processed in the case where two relationships have the same output. */\r\n public priority: number;\r\n\r\n /** @internal */\r\n constructor(props: ElementDrivesElementProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.status = props.status;\r\n this.priority = props.priority;\r\n }\r\n\r\n public static create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, priority: number = 0): T {\r\n const props: ElementDrivesElementProps = { sourceId, targetId, priority, status: 0, classFullName: this.classFullName };\r\n return iModel.relationships.createInstance(props) as T;\r\n }\r\n\r\n public override toJSON(): ElementDrivesElementProps {\r\n const props = super.toJSON() as ElementDrivesElementProps;\r\n props.status = this.status;\r\n props.priority = this.priority;\r\n return props;\r\n }\r\n}\r\n\r\n/** Manages [[Relationship]]s.\r\n * @public\r\n */\r\nexport class Relationships {\r\n private _iModel: IModelDb;\r\n\r\n /** @internal */\r\n constructor(iModel: IModelDb) { this._iModel = iModel; }\r\n\r\n /** Create a new instance of a Relationship.\r\n * @param props The properties of the new Relationship.\r\n * @throws [[IModelError]] if there is a problem creating the Relationship.\r\n */\r\n public createInstance(props: RelationshipProps): Relationship { return this._iModel.constructEntity<Relationship>(props); }\r\n\r\n /** Check classFullName to ensure it is a link table relationship class. */\r\n private checkRelationshipClass(classFullName: string) {\r\n if (!this._iModel.nativeDb.isLinkTableRelationship(classFullName.replace(\".\", \":\"))) {\r\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.`);\r\n }\r\n }\r\n\r\n /** Insert a new relationship instance into the iModel. The relationship provided must be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.\r\n * @param props The properties of the new relationship.\r\n * @returns The Id of the newly inserted relationship.\r\n * @note The id property of the props object is set as a side effect of this function.\r\n */\r\n public insertInstance(props: RelationshipProps): Id64String {\r\n this.checkRelationshipClass(props.classFullName);\r\n return props.id = this._iModel.nativeDb.insertLinkTableRelationship(props);\r\n }\r\n\r\n /** Update the properties of an existing relationship instance in the iModel.\r\n * @param props the properties of the relationship instance to update. Any properties that are not present will be left unchanged.\r\n */\r\n public updateInstance(props: RelationshipProps): void {\r\n this._iModel.nativeDb.updateLinkTableRelationship(props);\r\n }\r\n\r\n /** Delete an Relationship instance from this iModel. */\r\n public deleteInstance(props: RelationshipProps): void {\r\n this._iModel.nativeDb.deleteLinkTableRelationship(props);\r\n }\r\n\r\n /** Get the props of a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\r\n * @see tryGetInstanceProps\r\n */\r\n public getInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T {\r\n const relationshipProps = this.tryGetInstanceProps<T>(relClassFullName, criteria);\r\n if (undefined === relationshipProps) {\r\n throw new IModelError(IModelStatus.NotFound, \"Relationship not found\");\r\n }\r\n return relationshipProps;\r\n }\r\n\r\n /** Get the props of a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @returns The RelationshipProps or `undefined` if the relationship is not found.\r\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\r\n * @see getInstanceProps\r\n */\r\n public tryGetInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\r\n let props: T | undefined;\r\n if (typeof criteria === \"string\") {\r\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE ecinstanceid=?`, (stmt: ECSqlStatement) => {\r\n stmt.bindId(1, criteria);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\r\n });\r\n } else {\r\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE SourceECInstanceId=? AND TargetECInstanceId=?`, (stmt: ECSqlStatement) => {\r\n stmt.bindId(1, criteria.sourceId);\r\n stmt.bindId(2, criteria.targetId);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\r\n });\r\n }\r\n if (undefined !== props) {\r\n props.classFullName = (props as any).className.replace(\".\", \":\");\r\n }\r\n return props;\r\n }\r\n\r\n /** Get a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\r\n * @see tryGetInstance\r\n */\r\n public getInstance<T extends Relationship>(relClassSqlName: string, criteria: Id64String | SourceAndTarget): T {\r\n return this._iModel.constructEntity<T>(this.getInstanceProps(relClassSqlName, criteria));\r\n }\r\n\r\n /** Get a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @returns The relationship or `undefined` if the relationship is not found.\r\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\r\n * @see getInstance\r\n */\r\n public tryGetInstance<T extends Relationship>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\r\n const relationshipProps = this.tryGetInstanceProps<RelationshipProps>(relClassFullName, criteria);\r\n return undefined !== relationshipProps ? this._iMod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------\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 } from \"@itwin/core-bentley\";\nimport { EntityReferenceSet, IModelError, IModelStatus, RelationshipProps, SourceAndTarget } from \"@itwin/core-common\";\nimport { ECSqlStatement } from \"./ECSqlStatement\";\nimport { Entity } from \"./Entity\";\nimport { IModelDb } from \"./IModelDb\";\n\nexport type { SourceAndTarget, RelationshipProps } from \"@itwin/core-common\"; // for backwards compatibility\n\n/** Base class for all link table ECRelationships\n * @public\n */\nexport class Relationship extends Entity {\n /** @internal */\n public static override get className(): string { return \"Relationship\"; }\n public readonly sourceId: Id64String;\n public readonly targetId: Id64String;\n\n /** @internal */\n 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 /** @internal */\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 /**\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 */\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 * @param _props The deleted ElementDrivesElement relationship instance.\n * @param _iModel The iModel\n */\n public static onDeletedDependency(_props: RelationshipProps, _iModel: IModelDb): void { }\n\n /** Insert this Relationship into the iModel. */\n public insert(): Id64String { return this.id = this.iModel.relationships.insertInstance(this.toJSON()); }\n /** Update this Relationship in the iModel. */\n public update() { this.iModel.relationships.updateInstance(this.toJSON()); }\n /** Delete this Relationship from the iModel. */\n public delete() { this.iModel.relationships.deleteInstance(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 /** @internal */\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 /** 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 */\n public static insert<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): Id64String {\n const relationship: T = this.create(iModel, sourceId, targetId);\n return iModel.relationships.insertInstance(relationship.toJSON());\n }\n\n /** @internal */\n public override collectReferenceConcreteIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceConcreteIds(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 /** @internal */\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 /** @internal */\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 /** @internal */\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 /** @internal */\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 /** @internal */\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 /** @internal */\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 /** @internal */\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 /** @internal */\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 /** @internal */\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 /** @internal */\n 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 ElementRefersToElements>(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 /** @internal */\n public override collectReferenceConcreteIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceConcreteIds(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.collectReferenceConcreteIds]($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 /** @internal */\n public static override get className(): string { return \"ModelSelectorRefersToModels\"; }\n /** @internal */\n protected override collectReferenceConcreteIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceConcreteIds(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 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 */\n public insertInstance(props: RelationshipProps): Id64String {\n this.checkRelationshipClass(props.classFullName);\n return props.id = this._iModel.nativeDb.insertLinkTableRelationship(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 */\n public updateInstance(props: RelationshipProps): void {\n this._iModel.nativeDb.updateLinkTableRelationship(props);\n }\n\n /** Delete an Relationship instance from this iModel. */\n public deleteInstance(props: RelationshipProps): void {\n this._iModel.nativeDb.deleteLinkTableRelationship(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 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 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,29 +1,29 @@
1
- /** @packageDocumentation
2
- * @module RpcInterface
3
- */
4
- import { RpcActivity } from "@itwin/core-common";
5
- /**
6
- * Utility for tracing Rpc activity processing. When multiple Rpc requests are being processed asynchronously, this
7
- * class can be used to correlate the current calltrace with the originating RpcActivity. This is used for automatic appending
8
- * of RpcActivity to log messages emitted during Rpc processing. It may also be used to retrieve the user accessToken
9
- * from the RpcActivity.
10
- * @public
11
- */
12
- export declare class RpcTrace {
13
- private static _storage;
14
- /** Get the [RpcActivity]($common) for the currently executing async, or `undefined` if there is no
15
- * RpcActivity in the current call stack.
16
- * */
17
- static get currentActivity(): RpcActivity | undefined;
18
- /** Get the [RpcActivity]($common) for the currently executing async. Asserts that the RpcActivity
19
- * exists in the current call stack.
20
- * */
21
- static get expectCurrentActivity(): RpcActivity;
22
- /** Start the processing of an RpcActivity. */
23
- static run<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T>;
24
- /** Start the processing of an RpcActivity inside an OpenTelemetry span */
25
- static runWithSpan<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T>;
26
- }
27
- /** @internal */
28
- export declare function initializeRpcBackend(enableOpenTelemetry?: boolean): void;
1
+ /** @packageDocumentation
2
+ * @module RpcInterface
3
+ */
4
+ import { RpcActivity } from "@itwin/core-common";
5
+ /**
6
+ * Utility for tracing Rpc activity processing. When multiple Rpc requests are being processed asynchronously, this
7
+ * class can be used to correlate the current calltrace with the originating RpcActivity. This is used for automatic appending
8
+ * of RpcActivity to log messages emitted during Rpc processing. It may also be used to retrieve the user accessToken
9
+ * from the RpcActivity.
10
+ * @public
11
+ */
12
+ export declare class RpcTrace {
13
+ private static _storage;
14
+ /** Get the [RpcActivity]($common) for the currently executing async, or `undefined` if there is no
15
+ * RpcActivity in the current call stack.
16
+ * */
17
+ static get currentActivity(): RpcActivity | undefined;
18
+ /** Get the [RpcActivity]($common) for the currently executing async. Asserts that the RpcActivity
19
+ * exists in the current call stack.
20
+ * */
21
+ static get expectCurrentActivity(): RpcActivity;
22
+ /** Start the processing of an RpcActivity. */
23
+ static run<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T>;
24
+ /** Start the processing of an RpcActivity inside an OpenTelemetry span */
25
+ static runWithSpan<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T>;
26
+ }
27
+ /** @internal */
28
+ export declare function initializeRpcBackend(enableOpenTelemetry?: boolean): void;
29
29
  //# sourceMappingURL=RpcBackend.d.ts.map
@@ -1,127 +1,127 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module RpcInterface
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.initializeRpcBackend = exports.RpcTrace = void 0;
11
- // cspell:ignore calltrace
12
- const core_bentley_1 = require("@itwin/core-bentley");
13
- const core_common_1 = require("@itwin/core-common");
14
- const async_hooks_1 = require("async_hooks");
15
- const FormData = require("form-data");
16
- const multiparty = require("multiparty");
17
- const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
18
- const IModelHost_1 = require("./IModelHost");
19
- /**
20
- * Utility for tracing Rpc activity processing. When multiple Rpc requests are being processed asynchronously, this
21
- * class can be used to correlate the current calltrace with the originating RpcActivity. This is used for automatic appending
22
- * of RpcActivity to log messages emitted during Rpc processing. It may also be used to retrieve the user accessToken
23
- * from the RpcActivity.
24
- * @public
25
- */
26
- class RpcTrace {
27
- /** Get the [RpcActivity]($common) for the currently executing async, or `undefined` if there is no
28
- * RpcActivity in the current call stack.
29
- * */
30
- static get currentActivity() {
31
- return RpcTrace._storage.getStore();
32
- }
33
- /** Get the [RpcActivity]($common) for the currently executing async. Asserts that the RpcActivity
34
- * exists in the current call stack.
35
- * */
36
- static get expectCurrentActivity() {
37
- (0, core_bentley_1.assert)(undefined !== RpcTrace.currentActivity);
38
- return RpcTrace.currentActivity;
39
- }
40
- /** Start the processing of an RpcActivity. */
41
- static async run(activity, fn) {
42
- return RpcTrace._storage.run(activity, fn);
43
- }
44
- /** Start the processing of an RpcActivity inside an OpenTelemetry span */
45
- static async runWithSpan(activity, fn) {
46
- var _a;
47
- return core_bentley_1.Tracing.withSpan((_a = activity.rpcMethod) !== null && _a !== void 0 ? _a : "unknown RPC method", async () => RpcTrace.run(activity, fn), {
48
- attributes: { ...core_common_1.RpcInvocation.sanitizeForLog(activity) },
49
- kind: core_bentley_1.SpanKind.SERVER,
50
- });
51
- }
52
- }
53
- exports.RpcTrace = RpcTrace;
54
- RpcTrace._storage = new async_hooks_1.AsyncLocalStorage();
55
- let initialized = false;
56
- /** @internal */
57
- function initializeRpcBackend(enableOpenTelemetry = false) {
58
- if (initialized)
59
- return;
60
- initialized = true;
61
- core_common_1.RpcInvocation.runActivity = RpcTrace.run; // redirect the invocation processing to the tracer
62
- if (enableOpenTelemetry) {
63
- try {
64
- // eslint-disable-next-line @typescript-eslint/no-var-requires
65
- const api = require("@opentelemetry/api");
66
- const tracer = api.trace.getTracer("@itwin/core-backend", IModelHost_1.IModelHost.backendVersion);
67
- core_bentley_1.Tracing.enableOpenTelemetry(tracer, api);
68
- core_common_1.RpcInvocation.runActivity = RpcTrace.runWithSpan; // wrap invocation in an OpenTelemetry span in addition to RpcTrace
69
- }
70
- catch (e) {
71
- // eslint-disable-next-line @typescript-eslint/naming-convention
72
- core_bentley_1.Logger.logError(BackendLoggerCategory_1.BackendLoggerCategory.IModelHost, "Failed to initialize OpenTelemetry");
73
- core_bentley_1.Logger.logException(BackendLoggerCategory_1.BackendLoggerCategory.IModelHost, e);
74
- }
75
- }
76
- // set up static logger metadata to include current RpcActivity information for logs during rpc processing
77
- core_bentley_1.Logger.staticMetaData.set("rpc", () => core_common_1.RpcInvocation.sanitizeForLog(RpcTrace.currentActivity));
78
- core_common_1.RpcMultipart.createStream = (value) => {
79
- const form = new FormData();
80
- core_common_1.RpcMultipart.writeValueToForm(form, value);
81
- // Type information for FormData is lying. It actually extends Stream but not Readable, although it appears to work
82
- // fine for now.
83
- return form;
84
- };
85
- core_common_1.RpcMultipart.parseRequest = async (req) => {
86
- return new Promise((resolve, reject) => {
87
- const form = new multiparty.Form({ maxFieldsSize: Infinity });
88
- form.on("error", (err) => {
89
- reject(err);
90
- });
91
- const value = core_common_1.RpcSerializedValue.create();
92
- const data = {};
93
- form.on("part", (part) => {
94
- part.on("data", (chunk) => {
95
- if (part.name === "objects") {
96
- value.objects += chunk.toString();
97
- }
98
- else if (Buffer.isBuffer(chunk)) {
99
- if (!data[part.name]) {
100
- data[part.name] = { size: 0, chunks: [] };
101
- }
102
- data[part.name].size += chunk.byteLength;
103
- data[part.name].chunks.push(chunk);
104
- }
105
- else {
106
- throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "Unknown input.");
107
- }
108
- });
109
- });
110
- form.on("close", () => {
111
- let i = 0;
112
- for (;;) {
113
- const part = data[`data-${i}`];
114
- if (!part) {
115
- break;
116
- }
117
- value.data.push(Buffer.concat(part.chunks, part.size));
118
- ++i;
119
- }
120
- resolve(value);
121
- });
122
- form.parse(req);
123
- });
124
- };
125
- }
126
- exports.initializeRpcBackend = initializeRpcBackend;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module RpcInterface
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.initializeRpcBackend = exports.RpcTrace = void 0;
11
+ // cspell:ignore calltrace
12
+ const core_bentley_1 = require("@itwin/core-bentley");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ const async_hooks_1 = require("async_hooks");
15
+ const FormData = require("form-data");
16
+ const multiparty = require("multiparty");
17
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
18
+ const IModelHost_1 = require("./IModelHost");
19
+ /**
20
+ * Utility for tracing Rpc activity processing. When multiple Rpc requests are being processed asynchronously, this
21
+ * class can be used to correlate the current calltrace with the originating RpcActivity. This is used for automatic appending
22
+ * of RpcActivity to log messages emitted during Rpc processing. It may also be used to retrieve the user accessToken
23
+ * from the RpcActivity.
24
+ * @public
25
+ */
26
+ class RpcTrace {
27
+ /** Get the [RpcActivity]($common) for the currently executing async, or `undefined` if there is no
28
+ * RpcActivity in the current call stack.
29
+ * */
30
+ static get currentActivity() {
31
+ return RpcTrace._storage.getStore();
32
+ }
33
+ /** Get the [RpcActivity]($common) for the currently executing async. Asserts that the RpcActivity
34
+ * exists in the current call stack.
35
+ * */
36
+ static get expectCurrentActivity() {
37
+ (0, core_bentley_1.assert)(undefined !== RpcTrace.currentActivity);
38
+ return RpcTrace.currentActivity;
39
+ }
40
+ /** Start the processing of an RpcActivity. */
41
+ static async run(activity, fn) {
42
+ return RpcTrace._storage.run(activity, fn);
43
+ }
44
+ /** Start the processing of an RpcActivity inside an OpenTelemetry span */
45
+ static async runWithSpan(activity, fn) {
46
+ var _a;
47
+ return core_bentley_1.Tracing.withSpan((_a = activity.rpcMethod) !== null && _a !== void 0 ? _a : "unknown RPC method", async () => RpcTrace.run(activity, fn), {
48
+ attributes: { ...core_common_1.RpcInvocation.sanitizeForLog(activity) },
49
+ kind: core_bentley_1.SpanKind.SERVER,
50
+ });
51
+ }
52
+ }
53
+ exports.RpcTrace = RpcTrace;
54
+ RpcTrace._storage = new async_hooks_1.AsyncLocalStorage();
55
+ let initialized = false;
56
+ /** @internal */
57
+ function initializeRpcBackend(enableOpenTelemetry = false) {
58
+ if (initialized)
59
+ return;
60
+ initialized = true;
61
+ core_common_1.RpcInvocation.runActivity = RpcTrace.run; // redirect the invocation processing to the tracer
62
+ if (enableOpenTelemetry) {
63
+ try {
64
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
65
+ const api = require("@opentelemetry/api");
66
+ const tracer = api.trace.getTracer("@itwin/core-backend", IModelHost_1.IModelHost.backendVersion);
67
+ core_bentley_1.Tracing.enableOpenTelemetry(tracer, api);
68
+ core_common_1.RpcInvocation.runActivity = RpcTrace.runWithSpan; // wrap invocation in an OpenTelemetry span in addition to RpcTrace
69
+ }
70
+ catch (e) {
71
+ // eslint-disable-next-line @typescript-eslint/naming-convention
72
+ core_bentley_1.Logger.logError(BackendLoggerCategory_1.BackendLoggerCategory.IModelHost, "Failed to initialize OpenTelemetry");
73
+ core_bentley_1.Logger.logException(BackendLoggerCategory_1.BackendLoggerCategory.IModelHost, e);
74
+ }
75
+ }
76
+ // set up static logger metadata to include current RpcActivity information for logs during rpc processing
77
+ core_bentley_1.Logger.staticMetaData.set("rpc", () => core_common_1.RpcInvocation.sanitizeForLog(RpcTrace.currentActivity));
78
+ core_common_1.RpcMultipart.createStream = (value) => {
79
+ const form = new FormData();
80
+ core_common_1.RpcMultipart.writeValueToForm(form, value);
81
+ // Type information for FormData is lying. It actually extends Stream but not Readable, although it appears to work
82
+ // fine for now.
83
+ return form;
84
+ };
85
+ core_common_1.RpcMultipart.parseRequest = async (req) => {
86
+ return new Promise((resolve, reject) => {
87
+ const form = new multiparty.Form({ maxFieldsSize: Infinity });
88
+ form.on("error", (err) => {
89
+ reject(err);
90
+ });
91
+ const value = core_common_1.RpcSerializedValue.create();
92
+ const data = {};
93
+ form.on("part", (part) => {
94
+ part.on("data", (chunk) => {
95
+ if (part.name === "objects") {
96
+ value.objects += chunk.toString();
97
+ }
98
+ else if (Buffer.isBuffer(chunk)) {
99
+ if (!data[part.name]) {
100
+ data[part.name] = { size: 0, chunks: [] };
101
+ }
102
+ data[part.name].size += chunk.byteLength;
103
+ data[part.name].chunks.push(chunk);
104
+ }
105
+ else {
106
+ throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "Unknown input.");
107
+ }
108
+ });
109
+ });
110
+ form.on("close", () => {
111
+ let i = 0;
112
+ for (;;) {
113
+ const part = data[`data-${i}`];
114
+ if (!part) {
115
+ break;
116
+ }
117
+ value.data.push(Buffer.concat(part.chunks, part.size));
118
+ ++i;
119
+ }
120
+ resolve(value);
121
+ });
122
+ form.parse(req);
123
+ });
124
+ };
125
+ }
126
+ exports.initializeRpcBackend = initializeRpcBackend;
127
127
  //# sourceMappingURL=RpcBackend.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RpcBackend.js","sourceRoot":"","sources":["../../src/RpcBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,0BAA0B;AAE1B,sDAAwE;AACxE,oDAAiJ;AACjJ,6CAAgD;AAChD,sCAAsC;AACtC,yCAAyC;AACzC,mEAAgE;AAChE,6CAA0C;AAE1C;;;;;;GAMG;AACH,MAAa,QAAQ;IAGnB;;SAEK;IACE,MAAM,KAAK,eAAe;QAC/B,OAAO,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAA6B,CAAC;IACjE,CAAC;IAED;;SAEK;IACE,MAAM,KAAK,qBAAqB;QACrC,IAAA,qBAAM,EAAC,SAAS,KAAK,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC,eAAe,CAAC;IAClC,CAAC;IAED,8CAA8C;IACvC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAI,QAAqB,EAAE,EAAoB;QACpE,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,0EAA0E;IACnE,MAAM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AAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;yBAC3C;wBAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC;wBACzC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBACpC;yBAAM;wBACL,MAAM,IAAI,yBAAW,CAAC,2BAAa,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;qBAC9D;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACpB,IAAI,CAAC,GAAG,CAAC,CAAC;gBACV,SAAU;oBACR,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;oBAC/B,IAAI,CAAC,IAAI,EAAE;wBACT,MAAM;qBACP;oBAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;oBACvD,EAAE,CAAC,CAAC;iBACL;gBAED,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA9ED,oDA8EC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\n// cspell:ignore calltrace\r\n\r\nimport { assert, Logger, SpanKind, Tracing } from \"@itwin/core-bentley\";\r\nimport { BentleyStatus, HttpServerRequest, IModelError, RpcActivity, RpcInvocation, RpcMultipart, RpcSerializedValue } from \"@itwin/core-common\";\r\nimport { AsyncLocalStorage } from \"async_hooks\";\r\nimport * as FormData from \"form-data\";\r\nimport * as multiparty from \"multiparty\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n/**\r\n * Utility for tracing Rpc activity processing. When multiple Rpc requests are being processed asynchronously, this\r\n * class can be used to correlate the current calltrace with the originating RpcActivity. This is used for automatic appending\r\n * of RpcActivity to log messages emitted during Rpc processing. It may also be used to retrieve the user accessToken\r\n * from the RpcActivity.\r\n * @public\r\n */\r\nexport class RpcTrace {\r\n private static _storage = new AsyncLocalStorage();\r\n\r\n /** Get the [RpcActivity]($common) for the currently executing async, or `undefined` if there is no\r\n * RpcActivity in the current call stack.\r\n * */\r\n public static get currentActivity(): RpcActivity | undefined {\r\n return RpcTrace._storage.getStore() as RpcActivity | undefined;\r\n }\r\n\r\n /** Get the [RpcActivity]($common) for the currently executing async. Asserts that the RpcActivity\r\n * exists in the current call stack.\r\n * */\r\n public static get expectCurrentActivity(): RpcActivity {\r\n assert(undefined !== RpcTrace.currentActivity);\r\n return RpcTrace.currentActivity;\r\n }\r\n\r\n /** Start the processing of an RpcActivity. */\r\n public static async run<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T> {\r\n return RpcTrace._storage.run(activity, fn);\r\n }\r\n\r\n /** Start the processing of an RpcActivity inside an OpenTelemetry span */\r\n public static async runWithSpan<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T> {\r\n return Tracing.withSpan(activity.rpcMethod ?? \"unknown RPC method\", async () => RpcTrace.run(activity, fn), {\r\n attributes: { ...RpcInvocation.sanitizeForLog(activity) },\r\n kind: SpanKind.SERVER,\r\n });\r\n }\r\n}\r\n\r\nlet initialized = false;\r\n/** @internal */\r\nexport function initializeRpcBackend(enableOpenTelemetry: boolean = false) {\r\n if (initialized)\r\n return;\r\n\r\n initialized = true;\r\n\r\n RpcInvocation.runActivity = RpcTrace.run; // redirect the invocation processing to the tracer\r\n\r\n if (enableOpenTelemetry) {\r\n try {\r\n // eslint-disable-next-line @typescript-eslint/no-var-requires\r\n const api = require(\"@opentelemetry/api\");\r\n const tracer = api.trace.getTracer(\"@itwin/core-backend\", IModelHost.backendVersion);\r\n Tracing.enableOpenTelemetry(tracer, api);\r\n RpcInvocation.runActivity = RpcTrace.runWithSpan; // wrap invocation in an OpenTelemetry span in addition to RpcTrace\r\n } catch (e) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n Logger.logError(BackendLoggerCategory.IModelHost, \"Failed to initialize OpenTelemetry\");\r\n Logger.logException(BackendLoggerCategory.IModelHost, e);\r\n }\r\n }\r\n\r\n // set up static logger metadata to include current RpcActivity information for logs during rpc processing\r\n Logger.staticMetaData.set(\"rpc\", () => RpcInvocation.sanitizeForLog(RpcTrace.currentActivity));\r\n\r\n RpcMultipart.createStream = (value: RpcSerializedValue) => {\r\n const form = new FormData();\r\n RpcMultipart.writeValueToForm(form, value);\r\n // Type information for FormData is lying. It actually extends Stream but not Readable, although it appears to work\r\n // fine for now.\r\n return form;\r\n };\r\n\r\n RpcMultipart.parseRequest = async (req: HttpServerRequest) => {\r\n return new Promise<RpcSerializedValue>((resolve, reject) => {\r\n const form = new multiparty.Form({ maxFieldsSize: Infinity });\r\n form.on(\"error\", (err) => {\r\n reject(err);\r\n });\r\n\r\n const value = RpcSerializedValue.create();\r\n const data: { [index: string]: { size: number, chunks: Buffer[] } } = {};\r\n\r\n form.on(\"part\", (part: multiparty.Part) => {\r\n part.on(\"data\", (chunk: string | Buffer) => {\r\n if (part.name === \"objects\") {\r\n value.objects += chunk.toString();\r\n } else if (Buffer.isBuffer(chunk)) {\r\n if (!data[part.name]) {\r\n data[part.name] = { size: 0, chunks: [] };\r\n }\r\n\r\n data[part.name].size += chunk.byteLength;\r\n data[part.name].chunks.push(chunk);\r\n } else {\r\n throw new IModelError(BentleyStatus.ERROR, \"Unknown input.\");\r\n }\r\n });\r\n });\r\n\r\n form.on(\"close\", () => {\r\n let i = 0;\r\n for (; ;) {\r\n const part = data[`data-${i}`];\r\n if (!part) {\r\n break;\r\n }\r\n\r\n value.data.push(Buffer.concat(part.chunks, part.size));\r\n ++i;\r\n }\r\n\r\n resolve(value);\r\n });\r\n\r\n form.parse(req);\r\n });\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"RpcBackend.js","sourceRoot":"","sources":["../../src/RpcBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,0BAA0B;AAE1B,sDAAwE;AACxE,oDAAiJ;AACjJ,6CAAgD;AAChD,sCAAsC;AACtC,yCAAyC;AACzC,mEAAgE;AAChE,6CAA0C;AAE1C;;;;;;GAMG;AACH,MAAa,QAAQ;IAGnB;;SAEK;IACE,MAAM,KAAK,eAAe;QAC/B,OAAO,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAA6B,CAAC;IACjE,CAAC;IAED;;SAEK;IACE,MAAM,KAAK,qBAAqB;QACrC,IAAA,qBAAM,EAAC,SAAS,KAAK,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC,eAAe,CAAC;IAClC,CAAC;IAED,8CAA8C;IACvC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAI,QAAqB,EAAE,EAAoB;QACpE,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,0EAA0E;IACnE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAI,QAAqB,EAAE,EAAoB;;QAC5E,OAAO,sBAAO,CAAC,QAAQ,CAAC,MAAA,QAAQ,CAAC,SAAS,mCAAI,oBAAoB,EAAE,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE;YAC1G,UAAU,EAAE,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AI,CAAC,KAAK,CAAC,CAAC;qBACpC;yBAAM;wBACL,MAAM,IAAI,yBAAW,CAAC,2BAAa,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;qBAC9D;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACpB,IAAI,CAAC,GAAG,CAAC,CAAC;gBACV,SAAU;oBACR,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;oBAC/B,IAAI,CAAC,IAAI,EAAE;wBACT,MAAM;qBACP;oBAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;oBACvD,EAAE,CAAC,CAAC;iBACL;gBAED,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA9ED,oDA8EC","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 RpcInterface\n */\n\n// cspell:ignore calltrace\n\nimport { assert, Logger, SpanKind, Tracing } from \"@itwin/core-bentley\";\nimport { BentleyStatus, HttpServerRequest, IModelError, RpcActivity, RpcInvocation, RpcMultipart, RpcSerializedValue } from \"@itwin/core-common\";\nimport { AsyncLocalStorage } from \"async_hooks\";\nimport * as FormData from \"form-data\";\nimport * as multiparty from \"multiparty\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { IModelHost } from \"./IModelHost\";\n\n/**\n * Utility for tracing Rpc activity processing. When multiple Rpc requests are being processed asynchronously, this\n * class can be used to correlate the current calltrace with the originating RpcActivity. This is used for automatic appending\n * of RpcActivity to log messages emitted during Rpc processing. It may also be used to retrieve the user accessToken\n * from the RpcActivity.\n * @public\n */\nexport class RpcTrace {\n private static _storage = new AsyncLocalStorage();\n\n /** Get the [RpcActivity]($common) for the currently executing async, or `undefined` if there is no\n * RpcActivity in the current call stack.\n * */\n public static get currentActivity(): RpcActivity | undefined {\n return RpcTrace._storage.getStore() as RpcActivity | undefined;\n }\n\n /** Get the [RpcActivity]($common) for the currently executing async. Asserts that the RpcActivity\n * exists in the current call stack.\n * */\n public static get expectCurrentActivity(): RpcActivity {\n assert(undefined !== RpcTrace.currentActivity);\n return RpcTrace.currentActivity;\n }\n\n /** Start the processing of an RpcActivity. */\n public static async run<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T> {\n return RpcTrace._storage.run(activity, fn);\n }\n\n /** Start the processing of an RpcActivity inside an OpenTelemetry span */\n public static async runWithSpan<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T> {\n return Tracing.withSpan(activity.rpcMethod ?? \"unknown RPC method\", async () => RpcTrace.run(activity, fn), {\n attributes: { ...RpcInvocation.sanitizeForLog(activity) },\n kind: SpanKind.SERVER,\n });\n }\n}\n\nlet initialized = false;\n/** @internal */\nexport function initializeRpcBackend(enableOpenTelemetry: boolean = false) {\n if (initialized)\n return;\n\n initialized = true;\n\n RpcInvocation.runActivity = RpcTrace.run; // redirect the invocation processing to the tracer\n\n if (enableOpenTelemetry) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const api = require(\"@opentelemetry/api\");\n const tracer = api.trace.getTracer(\"@itwin/core-backend\", IModelHost.backendVersion);\n Tracing.enableOpenTelemetry(tracer, api);\n RpcInvocation.runActivity = RpcTrace.runWithSpan; // wrap invocation in an OpenTelemetry span in addition to RpcTrace\n } catch (e) {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Logger.logError(BackendLoggerCategory.IModelHost, \"Failed to initialize OpenTelemetry\");\n Logger.logException(BackendLoggerCategory.IModelHost, e);\n }\n }\n\n // set up static logger metadata to include current RpcActivity information for logs during rpc processing\n Logger.staticMetaData.set(\"rpc\", () => RpcInvocation.sanitizeForLog(RpcTrace.currentActivity));\n\n RpcMultipart.createStream = (value: RpcSerializedValue) => {\n const form = new FormData();\n RpcMultipart.writeValueToForm(form, value);\n // Type information for FormData is lying. It actually extends Stream but not Readable, although it appears to work\n // fine for now.\n return form;\n };\n\n RpcMultipart.parseRequest = async (req: HttpServerRequest) => {\n return new Promise<RpcSerializedValue>((resolve, reject) => {\n const form = new multiparty.Form({ maxFieldsSize: Infinity });\n form.on(\"error\", (err) => {\n reject(err);\n });\n\n const value = RpcSerializedValue.create();\n const data: { [index: string]: { size: number, chunks: Buffer[] } } = {};\n\n form.on(\"part\", (part: multiparty.Part) => {\n part.on(\"data\", (chunk: string | Buffer) => {\n if (part.name === \"objects\") {\n value.objects += chunk.toString();\n } else if (Buffer.isBuffer(chunk)) {\n if (!data[part.name]) {\n data[part.name] = { size: 0, chunks: [] };\n }\n\n data[part.name].size += chunk.byteLength;\n data[part.name].chunks.push(chunk);\n } else {\n throw new IModelError(BentleyStatus.ERROR, \"Unknown input.\");\n }\n });\n });\n\n form.on(\"close\", () => {\n let i = 0;\n for (; ;) {\n const part = data[`data-${i}`];\n if (!part) {\n break;\n }\n\n value.data.push(Buffer.concat(part.chunks, part.size));\n ++i;\n }\n\n resolve(value);\n });\n\n form.parse(req);\n });\n };\n}\n"]}