@itwin/core-backend 3.4.0-dev.50 → 3.4.0-dev.56

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 (246) hide show
  1. package/lib/cjs/AliCloudStorageService.d.ts +23 -17
  2. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
  3. package/lib/cjs/AliCloudStorageService.js +71 -68
  4. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  5. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  6. package/lib/cjs/BackendHubAccess.js +41 -41
  7. package/lib/cjs/BackendHubAccess.js.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.d.ts +91 -87
  9. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  10. package/lib/cjs/BackendLoggerCategory.js +99 -95
  11. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  12. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  13. package/lib/cjs/BisCoreSchema.js +60 -60
  14. package/lib/cjs/BisCoreSchema.js.map +1 -1
  15. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  16. package/lib/cjs/BriefcaseManager.js +405 -405
  17. package/lib/cjs/BriefcaseManager.js.map +1 -1
  18. package/lib/cjs/Category.d.ts +153 -153
  19. package/lib/cjs/Category.js +243 -243
  20. package/lib/cjs/Category.js.map +1 -1
  21. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  22. package/lib/cjs/ChangeSummaryManager.js +445 -445
  23. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  24. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  25. package/lib/cjs/ChangedElementsDb.js +165 -165
  26. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  27. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  28. package/lib/cjs/ChangedElementsManager.js +88 -88
  29. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  30. package/lib/cjs/CheckpointManager.d.ts +120 -122
  31. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  32. package/lib/cjs/CheckpointManager.js +343 -354
  33. package/lib/cjs/CheckpointManager.js.map +1 -1
  34. package/lib/cjs/ClassRegistry.d.ts +71 -71
  35. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  36. package/lib/cjs/ClassRegistry.js +215 -213
  37. package/lib/cjs/ClassRegistry.js.map +1 -1
  38. package/lib/cjs/CloudSqlite.d.ts +328 -328
  39. package/lib/cjs/CloudSqlite.js +135 -135
  40. package/lib/cjs/CloudSqlite.js.map +1 -1
  41. package/lib/cjs/CloudStorageBackend.d.ts +58 -46
  42. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
  43. package/lib/cjs/CloudStorageBackend.js +173 -164
  44. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  45. package/lib/cjs/CodeService.d.ts +391 -391
  46. package/lib/cjs/CodeService.d.ts.map +1 -1
  47. package/lib/cjs/CodeService.js +63 -61
  48. package/lib/cjs/CodeService.js.map +1 -1
  49. package/lib/cjs/CodeSpecs.d.ts +50 -50
  50. package/lib/cjs/CodeSpecs.js +112 -112
  51. package/lib/cjs/CodeSpecs.js.map +1 -1
  52. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  53. package/lib/cjs/ConcurrentQuery.js +30 -30
  54. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  55. package/lib/cjs/CustomViewState3dCreator.d.ts +32 -32
  56. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  57. package/lib/cjs/CustomViewState3dCreator.js +113 -107
  58. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  59. package/lib/cjs/DevTools.d.ts +71 -71
  60. package/lib/cjs/DevTools.d.ts.map +1 -1
  61. package/lib/cjs/DevTools.js +154 -154
  62. package/lib/cjs/DevTools.js.map +1 -1
  63. package/lib/cjs/DisplayStyle.d.ts +106 -106
  64. package/lib/cjs/DisplayStyle.js +256 -256
  65. package/lib/cjs/DisplayStyle.js.map +1 -1
  66. package/lib/cjs/ECDb.d.ts +191 -191
  67. package/lib/cjs/ECDb.js +350 -350
  68. package/lib/cjs/ECDb.js.map +1 -1
  69. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  70. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  71. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  72. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  73. package/lib/cjs/ECSqlStatement.js +791 -791
  74. package/lib/cjs/ECSqlStatement.js.map +1 -1
  75. package/lib/cjs/Element.d.ts +1109 -1109
  76. package/lib/cjs/Element.d.ts.map +1 -1
  77. package/lib/cjs/Element.js +1420 -1421
  78. package/lib/cjs/Element.js.map +1 -1
  79. package/lib/cjs/ElementAspect.d.ts +156 -156
  80. package/lib/cjs/ElementAspect.js +178 -178
  81. package/lib/cjs/ElementAspect.js.map +1 -1
  82. package/lib/cjs/ElementGraphics.d.ts +9 -9
  83. package/lib/cjs/ElementGraphics.js +41 -41
  84. package/lib/cjs/ElementGraphics.js.map +1 -1
  85. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  86. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  87. package/lib/cjs/ElementTreeWalker.js +409 -409
  88. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  89. package/lib/cjs/Entity.d.ts +76 -76
  90. package/lib/cjs/Entity.js +82 -82
  91. package/lib/cjs/Entity.js.map +1 -1
  92. package/lib/cjs/ExportGraphics.d.ts +317 -317
  93. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  94. package/lib/cjs/ExportGraphics.js +208 -208
  95. package/lib/cjs/ExportGraphics.js.map +1 -1
  96. package/lib/cjs/ExternalSource.d.ts +94 -94
  97. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  98. package/lib/cjs/ExternalSource.js +125 -125
  99. package/lib/cjs/ExternalSource.js.map +1 -1
  100. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  101. package/lib/cjs/GeoCoordConfig.js +82 -82
  102. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  103. package/lib/cjs/GeometrySummary.d.ts +4 -4
  104. package/lib/cjs/GeometrySummary.js +380 -380
  105. package/lib/cjs/GeometrySummary.js.map +1 -1
  106. package/lib/cjs/HubMock.d.ts +93 -93
  107. package/lib/cjs/HubMock.js +190 -190
  108. package/lib/cjs/HubMock.js.map +1 -1
  109. package/lib/cjs/IModelCloneContext.d.ts +85 -85
  110. package/lib/cjs/IModelCloneContext.js +150 -150
  111. package/lib/cjs/IModelCloneContext.js.map +1 -1
  112. package/lib/cjs/IModelDb.d.ts +1164 -1164
  113. package/lib/cjs/IModelDb.d.ts.map +1 -1
  114. package/lib/cjs/IModelDb.js +2324 -2321
  115. package/lib/cjs/IModelDb.js.map +1 -1
  116. package/lib/cjs/IModelHost.d.ts +361 -347
  117. package/lib/cjs/IModelHost.d.ts.map +1 -1
  118. package/lib/cjs/IModelHost.js +489 -457
  119. package/lib/cjs/IModelHost.js.map +1 -1
  120. package/lib/cjs/IModelJsFs.d.ts +62 -62
  121. package/lib/cjs/IModelJsFs.js +140 -140
  122. package/lib/cjs/IModelJsFs.js.map +1 -1
  123. package/lib/cjs/IpcHost.d.ts +98 -98
  124. package/lib/cjs/IpcHost.js +234 -234
  125. package/lib/cjs/IpcHost.js.map +1 -1
  126. package/lib/cjs/LineStyle.d.ts +311 -311
  127. package/lib/cjs/LineStyle.js +295 -295
  128. package/lib/cjs/LineStyle.js.map +1 -1
  129. package/lib/cjs/LocalHub.d.ts +162 -162
  130. package/lib/cjs/LocalHub.js +587 -587
  131. package/lib/cjs/LocalHub.js.map +1 -1
  132. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  133. package/lib/cjs/LocalhostIpcHost.js +81 -81
  134. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  135. package/lib/cjs/Material.d.ts +103 -103
  136. package/lib/cjs/Material.js +147 -147
  137. package/lib/cjs/Material.js.map +1 -1
  138. package/lib/cjs/Model.d.ts +386 -386
  139. package/lib/cjs/Model.d.ts.map +1 -1
  140. package/lib/cjs/Model.js +471 -468
  141. package/lib/cjs/Model.js.map +1 -1
  142. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  143. package/lib/cjs/NativeAppStorage.js +202 -202
  144. package/lib/cjs/NativeAppStorage.js.map +1 -1
  145. package/lib/cjs/NativeHost.d.ts +52 -52
  146. package/lib/cjs/NativeHost.js +168 -168
  147. package/lib/cjs/NativeHost.js.map +1 -1
  148. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  149. package/lib/cjs/NavigationRelationship.js +225 -225
  150. package/lib/cjs/NavigationRelationship.js.map +1 -1
  151. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  152. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  153. package/lib/cjs/PromiseMemoizer.js +101 -95
  154. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  155. package/lib/cjs/PropertyStore.d.ts +132 -132
  156. package/lib/cjs/PropertyStore.js +11 -11
  157. package/lib/cjs/PropertyStore.js.map +1 -1
  158. package/lib/cjs/Relationship.d.ts +400 -400
  159. package/lib/cjs/Relationship.js +465 -465
  160. package/lib/cjs/Relationship.js.map +1 -1
  161. package/lib/cjs/RpcBackend.d.ts +28 -28
  162. package/lib/cjs/RpcBackend.js +126 -126
  163. package/lib/cjs/RpcBackend.js.map +1 -1
  164. package/lib/cjs/SQLiteDb.d.ts +219 -219
  165. package/lib/cjs/SQLiteDb.js +214 -214
  166. package/lib/cjs/SQLiteDb.js.map +1 -1
  167. package/lib/cjs/Schema.d.ts +55 -55
  168. package/lib/cjs/Schema.js +83 -83
  169. package/lib/cjs/Schema.js.map +1 -1
  170. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  171. package/lib/cjs/ServerBasedLocks.js +168 -168
  172. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  173. package/lib/cjs/SqliteStatement.d.ts +283 -283
  174. package/lib/cjs/SqliteStatement.js +448 -448
  175. package/lib/cjs/SqliteStatement.js.map +1 -1
  176. package/lib/cjs/Texture.d.ts +58 -58
  177. package/lib/cjs/Texture.js +82 -82
  178. package/lib/cjs/Texture.js.map +1 -1
  179. package/lib/cjs/TileStorage.d.ts +19 -0
  180. package/lib/cjs/TileStorage.d.ts.map +1 -0
  181. package/lib/cjs/TileStorage.js +91 -0
  182. package/lib/cjs/TileStorage.js.map +1 -0
  183. package/lib/cjs/TxnManager.d.ts +202 -202
  184. package/lib/cjs/TxnManager.d.ts.map +1 -1
  185. package/lib/cjs/TxnManager.js +356 -353
  186. package/lib/cjs/TxnManager.js.map +1 -1
  187. package/lib/cjs/ViewDefinition.d.ts +435 -435
  188. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  189. package/lib/cjs/ViewDefinition.js +635 -629
  190. package/lib/cjs/ViewDefinition.js.map +1 -1
  191. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  192. package/lib/cjs/ViewStateHydrator.js +103 -103
  193. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  194. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  195. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  196. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  197. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  198. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  199. package/lib/cjs/core-backend.d.ts +182 -178
  200. package/lib/cjs/core-backend.d.ts.map +1 -1
  201. package/lib/cjs/core-backend.js +202 -198
  202. package/lib/cjs/core-backend.js.map +1 -1
  203. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  204. package/lib/cjs/domains/FunctionalElements.js +145 -145
  205. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  206. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  207. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  208. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  209. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  210. package/lib/cjs/domains/GenericElements.js +263 -263
  211. package/lib/cjs/domains/GenericElements.js.map +1 -1
  212. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  213. package/lib/cjs/domains/GenericSchema.js +28 -28
  214. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  215. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  216. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  217. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  218. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +45 -45
  219. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +262 -262
  220. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  221. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -20
  222. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  223. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +204 -195
  224. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  225. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  226. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  227. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -165
  228. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  229. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  230. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  231. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  232. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  233. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  234. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  235. package/lib/cjs/workspace/Settings.d.ts +186 -186
  236. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  237. package/lib/cjs/workspace/Settings.js +155 -152
  238. package/lib/cjs/workspace/Settings.js.map +1 -1
  239. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  240. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  241. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  242. package/lib/cjs/workspace/Workspace.d.ts +414 -405
  243. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  244. package/lib/cjs/workspace/Workspace.js +543 -539
  245. package/lib/cjs/workspace/Workspace.js.map +1 -1
  246. package/package.json +17 -13
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAkH;AAClH,oDAA4D;AAE5D,6CAA0C;AAmB1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,eAAe;IAI1B,YAA2B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAI,CAAC;IAC5C,IAAW,IAAI,KAAqC,OAAO,IAAI,CAAC,KAAM,CAAC,CAAC,CAAC;IACzE,IAAW,GAAG,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEtC,oEAAoE;IACpE,IAAW,UAAU,KAAc,OAAO,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAErE;;;;;;OAMG;IACI,OAAO,CAAC,EAAwB,EAAE,SAAS,GAAG,IAAI;QACvD,IAAI,IAAI,CAAC,UAAU;YACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,IAAI,uBAAU,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;QACvD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,SA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AGzB,YAAmB,QAAQ,GAAG,EAAE;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAM,CAAe,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,YAAY,CAAC,IAAU;QAC5B,IAAA,qBAAM,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAExB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,iGAAiG;YACjH,OAAO;SACR;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACzC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAG,CAAC;YACpC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;SACrB;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAEM,aAAa,CAAC,GAAW;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAjCD,wCAiCC","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 SQLite\r\n */\r\n\r\nimport { assert, BentleyError, DbResult, GuidString, Id64String, IDisposable, LRUMap } from \"@itwin/core-bentley\";\r\nimport { ECJsNames, IModelError } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\r\n\r\n/** Marks a string as either an [Id64String]($core-bentley) or [GuidString]($core-bentley), so\r\n * that it can be passed to the [bindValue]($backend.SqliteStatement) or [bindValues]($backend.SqliteStatement)\r\n * methods of [SqliteStatement]($backend).\r\n * @internal\r\n */\r\nexport interface StringParam {\r\n id?: Id64String;\r\n guid?: GuidString;\r\n}\r\n\r\n/** parameter Index (1-based), or name of the parameter (including the initial ':', '@' or '$')\r\n * @public\r\n */\r\nexport type BindParameter = number | string;\r\n\r\n/** Executes SQLite SQL statements.\r\n *\r\n * A statement must be prepared before it can be executed, and it must be released when no longer needed.\r\n * See [IModelDb.withPreparedSqliteStatement]($backend) or\r\n * [ECDb.withPreparedSqliteStatement]($backend) for a convenient and\r\n * reliable way to prepare, execute, and then release a statement.\r\n *\r\n * A statement may contain parameters that must be filled in before use by calling [SqliteStatement.bindValue]($backend)\r\n * or [SqliteStatement.bindValues]($backend).\r\n *\r\n * Once prepared (and parameters are bound, if any), the statement is executed by calling [SqliteStatement.step]($backend).\r\n * In case of an **SQL SELECT** statement, the current row can be retrieved with [SqliteStatement.getRow]($backend) as\r\n * a whole, or with [SqliteStatement.getValue]($backend) when individual values are needed.\r\n * Alternatively, query results of an **SQL SELECT** statement can be stepped through by using\r\n * standard iteration syntax, such as `for of`.\r\n *\r\n * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared\r\n * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.\r\n * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.\r\n * @public\r\n */\r\nexport class SqliteStatement implements IterableIterator<any>, IDisposable {\r\n private _stmt: IModelJsNative.SqliteStatement | undefined;\r\n private _db: IModelJsNative.AnyDb | undefined;\r\n\r\n public constructor(private _sql: string) { }\r\n public get stmt(): IModelJsNative.SqliteStatement { return this._stmt!; }\r\n public get sql() { return this._sql; }\r\n\r\n /** Check if this statement has been prepared successfully or not */\r\n public get isPrepared(): boolean { return undefined !== this._stmt; }\r\n\r\n /** Prepare this statement prior to first use.\r\n * @param db The DgnDb or ECDb to prepare the statement against\r\n * @param sql The SQL statement string to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @throws if the SQL statement cannot be prepared. Normally, prepare fails due to SQL syntax errors or references to tables or properties that do not exist.\r\n * The error.message property will provide details.\r\n */\r\n public prepare(db: IModelJsNative.AnyDb, logErrors = true): void {\r\n if (this.isPrepared)\r\n throw new Error(\"SqliteStatement is already prepared\");\r\n this._db = db;\r\n this._stmt = new IModelHost.platform.SqliteStatement();\r\n this._stmt.prepare(db, this._sql, logErrors);\r\n }\r\n\r\n /** Indicates whether the prepared statement makes no **direct* changes to the content of the file\r\n * or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.\r\n */\r\n public get isReadonly(): boolean {\r\n return this.stmt.isReadonly();\r\n }\r\n\r\n /** Reset this statement so that the next call to step will return the first row, if any.\r\n */\r\n public reset(): void {\r\n this.stmt.reset();\r\n }\r\n\r\n /** Call this function when finished with this statement. This releases the native resources held by the statement. */\r\n public dispose(): void {\r\n if (this._stmt) {\r\n this._stmt.dispose(); // free native statement\r\n this._stmt = undefined;\r\n this._db = undefined;\r\n }\r\n }\r\n\r\n /**\r\n * Call `step` on this statement and determine whether a new row is available.\r\n * Use this method only when this statement has been prepared with a SELECT statement.\r\n * @return true if a new row is available, false otherwise.\r\n * @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.\r\n */\r\n public nextRow(): boolean {\r\n const rc = this.step();\r\n switch (rc) {\r\n case DbResult.BE_SQLITE_ROW:\r\n return true;\r\n case DbResult.BE_SQLITE_DONE:\r\n return false;\r\n }\r\n\r\n throw new BentleyError(rc, this._db!.getLastError());\r\n }\r\n\r\n /** Binds a value to the specified SQL parameter.\r\n * The value must be of one of these types:\r\n * JavaScript Type | SQLite Type\r\n * --- | ---\r\n * undefined | NULL\r\n * boolean | INTEGER with true being bound as 1 and false as 0\r\n * number | INTEGER if number is integral or REAL if number is not integral\r\n * string | TEXT\r\n * Uint8Array or ArrayBuffer | BLOB\r\n * [StringParam]($backend) where member **id** is set | INTEGER\r\n * [StringParam]($backend) where member **guid** is set | BLOB\r\n *\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param value Value to bind.\r\n * @throws [IModelError]($common) if the value is of an unsupported type or in\r\n * case of other binding errors.\r\n */\r\n public bindValue(parameter: BindParameter, value: any): void {\r\n let stat: DbResult;\r\n if (value === undefined || value === null) {\r\n stat = this.stmt.bindNull(parameter);\r\n } else if (typeof (value) === \"number\") {\r\n if (Number.isInteger(value))\r\n stat = this.stmt.bindInteger(parameter, value);\r\n else\r\n stat = this.stmt.bindDouble(parameter, value);\r\n } else if (typeof (value) === \"boolean\") {\r\n stat = this.stmt.bindInteger(parameter, value ? 1 : 0);\r\n } else if (typeof (value) === \"string\") {\r\n stat = this.stmt.bindString(parameter, value);\r\n } else if (!!value.id) {\r\n stat = this.stmt.bindId(parameter, value.id);\r\n } else if (!!value.guid) {\r\n stat = this.stmt.bindGuid(parameter, value.guid);\r\n } else if (value instanceof Uint8Array) {\r\n stat = this.stmt.bindBlob(parameter, value);\r\n } else\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Parameter value ${value} is of an unsupported data type.`);\r\n\r\n if (stat !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(stat, \"Error in bindValue\");\r\n }\r\n\r\n private checkBind(stat: DbResult) {\r\n if (stat !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(stat, \"SQLite Bind error\");\r\n }\r\n /** Bind an integer parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val integer to bind.\r\n */\r\n public bindInteger(parameter: BindParameter, val: number) {\r\n this.checkBind(this.stmt.bindInteger(parameter, val));\r\n }\r\n /** Bind a double parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val double to bind.\r\n */\r\n public bindDouble(parameter: BindParameter, val: number) {\r\n this.checkBind(this.stmt.bindDouble(parameter, val));\r\n }\r\n /** Bind a string parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val string to bind.\r\n */\r\n public bindString(parameter: BindParameter, val: string) {\r\n this.checkBind(this.stmt.bindString(parameter, val));\r\n }\r\n /** Bind an Id64String parameter as a 64-bit integer\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val Id to bind.\r\n */\r\n public bindId(parameter: BindParameter, id: Id64String) {\r\n this.checkBind(this.stmt.bindId(parameter, id));\r\n }\r\n /** Bind a Guid parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val Guid to bind.\r\n */\r\n public bindGuid(parameter: BindParameter, guid: GuidString) {\r\n this.checkBind(this.stmt.bindGuid(parameter, guid));\r\n }\r\n /** Bind a blob parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val blob to bind.\r\n */\r\n public bindBlob(parameter: BindParameter, blob: Uint8Array) {\r\n this.checkBind(this.stmt.bindBlob(parameter, blob));\r\n }\r\n /** Bind null to a parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n */\r\n public bindNull(parameter: BindParameter) {\r\n this.checkBind(this.stmt.bindNull(parameter));\r\n }\r\n\r\n /** Bind values to all parameters in the statement.\r\n * @param values The values to bind to the parameters.\r\n * Pass an *array* of values if the parameters are *positional*.\r\n * Pass an *object of the values keyed on the parameter name* for *named parameters*.\r\n * The values in either the array or object must match the respective types of the parameter.\r\n * See [[SqliteStatement.bindValue]] for details on the supported types.\r\n */\r\n public bindValues(values: any[] | object): void {\r\n if (Array.isArray(values)) {\r\n for (let i = 0; i < values.length; i++) {\r\n const paramIndex: number = i + 1;\r\n const paramValue: any = values[i];\r\n if (paramValue === undefined || paramValue === null)\r\n continue;\r\n\r\n this.bindValue(paramIndex, paramValue);\r\n }\r\n return;\r\n }\r\n\r\n for (const entry of Object.entries(values)) {\r\n const paramName: string = entry[0];\r\n const paramValue: any = entry[1];\r\n if (paramValue === undefined || paramValue === null)\r\n continue;\r\n\r\n this.bindValue(paramName, paramValue);\r\n }\r\n }\r\n\r\n /** Clear any bindings that were previously set on this statement.\r\n * @throws [IModelError]($common) in case of errors\r\n */\r\n public clearBindings(): void {\r\n const stat = this.stmt.clearBindings();\r\n if (stat !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(stat, \"Error in clearBindings\");\r\n }\r\n\r\n /** Step this statement to the next row.\r\n *\r\n * For **SQL SELECT** statements the method returns\r\n * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.\r\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.\r\n * - Error status in case of errors.\r\n *\r\n * For **SQL INSERT, UPDATE, DELETE** statements the method returns\r\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.\r\n * - Error status in case of errors.\r\n */\r\n public step(): DbResult { return this.stmt.step(); }\r\n\r\n /** Get the query result's column count (only for SQL SELECT statements). */\r\n public getColumnCount(): number { return this.stmt.getColumnCount(); }\r\n\r\n /** Get the value for the column at the given index in the query result.\r\n * @param columnIx Index of SQL column in query result (0-based)\r\n */\r\n public getValue(columnIx: number): SqliteValue { return new SqliteValue(this.stmt, columnIx); }\r\n\r\n /** Determine whether the value of the specified column is null\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public isValueNull(colIndex: number): boolean { return this.stmt.isValueNull(colIndex); }\r\n\r\n /** Get a size in bytes of a blob or text column\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getColumnBytes(colIndex: number): number { return this.stmt.getColumnBytes(colIndex); }\r\n\r\n /** Get a value as a blob\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueBlob(colIndex: number): Uint8Array { return this.stmt.getValueBlob(colIndex); }\r\n /** Get a value as a double\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueDouble(colIndex: number): number { return this.stmt.getValueDouble(colIndex); }\r\n /** Get a value as a integer\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueInteger(colIndex: number): number { return this.stmt.getValueInteger(colIndex); }\r\n /** Get a value as a string\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueString(colIndex: number): string { return this.stmt.getValueString(colIndex); }\r\n /** Get a value as an Id\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueId(colIndex: number): Id64String { return this.stmt.getValueId(colIndex); }\r\n /** Get a value as a Guid\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueGuid(colIndex: number): GuidString { return this.stmt.getValueGuid(colIndex); }\r\n\r\n /** Get the current row.\r\n * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.\r\n *\r\n * The SQL select clause item's name becomes the member name of the JavaScript object, **with the first character lowered**.\r\n *\r\n * SQLite Type | JavaScript Type\r\n * --- | ---\r\n * [SqliteValueType.Null]($backend) | undefined\r\n * [SqliteValueType.Integer]($backend) | number\r\n * [SqliteValueType.Double]($backend) | number\r\n * [SqliteValueType.String]($backend) | string\r\n * [SqliteValueType.Blob]($backend) | Uint8Array\r\n */\r\n public getRow(): any {\r\n const colCount = this.getColumnCount();\r\n const row: object = {};\r\n const duplicatePropNames = new Map<string, number>();\r\n for (let i = 0; i < colCount; i++) {\r\n const sqliteValue = this.getValue(i);\r\n if (!sqliteValue.isNull) {\r\n const propName: string = SqliteStatement.determineResultRowPropertyName(duplicatePropNames, sqliteValue);\r\n let val: any;\r\n switch (sqliteValue.type) {\r\n case SqliteValueType.Blob:\r\n val = sqliteValue.getBlob();\r\n break;\r\n case SqliteValueType.Double:\r\n val = sqliteValue.getDouble();\r\n break;\r\n case SqliteValueType.Integer:\r\n val = sqliteValue.getInteger();\r\n break;\r\n case SqliteValueType.String:\r\n val = sqliteValue.getString();\r\n break;\r\n\r\n default:\r\n throw new Error(\"Unsupported SqliteValueType\");\r\n }\r\n\r\n Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });\r\n }\r\n }\r\n return row;\r\n }\r\n\r\n private static determineResultRowPropertyName(duplicatePropNames: Map<string, number>, sqliteValue: SqliteValue): string {\r\n let jsName = ECJsNames.toJsName(sqliteValue.columnName);\r\n\r\n // now check duplicates. If there are, append a numeric suffix to the duplicates\r\n let suffix = duplicatePropNames.get(jsName);\r\n if (suffix === undefined)\r\n duplicatePropNames.set(jsName, 0);\r\n else {\r\n suffix++;\r\n duplicatePropNames.set(jsName, suffix);\r\n jsName += `_${suffix}`;\r\n }\r\n\r\n return jsName;\r\n }\r\n\r\n /** Calls step when called as an iterator.\r\n */\r\n public next(): IteratorResult<any> {\r\n return DbResult.BE_SQLITE_ROW === this.step() ? { done: false, value: this.getRow() } : { done: true, value: undefined };\r\n }\r\n\r\n /** The iterator that will step through the results of this statement. */\r\n public [Symbol.iterator](): IterableIterator<any> { return this; }\r\n}\r\n\r\n/** Data type of a value in in an SQLite SQL query result.\r\n * See also:\r\n * - [SqliteValue]($backend)\r\n * - [SqliteStatement]($backend)\r\n * - [SqliteStatement.getValue]($backend)\r\n * @public\r\n */\r\nexport enum SqliteValueType {\r\n // do not change the values of that enum. It must correspond to the respective\r\n // enum DbValueType in the native BeSQLite API.\r\n Integer = 1,\r\n Double = 2,\r\n String = 3,\r\n Blob = 4,\r\n Null = 5,\r\n}\r\n\r\n/** Value of a column in a row of an SQLite SQL query result.\r\n * See also:\r\n * - [SqliteStatement]($backend)\r\n * - [SqliteStatement.getValue]($backend)\r\n * @public\r\n */\r\nexport class SqliteValue {\r\n private readonly _stmt: IModelJsNative.SqliteStatement;\r\n private readonly _colIndex: number;\r\n\r\n public constructor(stmt: IModelJsNative.SqliteStatement, colIndex: number) {\r\n this._stmt = stmt;\r\n this._colIndex = colIndex;\r\n }\r\n\r\n /** Indicates whether the value is NULL or not. */\r\n public get isNull(): boolean { return this._stmt.isValueNull(this._colIndex); }\r\n\r\n /** Gets the data type of the value. */\r\n public get type(): SqliteValueType { return this._stmt.getColumnType(this._colIndex); }\r\n\r\n /** Gets the name of the column of the value. */\r\n public get columnName(): string { return this._stmt.getColumnName(this._colIndex); }\r\n\r\n /** Gets the SqlValue as JavaScript value.\r\n *\r\n * SQLite Type | JavaScript Type\r\n * --- | ---\r\n * [SqliteValueType.Null]($backend) | undefined\r\n * [SqliteValueType.Integer]($backend) | number\r\n * [SqliteValueType.Double]($backend) | number\r\n * [SqliteValueType.String]($backend) | string\r\n * [SqliteValueType.Blob]($backend) | Uint8Array\r\n */\r\n public get value(): any {\r\n switch (this.type) {\r\n case SqliteValueType.Null:\r\n return undefined;\r\n case SqliteValueType.Blob:\r\n return this.getBlob();\r\n case SqliteValueType.Double:\r\n return this.getDouble();\r\n case SqliteValueType.Integer:\r\n return this.getInteger();\r\n case SqliteValueType.String:\r\n return this.getString();\r\n default:\r\n throw new Error(\"Unhandled SqliteValueType\");\r\n }\r\n }\r\n\r\n /** Get the value as BLOB */\r\n public getBlob(): Uint8Array { return this._stmt.getValueBlob(this._colIndex); }\r\n /** Get the value as a double value */\r\n public getDouble(): number { return this._stmt.getValueDouble(this._colIndex); }\r\n /** Get the value as a integer value */\r\n public getInteger(): number { return this._stmt.getValueInteger(this._colIndex); }\r\n /** Get the value as a string value */\r\n public getString(): string { return this._stmt.getValueString(this._colIndex); }\r\n /** Get the value as an Id value */\r\n public getId(): Id64String { return this._stmt.getValueId(this._colIndex); }\r\n /** Get the value as a Guid value */\r\n public getGuid(): GuidString { return this._stmt.getValueGuid(this._colIndex); }\r\n}\r\n\r\ninterface Statement {\r\n isPrepared: boolean;\r\n sql: string;\r\n dispose(): void;\r\n reset(): void;\r\n clearBindings(): void;\r\n}\r\n\r\n/** A cache for previously prepared SqliteStatements.\r\n * It only holds Statements after they are no longer in use, resetting and clearing their bindings before saving them.\r\n * When a request to use a statement from the cache is made, it is first removed from the cache.\r\n * @internal\r\n */\r\nexport class StatementCache<Stmt extends Statement> {\r\n private _cache: LRUMap<string, Stmt>;\r\n\r\n public constructor(maxCount = 40) {\r\n this._cache = new LRUMap<string, Stmt>(maxCount);\r\n }\r\n\r\n public get size() { return this._cache.size; }\r\n public addOrDispose(stmt: Stmt): void {\r\n assert(stmt.isPrepared);\r\n\r\n const existing = this._cache.get(stmt.sql);\r\n if (existing !== undefined) {\r\n stmt.dispose(); // we already have a statement with this sql cached, we can't save another one so just dispose it\r\n return;\r\n }\r\n if (this._cache.size >= this._cache.limit) {\r\n const oldest = this._cache.shift()!;\r\n oldest[1].dispose();\r\n }\r\n stmt.reset();\r\n stmt.clearBindings();\r\n this._cache.set(stmt.sql, stmt);\r\n }\r\n\r\n public findAndRemove(sql: string): Stmt | undefined {\r\n return this._cache.delete(sql);\r\n }\r\n\r\n public clear() {\r\n this._cache.forEach((stmt) => stmt.dispose());\r\n this._cache.clear();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAkH;AAClH,oDAA4D;AAE5D,6CAA0C;AAmB1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,eAAe;IAI1B,YAA2B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAI,CAAC;IAC5C,IAAW,IAAI,KAAqC,OAAO,IAAI,CA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,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAEM,aAAa,CAAC,GAAW;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAjCD,wCAiCC","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 SQLite\n */\n\nimport { assert, BentleyError, DbResult, GuidString, Id64String, IDisposable, LRUMap } from \"@itwin/core-bentley\";\nimport { ECJsNames, IModelError } from \"@itwin/core-common\";\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { IModelHost } from \"./IModelHost\";\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\n/** Marks a string as either an [Id64String]($core-bentley) or [GuidString]($core-bentley), so\n * that it can be passed to the [bindValue]($backend.SqliteStatement) or [bindValues]($backend.SqliteStatement)\n * methods of [SqliteStatement]($backend).\n * @internal\n */\nexport interface StringParam {\n id?: Id64String;\n guid?: GuidString;\n}\n\n/** parameter Index (1-based), or name of the parameter (including the initial ':', '@' or '$')\n * @public\n */\nexport type BindParameter = number | string;\n\n/** Executes SQLite SQL statements.\n *\n * A statement must be prepared before it can be executed, and it must be released when no longer needed.\n * See [IModelDb.withPreparedSqliteStatement]($backend) or\n * [ECDb.withPreparedSqliteStatement]($backend) for a convenient and\n * reliable way to prepare, execute, and then release a statement.\n *\n * A statement may contain parameters that must be filled in before use by calling [SqliteStatement.bindValue]($backend)\n * or [SqliteStatement.bindValues]($backend).\n *\n * Once prepared (and parameters are bound, if any), the statement is executed by calling [SqliteStatement.step]($backend).\n * In case of an **SQL SELECT** statement, the current row can be retrieved with [SqliteStatement.getRow]($backend) as\n * a whole, or with [SqliteStatement.getValue]($backend) when individual values are needed.\n * Alternatively, query results of an **SQL SELECT** statement can be stepped through by using\n * standard iteration syntax, such as `for of`.\n *\n * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared\n * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.\n * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.\n * @public\n */\nexport class SqliteStatement implements IterableIterator<any>, IDisposable {\n private _stmt: IModelJsNative.SqliteStatement | undefined;\n private _db: IModelJsNative.AnyDb | undefined;\n\n public constructor(private _sql: string) { }\n public get stmt(): IModelJsNative.SqliteStatement { return this._stmt!; }\n public get sql() { return this._sql; }\n\n /** Check if this statement has been prepared successfully or not */\n public get isPrepared(): boolean { return undefined !== this._stmt; }\n\n /** Prepare this statement prior to first use.\n * @param db The DgnDb or ECDb to prepare the statement against\n * @param sql The SQL statement string to prepare\n * @param logErrors Determine if errors are logged or not\n * @throws if the SQL statement cannot be prepared. Normally, prepare fails due to SQL syntax errors or references to tables or properties that do not exist.\n * The error.message property will provide details.\n */\n public prepare(db: IModelJsNative.AnyDb, logErrors = true): void {\n if (this.isPrepared)\n throw new Error(\"SqliteStatement is already prepared\");\n this._db = db;\n this._stmt = new IModelHost.platform.SqliteStatement();\n this._stmt.prepare(db, this._sql, logErrors);\n }\n\n /** Indicates whether the prepared statement makes no **direct* changes to the content of the file\n * or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.\n */\n public get isReadonly(): boolean {\n return this.stmt.isReadonly();\n }\n\n /** Reset this statement so that the next call to step will return the first row, if any.\n */\n public reset(): void {\n this.stmt.reset();\n }\n\n /** Call this function when finished with this statement. This releases the native resources held by the statement. */\n public dispose(): void {\n if (this._stmt) {\n this._stmt.dispose(); // free native statement\n this._stmt = undefined;\n this._db = undefined;\n }\n }\n\n /**\n * Call `step` on this statement and determine whether a new row is available.\n * Use this method only when this statement has been prepared with a SELECT statement.\n * @return true if a new row is available, false otherwise.\n * @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.\n */\n public nextRow(): boolean {\n const rc = this.step();\n switch (rc) {\n case DbResult.BE_SQLITE_ROW:\n return true;\n case DbResult.BE_SQLITE_DONE:\n return false;\n }\n\n throw new BentleyError(rc, this._db!.getLastError());\n }\n\n /** Binds a value to the specified SQL parameter.\n * The value must be of one of these types:\n * JavaScript Type | SQLite Type\n * --- | ---\n * undefined | NULL\n * boolean | INTEGER with true being bound as 1 and false as 0\n * number | INTEGER if number is integral or REAL if number is not integral\n * string | TEXT\n * Uint8Array or ArrayBuffer | BLOB\n * [StringParam]($backend) where member **id** is set | INTEGER\n * [StringParam]($backend) where member **guid** is set | BLOB\n *\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param value Value to bind.\n * @throws [IModelError]($common) if the value is of an unsupported type or in\n * case of other binding errors.\n */\n public bindValue(parameter: BindParameter, value: any): void {\n let stat: DbResult;\n if (value === undefined || value === null) {\n stat = this.stmt.bindNull(parameter);\n } else if (typeof (value) === \"number\") {\n if (Number.isInteger(value))\n stat = this.stmt.bindInteger(parameter, value);\n else\n stat = this.stmt.bindDouble(parameter, value);\n } else if (typeof (value) === \"boolean\") {\n stat = this.stmt.bindInteger(parameter, value ? 1 : 0);\n } else if (typeof (value) === \"string\") {\n stat = this.stmt.bindString(parameter, value);\n } else if (!!value.id) {\n stat = this.stmt.bindId(parameter, value.id);\n } else if (!!value.guid) {\n stat = this.stmt.bindGuid(parameter, value.guid);\n } else if (value instanceof Uint8Array) {\n stat = this.stmt.bindBlob(parameter, value);\n } else\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Parameter value ${value} is of an unsupported data type.`);\n\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in bindValue\");\n }\n\n private checkBind(stat: DbResult) {\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"SQLite Bind error\");\n }\n /** Bind an integer parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val integer to bind.\n */\n public bindInteger(parameter: BindParameter, val: number) {\n this.checkBind(this.stmt.bindInteger(parameter, val));\n }\n /** Bind a double parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val double to bind.\n */\n public bindDouble(parameter: BindParameter, val: number) {\n this.checkBind(this.stmt.bindDouble(parameter, val));\n }\n /** Bind a string parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val string to bind.\n */\n public bindString(parameter: BindParameter, val: string) {\n this.checkBind(this.stmt.bindString(parameter, val));\n }\n /** Bind an Id64String parameter as a 64-bit integer\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Id to bind.\n */\n public bindId(parameter: BindParameter, id: Id64String) {\n this.checkBind(this.stmt.bindId(parameter, id));\n }\n /** Bind a Guid parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Guid to bind.\n */\n public bindGuid(parameter: BindParameter, guid: GuidString) {\n this.checkBind(this.stmt.bindGuid(parameter, guid));\n }\n /** Bind a blob parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val blob to bind.\n */\n public bindBlob(parameter: BindParameter, blob: Uint8Array) {\n this.checkBind(this.stmt.bindBlob(parameter, blob));\n }\n /** Bind null to a parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n */\n public bindNull(parameter: BindParameter) {\n this.checkBind(this.stmt.bindNull(parameter));\n }\n\n /** Bind values to all parameters in the statement.\n * @param values The values to bind to the parameters.\n * Pass an *array* of values if the parameters are *positional*.\n * Pass an *object of the values keyed on the parameter name* for *named parameters*.\n * The values in either the array or object must match the respective types of the parameter.\n * See [[SqliteStatement.bindValue]] for details on the supported types.\n */\n public bindValues(values: any[] | object): void {\n if (Array.isArray(values)) {\n for (let i = 0; i < values.length; i++) {\n const paramIndex: number = i + 1;\n const paramValue: any = values[i];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramIndex, paramValue);\n }\n return;\n }\n\n for (const entry of Object.entries(values)) {\n const paramName: string = entry[0];\n const paramValue: any = entry[1];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramName, paramValue);\n }\n }\n\n /** Clear any bindings that were previously set on this statement.\n * @throws [IModelError]($common) in case of errors\n */\n public clearBindings(): void {\n const stat = this.stmt.clearBindings();\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in clearBindings\");\n }\n\n /** Step this statement to the next row.\n *\n * For **SQL SELECT** statements the method returns\n * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.\n * - Error status in case of errors.\n *\n * For **SQL INSERT, UPDATE, DELETE** statements the method returns\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.\n * - Error status in case of errors.\n */\n public step(): DbResult { return this.stmt.step(); }\n\n /** Get the query result's column count (only for SQL SELECT statements). */\n public getColumnCount(): number { return this.stmt.getColumnCount(); }\n\n /** Get the value for the column at the given index in the query result.\n * @param columnIx Index of SQL column in query result (0-based)\n */\n public getValue(columnIx: number): SqliteValue { return new SqliteValue(this.stmt, columnIx); }\n\n /** Determine whether the value of the specified column is null\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public isValueNull(colIndex: number): boolean { return this.stmt.isValueNull(colIndex); }\n\n /** Get a size in bytes of a blob or text column\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getColumnBytes(colIndex: number): number { return this.stmt.getColumnBytes(colIndex); }\n\n /** Get a value as a blob\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBlob(colIndex: number): Uint8Array { return this.stmt.getValueBlob(colIndex); }\n /** Get a value as a double\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueDouble(colIndex: number): number { return this.stmt.getValueDouble(colIndex); }\n /** Get a value as a integer\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueInteger(colIndex: number): number { return this.stmt.getValueInteger(colIndex); }\n /** Get a value as a string\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueString(colIndex: number): string { return this.stmt.getValueString(colIndex); }\n /** Get a value as an Id\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueId(colIndex: number): Id64String { return this.stmt.getValueId(colIndex); }\n /** Get a value as a Guid\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueGuid(colIndex: number): GuidString { return this.stmt.getValueGuid(colIndex); }\n\n /** Get the current row.\n * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.\n *\n * The SQL select clause item's name becomes the member name of the JavaScript object, **with the first character lowered**.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public getRow(): any {\n const colCount = this.getColumnCount();\n const row: object = {};\n const duplicatePropNames = new Map<string, number>();\n for (let i = 0; i < colCount; i++) {\n const sqliteValue = this.getValue(i);\n if (!sqliteValue.isNull) {\n const propName: string = SqliteStatement.determineResultRowPropertyName(duplicatePropNames, sqliteValue);\n let val: any;\n switch (sqliteValue.type) {\n case SqliteValueType.Blob:\n val = sqliteValue.getBlob();\n break;\n case SqliteValueType.Double:\n val = sqliteValue.getDouble();\n break;\n case SqliteValueType.Integer:\n val = sqliteValue.getInteger();\n break;\n case SqliteValueType.String:\n val = sqliteValue.getString();\n break;\n\n default:\n throw new Error(\"Unsupported SqliteValueType\");\n }\n\n Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });\n }\n }\n return row;\n }\n\n private static determineResultRowPropertyName(duplicatePropNames: Map<string, number>, sqliteValue: SqliteValue): string {\n let jsName = ECJsNames.toJsName(sqliteValue.columnName);\n\n // now check duplicates. If there are, append a numeric suffix to the duplicates\n let suffix = duplicatePropNames.get(jsName);\n if (suffix === undefined)\n duplicatePropNames.set(jsName, 0);\n else {\n suffix++;\n duplicatePropNames.set(jsName, suffix);\n jsName += `_${suffix}`;\n }\n\n return jsName;\n }\n\n /** Calls step when called as an iterator.\n */\n public next(): IteratorResult<any> {\n return DbResult.BE_SQLITE_ROW === this.step() ? { done: false, value: this.getRow() } : { done: true, value: undefined };\n }\n\n /** The iterator that will step through the results of this statement. */\n public [Symbol.iterator](): IterableIterator<any> { return this; }\n}\n\n/** Data type of a value in in an SQLite SQL query result.\n * See also:\n * - [SqliteValue]($backend)\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport enum SqliteValueType {\n // do not change the values of that enum. It must correspond to the respective\n // enum DbValueType in the native BeSQLite API.\n Integer = 1,\n Double = 2,\n String = 3,\n Blob = 4,\n Null = 5,\n}\n\n/** Value of a column in a row of an SQLite SQL query result.\n * See also:\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport class SqliteValue {\n private readonly _stmt: IModelJsNative.SqliteStatement;\n private readonly _colIndex: number;\n\n public constructor(stmt: IModelJsNative.SqliteStatement, colIndex: number) {\n this._stmt = stmt;\n this._colIndex = colIndex;\n }\n\n /** Indicates whether the value is NULL or not. */\n public get isNull(): boolean { return this._stmt.isValueNull(this._colIndex); }\n\n /** Gets the data type of the value. */\n public get type(): SqliteValueType { return this._stmt.getColumnType(this._colIndex); }\n\n /** Gets the name of the column of the value. */\n public get columnName(): string { return this._stmt.getColumnName(this._colIndex); }\n\n /** Gets the SqlValue as JavaScript value.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public get value(): any {\n switch (this.type) {\n case SqliteValueType.Null:\n return undefined;\n case SqliteValueType.Blob:\n return this.getBlob();\n case SqliteValueType.Double:\n return this.getDouble();\n case SqliteValueType.Integer:\n return this.getInteger();\n case SqliteValueType.String:\n return this.getString();\n default:\n throw new Error(\"Unhandled SqliteValueType\");\n }\n }\n\n /** Get the value as BLOB */\n public getBlob(): Uint8Array { return this._stmt.getValueBlob(this._colIndex); }\n /** Get the value as a double value */\n public getDouble(): number { return this._stmt.getValueDouble(this._colIndex); }\n /** Get the value as a integer value */\n public getInteger(): number { return this._stmt.getValueInteger(this._colIndex); }\n /** Get the value as a string value */\n public getString(): string { return this._stmt.getValueString(this._colIndex); }\n /** Get the value as an Id value */\n public getId(): Id64String { return this._stmt.getValueId(this._colIndex); }\n /** Get the value as a Guid value */\n public getGuid(): GuidString { return this._stmt.getValueGuid(this._colIndex); }\n}\n\ninterface Statement {\n isPrepared: boolean;\n sql: string;\n dispose(): void;\n reset(): void;\n clearBindings(): void;\n}\n\n/** A cache for previously prepared SqliteStatements.\n * It only holds Statements after they are no longer in use, resetting and clearing their bindings before saving them.\n * When a request to use a statement from the cache is made, it is first removed from the cache.\n * @internal\n */\nexport class StatementCache<Stmt extends Statement> {\n private _cache: LRUMap<string, Stmt>;\n\n public constructor(maxCount = 40) {\n this._cache = new LRUMap<string, Stmt>(maxCount);\n }\n\n public get size() { return this._cache.size; }\n public addOrDispose(stmt: Stmt): void {\n assert(stmt.isPrepared);\n\n const existing = this._cache.get(stmt.sql);\n if (existing !== undefined) {\n stmt.dispose(); // we already have a statement with this sql cached, we can't save another one so just dispose it\n return;\n }\n if (this._cache.size >= this._cache.limit) {\n const oldest = this._cache.shift()!;\n oldest[1].dispose();\n }\n stmt.reset();\n stmt.clearBindings();\n this._cache.set(stmt.sql, stmt);\n }\n\n public findAndRemove(sql: string): Stmt | undefined {\n return this._cache.delete(sql);\n }\n\n public clear() {\n this._cache.forEach((stmt) => stmt.dispose());\n this._cache.clear();\n }\n}\n"]}
@@ -1,59 +1,59 @@
1
- /** @packageDocumentation
2
- * @module Elements
3
- */
4
- import { Id64String } from "@itwin/core-bentley";
5
- import { Base64EncodedString, Code, CodeScopeProps, ImageSourceFormat, TextureProps } from "@itwin/core-common";
6
- import { DefinitionElement } from "./Element";
7
- import { IModelDb } from "./IModelDb";
8
- /** A [TextureProps]($common) in which the image data can be specified either as a base-64-encoded string or a Uint8Array.
9
- * @see [[Texture]] constructor.
10
- * @internal
11
- */
12
- export interface TextureCreateProps extends Omit<TextureProps, "data"> {
13
- data: Base64EncodedString | Uint8Array;
14
- }
15
- /** Defines a rendering texture that is associated with a Material and applied to surface geometry.
16
- * @public
17
- */
18
- export declare class Texture extends DefinitionElement {
19
- /** @internal */
20
- static get className(): string;
21
- format: ImageSourceFormat;
22
- data: Uint8Array;
23
- description?: string;
24
- /** @internal */
25
- constructor(props: TextureCreateProps, iModel: IModelDb);
26
- /** @internal */
27
- toJSON(): TextureProps;
28
- /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.
29
- * @param iModel The IModelDb
30
- * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.
31
- * @param name The Texture name
32
- */
33
- static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code;
34
- /** Create a texture with the given parameters.
35
- * @param iModelDb The iModel to contain the texture.
36
- * @param definitionModelId The [[DefinitionModel]] to contain the texture.
37
- * @param name The name to serve as the texture's [Code]($common) value.
38
- * @param format The format of the image data.
39
- * @param data The image data in the format specified by `format`.
40
- * @param description An optional description of the texture
41
- * @returns The newly constructed Texture element.
42
- * @throws [[IModelError]] if unable to create the element.
43
- * @see [[insertTexture]] to insert a new texture into the iModel.
44
- */
45
- static createTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Texture;
46
- /** Insert a new texture into a [[DefinitionModel]].
47
- * @param iModelDb The iModel to contain the texture.
48
- * @param definitionModelId The [[DefinitionModel]] to contain the texture.
49
- * @param name The name to serve as the texture's [Code]($common) value.
50
- * @param format The format of the image data.
51
- * @param data The image data in the format specified by `format`.
52
- * @param description An optional description of the texture
53
- * @returns The Id of the newly-inserted texture element.
54
- * @throws [[IModelError]] if unable to insert the element.
55
- * @see [[insertTexture]] to insert a new texture into the iModel.
56
- */
57
- static insertTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Id64String;
58
- }
1
+ /** @packageDocumentation
2
+ * @module Elements
3
+ */
4
+ import { Id64String } from "@itwin/core-bentley";
5
+ import { Base64EncodedString, Code, CodeScopeProps, ImageSourceFormat, TextureProps } from "@itwin/core-common";
6
+ import { DefinitionElement } from "./Element";
7
+ import { IModelDb } from "./IModelDb";
8
+ /** A [TextureProps]($common) in which the image data can be specified either as a base-64-encoded string or a Uint8Array.
9
+ * @see [[Texture]] constructor.
10
+ * @internal
11
+ */
12
+ export interface TextureCreateProps extends Omit<TextureProps, "data"> {
13
+ data: Base64EncodedString | Uint8Array;
14
+ }
15
+ /** Defines a rendering texture that is associated with a Material and applied to surface geometry.
16
+ * @public
17
+ */
18
+ export declare class Texture extends DefinitionElement {
19
+ /** @internal */
20
+ static get className(): string;
21
+ format: ImageSourceFormat;
22
+ data: Uint8Array;
23
+ description?: string;
24
+ /** @internal */
25
+ constructor(props: TextureCreateProps, iModel: IModelDb);
26
+ /** @internal */
27
+ toJSON(): TextureProps;
28
+ /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.
29
+ * @param iModel The IModelDb
30
+ * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.
31
+ * @param name The Texture name
32
+ */
33
+ static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code;
34
+ /** Create a texture with the given parameters.
35
+ * @param iModelDb The iModel to contain the texture.
36
+ * @param definitionModelId The [[DefinitionModel]] to contain the texture.
37
+ * @param name The name to serve as the texture's [Code]($common) value.
38
+ * @param format The format of the image data.
39
+ * @param data The image data in the format specified by `format`.
40
+ * @param description An optional description of the texture
41
+ * @returns The newly constructed Texture element.
42
+ * @throws [[IModelError]] if unable to create the element.
43
+ * @see [[insertTexture]] to insert a new texture into the iModel.
44
+ */
45
+ static createTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Texture;
46
+ /** Insert a new texture into a [[DefinitionModel]].
47
+ * @param iModelDb The iModel to contain the texture.
48
+ * @param definitionModelId The [[DefinitionModel]] to contain the texture.
49
+ * @param name The name to serve as the texture's [Code]($common) value.
50
+ * @param format The format of the image data.
51
+ * @param data The image data in the format specified by `format`.
52
+ * @param description An optional description of the texture
53
+ * @returns The Id of the newly-inserted texture element.
54
+ * @throws [[IModelError]] if unable to insert the element.
55
+ * @see [[insertTexture]] to insert a new texture into the iModel.
56
+ */
57
+ static insertTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Id64String;
58
+ }
59
59
  //# sourceMappingURL=Texture.d.ts.map
@@ -1,83 +1,83 @@
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 Elements
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Texture = void 0;
11
- const core_common_1 = require("@itwin/core-common");
12
- const Element_1 = require("./Element");
13
- /** Defines a rendering texture that is associated with a Material and applied to surface geometry.
14
- * @public
15
- */
16
- class Texture extends Element_1.DefinitionElement {
17
- /** @internal */
18
- constructor(props, iModel) {
19
- super(props, iModel);
20
- this.format = props.format;
21
- this.data = typeof props.data === "string" ? core_common_1.Base64EncodedString.toUint8Array(props.data) : props.data;
22
- this.description = props.description;
23
- }
24
- /** @internal */
25
- static get className() { return "Texture"; }
26
- /** @internal */
27
- toJSON() {
28
- const val = super.toJSON();
29
- val.format = this.format;
30
- val.data = core_common_1.Base64EncodedString.fromUint8Array(this.data);
31
- val.description = this.description;
32
- return val;
33
- }
34
- /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.
35
- * @param iModel The IModelDb
36
- * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.
37
- * @param name The Texture name
38
- */
39
- static createCode(iModel, scopeModelId, name) {
40
- const codeSpec = iModel.codeSpecs.getByName(core_common_1.BisCodeSpec.texture);
41
- return 0 === name.length ? core_common_1.Code.createEmpty() : new core_common_1.Code({ spec: codeSpec.id, scope: scopeModelId, value: name });
42
- }
43
- /** Create a texture with the given parameters.
44
- * @param iModelDb The iModel to contain the texture.
45
- * @param definitionModelId The [[DefinitionModel]] to contain the texture.
46
- * @param name The name to serve as the texture's [Code]($common) value.
47
- * @param format The format of the image data.
48
- * @param data The image data in the format specified by `format`.
49
- * @param description An optional description of the texture
50
- * @returns The newly constructed Texture element.
51
- * @throws [[IModelError]] if unable to create the element.
52
- * @see [[insertTexture]] to insert a new texture into the iModel.
53
- */
54
- static createTexture(iModelDb, definitionModelId, name, format, data, description) {
55
- const textureProps = {
56
- classFullName: this.classFullName,
57
- code: this.createCode(iModelDb, definitionModelId, name),
58
- format,
59
- data,
60
- description,
61
- model: definitionModelId,
62
- isPrivate: false,
63
- };
64
- return new Texture(textureProps, iModelDb);
65
- }
66
- /** Insert a new texture into a [[DefinitionModel]].
67
- * @param iModelDb The iModel to contain the texture.
68
- * @param definitionModelId The [[DefinitionModel]] to contain the texture.
69
- * @param name The name to serve as the texture's [Code]($common) value.
70
- * @param format The format of the image data.
71
- * @param data The image data in the format specified by `format`.
72
- * @param description An optional description of the texture
73
- * @returns The Id of the newly-inserted texture element.
74
- * @throws [[IModelError]] if unable to insert the element.
75
- * @see [[insertTexture]] to insert a new texture into the iModel.
76
- */
77
- static insertTexture(iModelDb, definitionModelId, name, format, data, description) {
78
- const texture = this.createTexture(iModelDb, definitionModelId, name, format, data, description);
79
- return iModelDb.elements.insertElement(texture.toJSON());
80
- }
81
- }
82
- exports.Texture = Texture;
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 Elements
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Texture = void 0;
11
+ const core_common_1 = require("@itwin/core-common");
12
+ const Element_1 = require("./Element");
13
+ /** Defines a rendering texture that is associated with a Material and applied to surface geometry.
14
+ * @public
15
+ */
16
+ class Texture extends Element_1.DefinitionElement {
17
+ /** @internal */
18
+ constructor(props, iModel) {
19
+ super(props, iModel);
20
+ this.format = props.format;
21
+ this.data = typeof props.data === "string" ? core_common_1.Base64EncodedString.toUint8Array(props.data) : props.data;
22
+ this.description = props.description;
23
+ }
24
+ /** @internal */
25
+ static get className() { return "Texture"; }
26
+ /** @internal */
27
+ toJSON() {
28
+ const val = super.toJSON();
29
+ val.format = this.format;
30
+ val.data = core_common_1.Base64EncodedString.fromUint8Array(this.data);
31
+ val.description = this.description;
32
+ return val;
33
+ }
34
+ /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.
35
+ * @param iModel The IModelDb
36
+ * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.
37
+ * @param name The Texture name
38
+ */
39
+ static createCode(iModel, scopeModelId, name) {
40
+ const codeSpec = iModel.codeSpecs.getByName(core_common_1.BisCodeSpec.texture);
41
+ return 0 === name.length ? core_common_1.Code.createEmpty() : new core_common_1.Code({ spec: codeSpec.id, scope: scopeModelId, value: name });
42
+ }
43
+ /** Create a texture with the given parameters.
44
+ * @param iModelDb The iModel to contain the texture.
45
+ * @param definitionModelId The [[DefinitionModel]] to contain the texture.
46
+ * @param name The name to serve as the texture's [Code]($common) value.
47
+ * @param format The format of the image data.
48
+ * @param data The image data in the format specified by `format`.
49
+ * @param description An optional description of the texture
50
+ * @returns The newly constructed Texture element.
51
+ * @throws [[IModelError]] if unable to create the element.
52
+ * @see [[insertTexture]] to insert a new texture into the iModel.
53
+ */
54
+ static createTexture(iModelDb, definitionModelId, name, format, data, description) {
55
+ const textureProps = {
56
+ classFullName: this.classFullName,
57
+ code: this.createCode(iModelDb, definitionModelId, name),
58
+ format,
59
+ data,
60
+ description,
61
+ model: definitionModelId,
62
+ isPrivate: false,
63
+ };
64
+ return new Texture(textureProps, iModelDb);
65
+ }
66
+ /** Insert a new texture into a [[DefinitionModel]].
67
+ * @param iModelDb The iModel to contain the texture.
68
+ * @param definitionModelId The [[DefinitionModel]] to contain the texture.
69
+ * @param name The name to serve as the texture's [Code]($common) value.
70
+ * @param format The format of the image data.
71
+ * @param data The image data in the format specified by `format`.
72
+ * @param description An optional description of the texture
73
+ * @returns The Id of the newly-inserted texture element.
74
+ * @throws [[IModelError]] if unable to insert the element.
75
+ * @see [[insertTexture]] to insert a new texture into the iModel.
76
+ */
77
+ static insertTexture(iModelDb, definitionModelId, name, format, data, description) {
78
+ const texture = this.createTexture(iModelDb, definitionModelId, name, format, data, description);
79
+ return iModelDb.elements.insertElement(texture.toJSON());
80
+ }
81
+ }
82
+ exports.Texture = Texture;
83
83
  //# sourceMappingURL=Texture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../src/Texture.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;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,IAAI,EAAE,CAAC,CAAC;IACpH,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,aAAa,CAAC,QAAkB,EAAE,iBAA6B,EAAE,IAAY,EAAE,MAAyB,EAAE,IAAsC,EAAE,WAAoB;QAClL,MAAM,YAAY,GAAuB;YACvC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC;YACxD,MAAM;YACN,IAAI;YACJ,WAAW;YACX,KAAK,EAAE,iBAAiB;YACxB,SAAS,EAAE,KAAK;SACjB,CAAC;QAEF,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,aAAa,CAAC,QAAkB,EAAE,iBAA6B,EAAE,IAAY,EAAE,MAAyB,EAAE,IAAsC,EAAE,WAAoB;QAClL,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QACjG,OAAO,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF;AA1ED,0BA0EC","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 Elements\r\n */\r\n\r\nimport { Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n Base64EncodedString, BisCodeSpec, Code, CodeScopeProps, CodeSpec, ImageSourceFormat, TextureProps,\r\n} from \"@itwin/core-common\";\r\nimport { DefinitionElement } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/** A [TextureProps]($common) in which the image data can be specified either as a base-64-encoded string or a Uint8Array.\r\n * @see [[Texture]] constructor.\r\n * @internal\r\n */\r\nexport interface TextureCreateProps extends Omit<TextureProps, \"data\"> {\r\n data: Base64EncodedString | Uint8Array;\r\n}\r\n\r\n/** Defines a rendering texture that is associated with a Material and applied to surface geometry.\r\n * @public\r\n */\r\nexport class Texture extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"Texture\"; }\r\n public format: ImageSourceFormat;\r\n public data: Uint8Array;\r\n public description?: string;\r\n\r\n /** @internal */\r\n constructor(props: TextureCreateProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.format = props.format;\r\n this.data = typeof props.data === \"string\" ? Base64EncodedString.toUint8Array(props.data) : props.data;\r\n this.description = props.description;\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): TextureProps {\r\n const val = super.toJSON() as TextureProps;\r\n val.format = this.format;\r\n val.data = Base64EncodedString.fromUint8Array(this.data);\r\n val.description = this.description;\r\n return val;\r\n }\r\n\r\n /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModelDb\r\n * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.\r\n * @param name The Texture name\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.texture);\r\n return 0 === name.length ? Code.createEmpty() : new Code({ spec: codeSpec.id, scope: scopeModelId, value: name });\r\n }\r\n\r\n /** Create a texture with the given parameters.\r\n * @param iModelDb The iModel to contain the texture.\r\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\r\n * @param name The name to serve as the texture's [Code]($common) value.\r\n * @param format The format of the image data.\r\n * @param data The image data in the format specified by `format`.\r\n * @param description An optional description of the texture\r\n * @returns The newly constructed Texture element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n * @see [[insertTexture]] to insert a new texture into the iModel.\r\n */\r\n public static createTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Texture {\r\n const textureProps: TextureCreateProps = {\r\n classFullName: this.classFullName,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n format,\r\n data,\r\n description,\r\n model: definitionModelId,\r\n isPrivate: false,\r\n };\r\n\r\n return new Texture(textureProps, iModelDb);\r\n }\r\n\r\n /** Insert a new texture into a [[DefinitionModel]].\r\n * @param iModelDb The iModel to contain the texture.\r\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\r\n * @param name The name to serve as the texture's [Code]($common) value.\r\n * @param format The format of the image data.\r\n * @param data The image data in the format specified by `format`.\r\n * @param description An optional description of the texture\r\n * @returns The Id of the newly-inserted texture element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n * @see [[insertTexture]] to insert a new texture into the iModel.\r\n */\r\n public static insertTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Id64String {\r\n const texture = this.createTexture(iModelDb, definitionModelId, name, format, data, description);\r\n return iModelDb.elements.insertElement(texture.toJSON());\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../src/Texture.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oDAE4B;AAC5B,uCAA8C;AAW9C;;GAEG;AACH,MAAa,OAAQ,SAAQ,2BAAiB;IAO5C,gBAAgB;IAChB,YAAY,KAAyB,EAAE,MAAgB;QACrD,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,iCAAmB,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAA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AAK;SACjB,CAAC;QAEF,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,aAAa,CAAC,QAAkB,EAAE,iBAA6B,EAAE,IAAY,EAAE,MAAyB,EAAE,IAAsC,EAAE,WAAoB;QAClL,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QACjG,OAAO,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF;AA1ED,0BA0EC","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 Elements\n */\n\nimport { Id64String } from \"@itwin/core-bentley\";\nimport {\n Base64EncodedString, BisCodeSpec, Code, CodeScopeProps, CodeSpec, ImageSourceFormat, TextureProps,\n} from \"@itwin/core-common\";\nimport { DefinitionElement } from \"./Element\";\nimport { IModelDb } from \"./IModelDb\";\n\n/** A [TextureProps]($common) in which the image data can be specified either as a base-64-encoded string or a Uint8Array.\n * @see [[Texture]] constructor.\n * @internal\n */\nexport interface TextureCreateProps extends Omit<TextureProps, \"data\"> {\n data: Base64EncodedString | Uint8Array;\n}\n\n/** Defines a rendering texture that is associated with a Material and applied to surface geometry.\n * @public\n */\nexport class Texture extends DefinitionElement {\n /** @internal */\n public static override get className(): string { return \"Texture\"; }\n public format: ImageSourceFormat;\n public data: Uint8Array;\n public description?: string;\n\n /** @internal */\n constructor(props: TextureCreateProps, iModel: IModelDb) {\n super(props, iModel);\n this.format = props.format;\n this.data = typeof props.data === \"string\" ? Base64EncodedString.toUint8Array(props.data) : props.data;\n this.description = props.description;\n }\n\n /** @internal */\n public override toJSON(): TextureProps {\n const val = super.toJSON() as TextureProps;\n val.format = this.format;\n val.data = Base64EncodedString.fromUint8Array(this.data);\n val.description = this.description;\n return val;\n }\n\n /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.\n * @param iModel The IModelDb\n * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.\n * @param name The Texture name\n */\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code {\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.texture);\n return 0 === name.length ? Code.createEmpty() : new Code({ spec: codeSpec.id, scope: scopeModelId, value: name });\n }\n\n /** Create a texture with the given parameters.\n * @param iModelDb The iModel to contain the texture.\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\n * @param name The name to serve as the texture's [Code]($common) value.\n * @param format The format of the image data.\n * @param data The image data in the format specified by `format`.\n * @param description An optional description of the texture\n * @returns The newly constructed Texture element.\n * @throws [[IModelError]] if unable to create the element.\n * @see [[insertTexture]] to insert a new texture into the iModel.\n */\n public static createTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Texture {\n const textureProps: TextureCreateProps = {\n classFullName: this.classFullName,\n code: this.createCode(iModelDb, definitionModelId, name),\n format,\n data,\n description,\n model: definitionModelId,\n isPrivate: false,\n };\n\n return new Texture(textureProps, iModelDb);\n }\n\n /** Insert a new texture into a [[DefinitionModel]].\n * @param iModelDb The iModel to contain the texture.\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\n * @param name The name to serve as the texture's [Code]($common) value.\n * @param format The format of the image data.\n * @param data The image data in the format specified by `format`.\n * @param description An optional description of the texture\n * @returns The Id of the newly-inserted texture element.\n * @throws [[IModelError]] if unable to insert the element.\n * @see [[insertTexture]] to insert a new texture into the iModel.\n */\n public static insertTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Id64String {\n const texture = this.createTexture(iModelDb, definitionModelId, name, format, data, description);\n return iModelDb.elements.insertElement(texture.toJSON());\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { Metadata, ServerStorage, TransferConfig } from "@itwin/object-storage-core";
2
+ /** @beta */
3
+ export declare class TileStorage {
4
+ readonly storage: ServerStorage;
5
+ constructor(storage: ServerStorage);
6
+ private _initializedIModels;
7
+ initialize(iModelId: string): Promise<void>;
8
+ getDownloadConfig(iModelId: string, expiresInSeconds?: number): Promise<TransferConfig>;
9
+ uploadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, content: Uint8Array, guid?: string, metadata?: Metadata): Promise<void>;
10
+ downloadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<Uint8Array>;
11
+ getCachedTiles(iModelId: string, _prefix: string): Promise<{
12
+ treeId: string;
13
+ contentId: string;
14
+ guid?: string;
15
+ }[]>;
16
+ isTileCached(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<boolean>;
17
+ private logException;
18
+ }
19
+ //# sourceMappingURL=TileStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TileStorage.d.ts","sourceRoot":"","sources":["../../src/TileStorage.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAMrF,YAAY;AACZ,qBAAa,WAAW;aACa,OAAO,EAAE,aAAa;gBAAtB,OAAO,EAAE,aAAa;IAEzD,OAAO,CAAC,mBAAmB,CAA0B;IAExC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS3C,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IASvF,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5J,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAa1H,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAyBlH,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpI,OAAO,CAAC,YAAY;CAOrB"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TileStorage = 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
+ const zlib_1 = require("zlib");
9
+ const util_1 = require("util");
10
+ const core_common_1 = require("@itwin/core-common");
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
13
+ const IModelHost_1 = require("./IModelHost");
14
+ /** @beta */
15
+ class TileStorage {
16
+ constructor(storage) {
17
+ this.storage = storage;
18
+ this._initializedIModels = new Set();
19
+ }
20
+ async initialize(iModelId) {
21
+ if (this._initializedIModels.has(iModelId))
22
+ return;
23
+ if (!(await this.storage.baseDirectoryExists({ baseDirectory: iModelId }))) {
24
+ await this.storage.createBaseDirectory({ baseDirectory: iModelId });
25
+ }
26
+ this._initializedIModels.add(iModelId);
27
+ }
28
+ async getDownloadConfig(iModelId, expiresInSeconds) {
29
+ try {
30
+ return await this.storage.getDownloadConfig({ baseDirectory: iModelId }, expiresInSeconds);
31
+ }
32
+ catch (err) {
33
+ this.logException("Failed to get download config", err);
34
+ throw err;
35
+ }
36
+ }
37
+ async uploadTile(iModelId, changesetId, treeId, contentId, content, guid, metadata) {
38
+ try {
39
+ await this.storage.upload((0, core_common_1.getTileObjectReference)(iModelId, changesetId, treeId, contentId, guid), Buffer.from(IModelHost_1.IModelHost.compressCachedTiles ? await (0, util_1.promisify)(zlib_1.gzip)(content.buffer) : content.buffer), metadata);
40
+ }
41
+ catch (err) {
42
+ this.logException("Failed to upload tile", err);
43
+ throw err;
44
+ }
45
+ }
46
+ async downloadTile(iModelId, changesetId, treeId, contentId, guid) {
47
+ try {
48
+ const buffer = await this.storage.download((0, core_common_1.getTileObjectReference)(iModelId, changesetId, treeId, contentId, guid), "buffer");
49
+ return IModelHost_1.IModelHost.compressCachedTiles ? await (0, util_1.promisify)(zlib_1.gunzip)(buffer) : buffer;
50
+ }
51
+ catch (err) {
52
+ this.logException("Failed to download tile", err);
53
+ throw err;
54
+ }
55
+ }
56
+ async getCachedTiles(iModelId, _prefix) {
57
+ return (await this.storage.list({ baseDirectory: iModelId }))
58
+ .map((objectReference) => {
59
+ var _a, _b;
60
+ return ({
61
+ parts: (_b = (_a = objectReference.relativeDirectory) === null || _a === void 0 ? void 0 : _a.split("/")) !== null && _b !== void 0 ? _b : [""],
62
+ objectName: objectReference.objectName,
63
+ });
64
+ })
65
+ .filter(({ parts, objectName }) => {
66
+ if (parts[0] !== "tiles")
67
+ return false;
68
+ if (parts.length !== 3) {
69
+ core_bentley_1.Logger.logWarning(BackendLoggerCategory_1.BackendLoggerCategory.IModelTileStorage, "Malformed tile id found in tile cache: {tileId}", { tileId: [...parts, objectName].join("/") });
70
+ return false;
71
+ }
72
+ return true;
73
+ }).map(({ parts, objectName }) => {
74
+ // relativeDirectory = tiles/<treeId>/<guid>
75
+ // objectName = <contentId>
76
+ return {
77
+ treeId: parts[1],
78
+ contentId: objectName,
79
+ guid: parts[2],
80
+ };
81
+ });
82
+ }
83
+ async isTileCached(iModelId, changesetId, treeId, contentId, guid) {
84
+ return this.storage.objectExists((0, core_common_1.getTileObjectReference)(iModelId, changesetId, treeId, contentId, guid));
85
+ }
86
+ logException(message, err) {
87
+ core_bentley_1.Logger.logException(BackendLoggerCategory_1.BackendLoggerCategory.IModelTileStorage, err, (category, msg, errorMetadata) => core_bentley_1.Logger.logError(category, `${message}: {errorMessage}`, { ...errorMetadata, errorMessage: msg }));
88
+ }
89
+ }
90
+ exports.TileStorage = TileStorage;
91
+ //# sourceMappingURL=TileStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TileStorage.js","sourceRoot":"","sources":["../../src/TileStorage.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAAoC;AACpC,+BAAiC;AAEjC,oDAA4D;AAC5D,sDAA6C;AAC7C,mEAAgE;AAChE,6CAA0C;AAE1C,YAAY;AACZ,MAAa,WAAW;IACtB,YAAmC,OAAsB;QAAtB,YAAO,GAAP,OAAO,CAAe;QAEjD,wBAAmB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAFQ,CAAC;IAIvD,KAAK,CAAC,UAAU,CAAC,QAAgB;QACtC,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC;YACxC,OAAO;QACT,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE;YAC1E,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC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YAC/B,4CAA4C;YAC5C,2BAA2B;YAC3B,OAAO;gBACL,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;gBAChB,SAAS,EAAE,UAAU;gBACrB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aACf,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,WAAmB,EAAE,MAAc,EAAE,SAAiB,EAAE,IAAa;QAC/G,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAA,oCAAsB,EAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3G,CAAC;IAEO,YAAY,CAAC,OAAe,EAAE,GAAY;QAChD,qBAAM,CAAC,YAAY,CACjB,6CAAqB,CAAC,iBAAiB,EACvC,GAAG,EACH,CAAC,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC,qBAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,OAAO,kBAAkB,EAAE,EAAE,GAAG,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CACnI,CAAC;IACJ,CAAC;CACF;AArFD,kCAqFC","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*--------------------------------------------------------------------------------------------*/\nimport { gunzip, gzip } from \"zlib\";\nimport { promisify } from \"util\";\nimport { Metadata, ServerStorage, TransferConfig } from \"@itwin/object-storage-core\";\nimport { getTileObjectReference } from \"@itwin/core-common\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { IModelHost } from \"./IModelHost\";\n\n/** @beta */\nexport class TileStorage {\n public constructor(public readonly storage: ServerStorage) { }\n\n private _initializedIModels: Set<string> = new Set();\n\n public async initialize(iModelId: string): Promise<void> {\n if (this._initializedIModels.has(iModelId))\n return;\n if (!(await this.storage.baseDirectoryExists({ baseDirectory: iModelId }))) {\n await this.storage.createBaseDirectory({ baseDirectory: iModelId });\n }\n this._initializedIModels.add(iModelId);\n }\n\n public async getDownloadConfig(iModelId: string, expiresInSeconds?: number): Promise<TransferConfig> {\n try {\n return await this.storage.getDownloadConfig({ baseDirectory: iModelId }, expiresInSeconds);\n } catch (err) {\n this.logException(\"Failed to get download config\", err);\n throw err;\n }\n }\n\n public async uploadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, content: Uint8Array, guid?: string, metadata?: Metadata): Promise<void> {\n try {\n await this.storage.upload(\n getTileObjectReference(iModelId, changesetId, treeId, contentId, guid),\n Buffer.from(IModelHost.compressCachedTiles ? await promisify(gzip)(content.buffer) : content.buffer),\n metadata\n );\n } catch (err) {\n this.logException(\"Failed to upload tile\", err);\n throw err;\n }\n }\n\n public async downloadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<Uint8Array> {\n try {\n const buffer = await this.storage.download(\n getTileObjectReference(iModelId, changesetId, treeId, contentId, guid),\n \"buffer\"\n );\n return IModelHost.compressCachedTiles ? await promisify(gunzip)(buffer) : buffer;\n } catch (err) {\n this.logException(\"Failed to download tile\", err);\n throw err;\n }\n }\n\n public async getCachedTiles(iModelId: string, _prefix: string): Promise<{ treeId: string, contentId: string, guid?: string }[]> {\n return (await this.storage.list({ baseDirectory: iModelId }))\n .map((objectReference) => ({\n parts: objectReference.relativeDirectory?.split(\"/\") ?? [\"\"],\n objectName: objectReference.objectName,\n }))\n .filter(({ parts, objectName }) => {\n if (parts[0] !== \"tiles\")\n return false;\n if (parts.length !== 3) {\n Logger.logWarning(BackendLoggerCategory.IModelTileStorage, \"Malformed tile id found in tile cache: {tileId}\", { tileId: [...parts, objectName].join(\"/\") });\n return false;\n }\n return true;\n }).map(({ parts, objectName }) => {\n // relativeDirectory = tiles/<treeId>/<guid>\n // objectName = <contentId>\n return {\n treeId: parts[1],\n contentId: objectName,\n guid: parts[2],\n };\n });\n }\n\n public async isTileCached(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<boolean> {\n return this.storage.objectExists(getTileObjectReference(iModelId, changesetId, treeId, contentId, guid));\n }\n\n private logException(message: string, err: unknown): void {\n Logger.logException(\n BackendLoggerCategory.IModelTileStorage,\n err,\n (category, msg, errorMetadata) => Logger.logError(category, `${message}: {errorMessage}`, { ...errorMetadata, errorMessage: msg })\n );\n }\n}\n"]}