@itwin/core-backend 4.0.0-dev.10 → 4.0.0-dev.101

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 (295) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +226 -224
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +41 -41
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.d.ts +90 -91
  7. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.js +98 -99
  9. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  10. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  11. package/lib/cjs/BisCoreSchema.js +60 -60
  12. package/lib/cjs/BisCoreSchema.js.map +1 -1
  13. package/lib/cjs/BlobContainerService.d.ts +120 -0
  14. package/lib/cjs/BlobContainerService.d.ts.map +1 -0
  15. package/lib/cjs/BlobContainerService.js +18 -0
  16. package/lib/cjs/BlobContainerService.js.map +1 -0
  17. package/lib/cjs/BriefcaseManager.d.ts +184 -170
  18. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  19. package/lib/cjs/BriefcaseManager.js +421 -414
  20. package/lib/cjs/BriefcaseManager.js.map +1 -1
  21. package/lib/cjs/Category.d.ts +153 -153
  22. package/lib/cjs/Category.js +243 -243
  23. package/lib/cjs/Category.js.map +1 -1
  24. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  25. package/lib/cjs/ChangeSummaryManager.js +446 -447
  26. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  27. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  28. package/lib/cjs/ChangedElementsDb.js +165 -165
  29. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  30. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  31. package/lib/cjs/ChangedElementsManager.js +88 -88
  32. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  33. package/lib/cjs/ChannelControl.d.ts +70 -0
  34. package/lib/cjs/ChannelControl.d.ts.map +1 -0
  35. package/lib/cjs/ChannelControl.js +89 -0
  36. package/lib/cjs/ChannelControl.js.map +1 -0
  37. package/lib/cjs/CheckpointManager.d.ts +121 -121
  38. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  39. package/lib/cjs/CheckpointManager.js +351 -349
  40. package/lib/cjs/CheckpointManager.js.map +1 -1
  41. package/lib/cjs/ClassRegistry.d.ts +79 -79
  42. package/lib/cjs/ClassRegistry.js +254 -250
  43. package/lib/cjs/ClassRegistry.js.map +1 -1
  44. package/lib/cjs/CloudSqlite.d.ts +572 -350
  45. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  46. package/lib/cjs/CloudSqlite.js +374 -153
  47. package/lib/cjs/CloudSqlite.js.map +1 -1
  48. package/lib/cjs/CodeService.d.ts +399 -396
  49. package/lib/cjs/CodeService.d.ts.map +1 -1
  50. package/lib/cjs/CodeService.js +63 -63
  51. package/lib/cjs/CodeService.js.map +1 -1
  52. package/lib/cjs/CodeSpecs.d.ts +58 -55
  53. package/lib/cjs/CodeSpecs.d.ts.map +1 -1
  54. package/lib/cjs/CodeSpecs.js +154 -124
  55. package/lib/cjs/CodeSpecs.js.map +1 -1
  56. package/lib/cjs/ConcurrentQuery.d.ts +13 -13
  57. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
  58. package/lib/cjs/ConcurrentQuery.js +36 -36
  59. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  60. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  61. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  62. package/lib/cjs/CustomViewState3dCreator.js +80 -81
  63. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  64. package/lib/cjs/DevTools.d.ts +74 -71
  65. package/lib/cjs/DevTools.d.ts.map +1 -1
  66. package/lib/cjs/DevTools.js +156 -154
  67. package/lib/cjs/DevTools.js.map +1 -1
  68. package/lib/cjs/DisplayStyle.d.ts +104 -106
  69. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  70. package/lib/cjs/DisplayStyle.js +251 -256
  71. package/lib/cjs/DisplayStyle.js.map +1 -1
  72. package/lib/cjs/ECDb.d.ts +194 -191
  73. package/lib/cjs/ECDb.d.ts.map +1 -1
  74. package/lib/cjs/ECDb.js +351 -350
  75. package/lib/cjs/ECDb.js.map +1 -1
  76. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  77. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  78. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  79. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  80. package/lib/cjs/ECSqlStatement.d.ts +473 -473
  81. package/lib/cjs/ECSqlStatement.js +791 -791
  82. package/lib/cjs/ECSqlStatement.js.map +1 -1
  83. package/lib/cjs/Element.d.ts +1105 -1109
  84. package/lib/cjs/Element.d.ts.map +1 -1
  85. package/lib/cjs/Element.js +1416 -1427
  86. package/lib/cjs/Element.js.map +1 -1
  87. package/lib/cjs/ElementAspect.d.ts +175 -179
  88. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  89. package/lib/cjs/ElementAspect.js +202 -211
  90. package/lib/cjs/ElementAspect.js.map +1 -1
  91. package/lib/cjs/ElementGraphics.d.ts +9 -9
  92. package/lib/cjs/ElementGraphics.js +41 -41
  93. package/lib/cjs/ElementGraphics.js.map +1 -1
  94. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  95. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  96. package/lib/cjs/ElementTreeWalker.js +409 -409
  97. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  98. package/lib/cjs/Entity.d.ts +102 -106
  99. package/lib/cjs/Entity.d.ts.map +1 -1
  100. package/lib/cjs/Entity.js +118 -134
  101. package/lib/cjs/Entity.js.map +1 -1
  102. package/lib/cjs/EntityReferences.d.ts +49 -49
  103. package/lib/cjs/EntityReferences.d.ts.map +1 -1
  104. package/lib/cjs/EntityReferences.js +95 -95
  105. package/lib/cjs/EntityReferences.js.map +1 -1
  106. package/lib/cjs/ExportGraphics.d.ts +317 -317
  107. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  108. package/lib/cjs/ExportGraphics.js +208 -208
  109. package/lib/cjs/ExportGraphics.js.map +1 -1
  110. package/lib/cjs/ExternalSource.d.ts +95 -96
  111. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  112. package/lib/cjs/ExternalSource.js +130 -131
  113. package/lib/cjs/ExternalSource.js.map +1 -1
  114. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  115. package/lib/cjs/GeoCoordConfig.js +85 -85
  116. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  117. package/lib/cjs/GeometrySummary.d.ts +4 -4
  118. package/lib/cjs/GeometrySummary.js +380 -380
  119. package/lib/cjs/GeometrySummary.js.map +1 -1
  120. package/lib/cjs/HubMock.d.ts +94 -94
  121. package/lib/cjs/HubMock.js +220 -222
  122. package/lib/cjs/HubMock.js.map +1 -1
  123. package/lib/cjs/IModelCloneContext.d.ts +8 -8
  124. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  125. package/lib/cjs/IModelCloneContext.js +15 -15
  126. package/lib/cjs/IModelCloneContext.js.map +1 -1
  127. package/lib/cjs/IModelDb.d.ts +1222 -1196
  128. package/lib/cjs/IModelDb.d.ts.map +1 -1
  129. package/lib/cjs/IModelDb.js +2389 -2392
  130. package/lib/cjs/IModelDb.js.map +1 -1
  131. package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
  132. package/lib/cjs/IModelElementCloneContext.js +159 -159
  133. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  134. package/lib/cjs/IModelHost.d.ts +370 -369
  135. package/lib/cjs/IModelHost.d.ts.map +1 -1
  136. package/lib/cjs/IModelHost.js +476 -496
  137. package/lib/cjs/IModelHost.js.map +1 -1
  138. package/lib/cjs/IModelJsFs.d.ts +62 -62
  139. package/lib/cjs/IModelJsFs.js +139 -140
  140. package/lib/cjs/IModelJsFs.js.map +1 -1
  141. package/lib/cjs/IpcHost.d.ts +104 -104
  142. package/lib/cjs/IpcHost.js +276 -278
  143. package/lib/cjs/IpcHost.js.map +1 -1
  144. package/lib/cjs/LineStyle.d.ts +311 -311
  145. package/lib/cjs/LineStyle.js +295 -295
  146. package/lib/cjs/LineStyle.js.map +1 -1
  147. package/lib/cjs/LocalHub.d.ts +162 -162
  148. package/lib/cjs/LocalHub.d.ts.map +1 -1
  149. package/lib/cjs/LocalHub.js +580 -585
  150. package/lib/cjs/LocalHub.js.map +1 -1
  151. package/lib/cjs/LocalhostIpcHost.d.ts +21 -20
  152. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
  153. package/lib/cjs/LocalhostIpcHost.js +79 -81
  154. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  155. package/lib/cjs/Material.d.ts +131 -131
  156. package/lib/cjs/Material.d.ts.map +1 -1
  157. package/lib/cjs/Material.js +185 -181
  158. package/lib/cjs/Material.js.map +1 -1
  159. package/lib/cjs/Model.d.ts +391 -392
  160. package/lib/cjs/Model.d.ts.map +1 -1
  161. package/lib/cjs/Model.js +487 -485
  162. package/lib/cjs/Model.js.map +1 -1
  163. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  164. package/lib/cjs/NativeAppStorage.js +202 -202
  165. package/lib/cjs/NativeAppStorage.js.map +1 -1
  166. package/lib/cjs/NativeHost.d.ts +52 -52
  167. package/lib/cjs/NativeHost.d.ts.map +1 -1
  168. package/lib/cjs/NativeHost.js +158 -163
  169. package/lib/cjs/NativeHost.js.map +1 -1
  170. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  171. package/lib/cjs/NavigationRelationship.js +225 -225
  172. package/lib/cjs/NavigationRelationship.js.map +1 -1
  173. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  174. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  175. package/lib/cjs/PromiseMemoizer.js +101 -101
  176. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  177. package/lib/cjs/PropertyStore.d.ts +123 -132
  178. package/lib/cjs/PropertyStore.d.ts.map +1 -1
  179. package/lib/cjs/PropertyStore.js +179 -11
  180. package/lib/cjs/PropertyStore.js.map +1 -1
  181. package/lib/cjs/Relationship.d.ts +413 -416
  182. package/lib/cjs/Relationship.d.ts.map +1 -1
  183. package/lib/cjs/Relationship.js +491 -494
  184. package/lib/cjs/Relationship.js.map +1 -1
  185. package/lib/cjs/RpcBackend.d.ts +5 -5
  186. package/lib/cjs/RpcBackend.js +32 -32
  187. package/lib/cjs/RpcBackend.js.map +1 -1
  188. package/lib/cjs/SQLiteDb.d.ts +317 -219
  189. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  190. package/lib/cjs/SQLiteDb.js +318 -214
  191. package/lib/cjs/SQLiteDb.js.map +1 -1
  192. package/lib/cjs/Schema.d.ts +55 -55
  193. package/lib/cjs/Schema.js +83 -83
  194. package/lib/cjs/Schema.js.map +1 -1
  195. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  196. package/lib/cjs/ServerBasedLocks.js +168 -168
  197. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  198. package/lib/cjs/SqliteStatement.d.ts +360 -360
  199. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  200. package/lib/cjs/SqliteStatement.js +586 -586
  201. package/lib/cjs/SqliteStatement.js.map +1 -1
  202. package/lib/cjs/Texture.d.ts +58 -58
  203. package/lib/cjs/Texture.js +82 -82
  204. package/lib/cjs/Texture.js.map +1 -1
  205. package/lib/cjs/TileStorage.d.ts +44 -18
  206. package/lib/cjs/TileStorage.d.ts.map +1 -1
  207. package/lib/cjs/TileStorage.js +109 -90
  208. package/lib/cjs/TileStorage.js.map +1 -1
  209. package/lib/cjs/TxnManager.d.ts +202 -202
  210. package/lib/cjs/TxnManager.d.ts.map +1 -1
  211. package/lib/cjs/TxnManager.js +356 -356
  212. package/lib/cjs/TxnManager.js.map +1 -1
  213. package/lib/cjs/ViewDefinition.d.ts +429 -439
  214. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  215. package/lib/cjs/ViewDefinition.js +640 -646
  216. package/lib/cjs/ViewDefinition.js.map +1 -1
  217. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  218. package/lib/cjs/ViewStateHydrator.js +103 -103
  219. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  220. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  221. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  222. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  223. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  224. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  225. package/lib/cjs/core-backend.d.ts +181 -184
  226. package/lib/cjs/core-backend.d.ts.map +1 -1
  227. package/lib/cjs/core-backend.js +205 -204
  228. package/lib/cjs/core-backend.js.map +1 -1
  229. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  230. package/lib/cjs/domains/FunctionalElements.js +145 -145
  231. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  232. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  233. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
  234. package/lib/cjs/domains/FunctionalSchema.js +39 -40
  235. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  236. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  237. package/lib/cjs/domains/GenericElements.js +263 -263
  238. package/lib/cjs/domains/GenericElements.js.map +1 -1
  239. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  240. package/lib/cjs/domains/GenericSchema.js +28 -28
  241. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  242. package/lib/cjs/rpc/multipart.d.ts +11 -11
  243. package/lib/cjs/rpc/multipart.js +71 -71
  244. package/lib/cjs/rpc/multipart.js.map +1 -1
  245. package/lib/cjs/rpc/tracing.d.ts +28 -28
  246. package/lib/cjs/rpc/tracing.js +73 -74
  247. package/lib/cjs/rpc/tracing.js.map +1 -1
  248. package/lib/cjs/rpc/web/logging.d.ts +9 -9
  249. package/lib/cjs/rpc/web/logging.js +43 -43
  250. package/lib/cjs/rpc/web/logging.js.map +1 -1
  251. package/lib/cjs/rpc/web/request.d.ts +6 -6
  252. package/lib/cjs/rpc/web/request.js +73 -74
  253. package/lib/cjs/rpc/web/request.js.map +1 -1
  254. package/lib/cjs/rpc/web/response.d.ts +6 -6
  255. package/lib/cjs/rpc/web/response.js +105 -106
  256. package/lib/cjs/rpc/web/response.js.map +1 -1
  257. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  258. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  259. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  260. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
  261. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -294
  262. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  263. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +20 -22
  264. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  265. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -205
  266. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  267. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  268. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +166 -168
  269. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  270. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  271. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -43
  272. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  273. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  274. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  275. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  276. package/lib/cjs/workspace/Settings.d.ts +186 -186
  277. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  278. package/lib/cjs/workspace/Settings.js +155 -155
  279. package/lib/cjs/workspace/Settings.js.map +1 -1
  280. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  281. package/lib/cjs/workspace/SettingsSchemas.js +190 -191
  282. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  283. package/lib/cjs/workspace/Workspace.d.ts +411 -414
  284. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  285. package/lib/cjs/workspace/Workspace.js +521 -543
  286. package/lib/cjs/workspace/Workspace.js.map +1 -1
  287. package/package.json +25 -28
  288. package/lib/cjs/AliCloudStorageService.d.ts +0 -24
  289. package/lib/cjs/AliCloudStorageService.d.ts.map +0 -1
  290. package/lib/cjs/AliCloudStorageService.js +0 -72
  291. package/lib/cjs/AliCloudStorageService.js.map +0 -1
  292. package/lib/cjs/CloudStorageBackend.d.ts +0 -59
  293. package/lib/cjs/CloudStorageBackend.d.ts.map +0 -1
  294. package/lib/cjs/CloudStorageBackend.js +0 -174
  295. package/lib/cjs/CloudStorageBackend.js.map +0 -1
@@ -1,155 +1,157 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.DevTools = exports.DevToolsStatsFormatter = void 0;
8
- const os = require("os");
9
- const process = require("process");
10
- const core_bentley_1 = require("@itwin/core-bentley");
11
- const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
12
- const IModelHost_1 = require("./IModelHost");
13
- // cspell:ignore ppid elap
14
- const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.DevTools;
15
- /** Utility to format the JSON created by DevTools.stats() to include the appropriate units
16
- * @internal
17
- */
18
- class DevToolsStatsFormatter {
19
- /** Converts the input stats to another JSON object with the appropriate units setup for various fields */
20
- static toFormattedJson(stats) {
21
- // Serialize the stats to a string with a replacer that sets up units during the serialization
22
- const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);
23
- // Deserialize back to JSON
24
- return JSON.parse(statsStr);
25
- }
26
- }
27
- exports.DevToolsStatsFormatter = DevToolsStatsFormatter;
28
- DevToolsStatsFormatter._megaByteProps = ["totalmem", "freemem", "rss", "heapTotal", "heapUsed", "external"];
29
- DevToolsStatsFormatter._percentProps = ["user", "nice", "sys", "idle", "irq", "cpuUsage"];
30
- DevToolsStatsFormatter._mHzProps = ["speed"];
31
- DevToolsStatsFormatter._secondsProps = ["uptime"];
32
- /** Replacer that includes units - can be used with JSON.stringify() */
33
- DevToolsStatsFormatter._replacer = (key, value) => {
34
- if (DevToolsStatsFormatter._megaByteProps.includes(key))
35
- return `${value.toFixed()} MB`;
36
- if (DevToolsStatsFormatter._percentProps.includes(key))
37
- return `${value.toFixed()}%`;
38
- if (DevToolsStatsFormatter._mHzProps.includes(key))
39
- return `${value.toString()} MHz`;
40
- if (DevToolsStatsFormatter._secondsProps.includes(key))
41
- return `${value.toFixed()} secs`;
42
- return value;
43
- };
44
- /**
45
- * Internal diagnostic utility
46
- * @internal
47
- */
48
- class DevTools {
49
- /** Receives a ping and returns true */
50
- static ping() {
51
- core_bentley_1.Logger.logInfo(loggerCategory, "Received ping at backend");
52
- return true;
53
- }
54
- static hrtimeToMS(hrtime) {
55
- return hrtime[0] * 1000 + hrtime[1] / 1000000;
56
- }
57
- static bytesToMegaBytes(bytes) {
58
- const megaBytes = bytes / Math.pow(1024, 2);
59
- return Math.round(megaBytes * 100) / 100;
60
- }
61
- static evaluateCpuUsage() {
62
- const NUMBER_OF_CPUS = os.cpus().length;
63
- const startTime = process.hrtime();
64
- const startUsage = process.cpuUsage();
65
- // spin the CPU for 500 milliseconds
66
- const now = Date.now();
67
- while (Date.now() - now < 500)
68
- ;
69
- const elapTime = process.hrtime(startTime);
70
- const elapUsage = process.cpuUsage(startUsage);
71
- const elapTimeMS = this.hrtimeToMS(elapTime);
72
- const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds
73
- const elapSystMS = elapUsage.system / 1000;
74
- const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));
75
- return cpuPercent;
76
- }
77
- static evaluateCpus() {
78
- // Create a clone
79
- const srcCpus = os.cpus();
80
- const cpus = new Array(srcCpus.length);
81
- let ii = 0;
82
- for (const srcCpu of srcCpus)
83
- cpus[ii++] = { ...srcCpu };
84
- // Evaluate cpu usage as percentages
85
- for (const cpu of Object.values(cpus)) {
86
- const total = Object.values(cpu.times).reduce((_total, currValue) => _total += currValue, 0);
87
- const cpuTimes = cpu.times;
88
- for (const type of Object.keys(cpuTimes)) {
89
- const cpuPercent = Math.round(100 * cpuTimes[type] / total);
90
- cpuTimes[type] = cpuPercent;
91
- }
92
- }
93
- return cpus;
94
- }
95
- static evaluateMemoryUsage() {
96
- // Create a clone
97
- const memUsage = { ...process.memoryUsage() };
98
- const memUsageObj = memUsage;
99
- // Evaluate memory usage as mega bytes
100
- for (const type of Object.keys(memUsageObj)) {
101
- memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);
102
- }
103
- return memUsage;
104
- }
105
- static evaluateProcessStats() {
106
- return {
107
- uptime: process.uptime(),
108
- pid: process.pid,
109
- ppid: process.ppid,
110
- memoryUsage: this.evaluateMemoryUsage(),
111
- };
112
- }
113
- static evaluateOsStats() {
114
- return {
115
- platform: os.platform(),
116
- hostname: os.hostname(),
117
- totalmem: this.bytesToMegaBytes(os.totalmem()),
118
- freemem: this.bytesToMegaBytes(os.freemem()),
119
- uptime: os.uptime(),
120
- cpus: this.evaluateCpus(),
121
- cpuUsage: this.evaluateCpuUsage(),
122
- };
123
- }
124
- /** Returns JSON object with backend statistics */
125
- static stats() {
126
- try {
127
- const stats = {
128
- os: this.evaluateOsStats(),
129
- process: this.evaluateProcessStats(),
130
- };
131
- return stats;
132
- }
133
- catch (error) {
134
- core_bentley_1.Logger.logError(loggerCategory, "Could not fetch stats at backend");
135
- throw error;
136
- }
137
- }
138
- /** Sets up a log level at the backend and returns the old log level */
139
- static setLogLevel(inLoggerCategory, newLevel) {
140
- const oldLevel = core_bentley_1.Logger.getLevel(inLoggerCategory);
141
- core_bentley_1.Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));
142
- core_bentley_1.Logger.setLevel(inLoggerCategory, newLevel);
143
- IModelHost_1.IModelHost.platform.clearLogLevelCache();
144
- return oldLevel;
145
- }
146
- /** Obtains the backend application and iTwin.js Core versions */
147
- static versions() {
148
- return {
149
- application: IModelHost_1.IModelHost.applicationVersion,
150
- iTwinJs: require("../../package.json").version, // eslint-disable-line @typescript-eslint/no-var-requires
151
- };
152
- }
153
- }
154
- exports.DevTools = DevTools;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DevTools = exports.DevToolsStatsFormatter = void 0;
8
+ const os = require("os");
9
+ const process = require("process");
10
+ const core_bentley_1 = require("@itwin/core-bentley");
11
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
12
+ const IModelHost_1 = require("./IModelHost");
13
+ // cspell:ignore ppid elap
14
+ const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.DevTools;
15
+ /** Utility to format the JSON created by DevTools.stats() to include the appropriate units
16
+ * @internal
17
+ */
18
+ class DevToolsStatsFormatter {
19
+ /** Converts the input stats to another JSON object with the appropriate units setup for various fields */
20
+ static toFormattedJson(stats) {
21
+ // Serialize the stats to a string with a replacer that sets up units during the serialization
22
+ const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);
23
+ // Deserialize back to JSON
24
+ return JSON.parse(statsStr);
25
+ }
26
+ }
27
+ DevToolsStatsFormatter._megaByteProps = ["totalmem", "freemem", "rss", "heapTotal", "heapUsed", "external"];
28
+ DevToolsStatsFormatter._percentProps = ["user", "nice", "sys", "idle", "irq", "cpuUsage"];
29
+ DevToolsStatsFormatter._mHzProps = ["speed"];
30
+ DevToolsStatsFormatter._secondsProps = ["uptime"];
31
+ /** Replacer that includes units - can be used with JSON.stringify() */
32
+ DevToolsStatsFormatter._replacer = (key, value) => {
33
+ if (DevToolsStatsFormatter._megaByteProps.includes(key))
34
+ return `${value.toFixed()} MB`;
35
+ if (DevToolsStatsFormatter._percentProps.includes(key))
36
+ return `${value.toFixed()}%`;
37
+ if (DevToolsStatsFormatter._mHzProps.includes(key))
38
+ return `${value.toString()} MHz`;
39
+ if (DevToolsStatsFormatter._secondsProps.includes(key))
40
+ return `${value.toFixed()} secs`;
41
+ return value;
42
+ };
43
+ exports.DevToolsStatsFormatter = DevToolsStatsFormatter;
44
+ /**
45
+ * Internal diagnostic utility
46
+ * @internal
47
+ */
48
+ class DevTools {
49
+ /** Receives a ping and returns true */
50
+ static ping() {
51
+ core_bentley_1.Logger.logInfo(loggerCategory, "Received ping at backend");
52
+ return true;
53
+ }
54
+ static hrtimeToMS(hrtime) {
55
+ return hrtime[0] * 1000 + hrtime[1] / 1000000;
56
+ }
57
+ static bytesToMegaBytes(bytes) {
58
+ const megaBytes = bytes / Math.pow(1024, 2);
59
+ return Math.round(megaBytes * 100) / 100;
60
+ }
61
+ static evaluateCpuUsage() {
62
+ const NUMBER_OF_CPUS = os.cpus().length;
63
+ const startTime = process.hrtime();
64
+ const startUsage = process.cpuUsage();
65
+ // spin the CPU for 500 milliseconds
66
+ const now = Date.now();
67
+ while (Date.now() - now < 500)
68
+ ;
69
+ const elapTime = process.hrtime(startTime);
70
+ const elapUsage = process.cpuUsage(startUsage);
71
+ const elapTimeMS = this.hrtimeToMS(elapTime);
72
+ const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds
73
+ const elapSystMS = elapUsage.system / 1000;
74
+ const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));
75
+ return cpuPercent;
76
+ }
77
+ static evaluateCpus() {
78
+ // Create a clone
79
+ const srcCpus = os.cpus();
80
+ const cpus = new Array(srcCpus.length);
81
+ let ii = 0;
82
+ for (const srcCpu of srcCpus)
83
+ cpus[ii++] = { ...srcCpu };
84
+ // Evaluate cpu usage as percentages
85
+ for (const cpu of Object.values(cpus)) {
86
+ const total = Object.values(cpu.times).reduce((_total, currValue) => _total += currValue, 0);
87
+ const cpuTimes = cpu.times;
88
+ for (const type of Object.keys(cpuTimes)) {
89
+ const cpuPercent = Math.round(100 * cpuTimes[type] / total);
90
+ cpuTimes[type] = cpuPercent;
91
+ }
92
+ }
93
+ return cpus;
94
+ }
95
+ static evaluateMemoryUsage() {
96
+ // Create a clone
97
+ const memUsage = { ...process.memoryUsage() };
98
+ const memUsageObj = memUsage;
99
+ // Evaluate memory usage as mega bytes
100
+ for (const type of Object.keys(memUsageObj)) {
101
+ memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);
102
+ }
103
+ return memUsage;
104
+ }
105
+ static evaluateProcessStats() {
106
+ return {
107
+ uptime: process.uptime(),
108
+ pid: process.pid,
109
+ ppid: process.ppid,
110
+ memoryUsage: this.evaluateMemoryUsage(),
111
+ };
112
+ }
113
+ static evaluateOsStats() {
114
+ return {
115
+ platform: os.platform(),
116
+ hostname: os.hostname(),
117
+ totalmem: this.bytesToMegaBytes(os.totalmem()),
118
+ freemem: this.bytesToMegaBytes(os.freemem()),
119
+ uptime: os.uptime(),
120
+ cpus: this.evaluateCpus(),
121
+ cpuUsage: this.evaluateCpuUsage(),
122
+ };
123
+ }
124
+ /** Returns JSON object with backend statistics */
125
+ static stats() {
126
+ try {
127
+ const stats = {
128
+ os: this.evaluateOsStats(),
129
+ process: this.evaluateProcessStats(),
130
+ };
131
+ return stats;
132
+ }
133
+ catch (error) {
134
+ core_bentley_1.Logger.logError(loggerCategory, "Could not fetch stats at backend");
135
+ throw error;
136
+ }
137
+ }
138
+ /** Sets up a log level at the backend and returns the old log level */
139
+ static setLogLevel(inLoggerCategory, newLevel) {
140
+ const oldLevel = core_bentley_1.Logger.getLevel(inLoggerCategory);
141
+ core_bentley_1.Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));
142
+ core_bentley_1.Logger.setLevel(inLoggerCategory, newLevel);
143
+ IModelHost_1.IModelHost.platform.clearLogLevelCache();
144
+ return oldLevel;
145
+ }
146
+ /** Obtains the backend application and iTwin.js Core versions */
147
+ static async versions() {
148
+ const availableRpcs = [];
149
+ return {
150
+ application: IModelHost_1.IModelHost.applicationVersion,
151
+ iTwinJs: require("../../package.json").version,
152
+ availableRpcs, // filled in on the frontend
153
+ };
154
+ }
155
+ }
156
+ exports.DevTools = DevTools;
155
157
  //# sourceMappingURL=DevTools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DevTools.js","sourceRoot":"","sources":["../../src/DevTools.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,mCAAmC;AACnC,sDAAuD;AACvD,mEAAgE;AAChE,6CAA0C;AAE1C,0BAA0B;AAE1B,MAAM,cAAc,GAAW,6CAAqB,CAAC,QAAQ,CAAC;AAwC9D;;GAEG;AACH,MAAa,sBAAsB;IAmBjC,0GAA0G;IACnG,MAAM,CAAC,eAAe,CAAC,KAAU;QACtC,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAEzE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,EAAE,CAAC,CAAC,CAAC;QACtH,qBAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAC5C,uBAAU,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QACzC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,iEAAiE;IAC1D,MAAM,CAAC,QAAQ;QACpB,OAAO;YACL,WAAW,EAAE,uBAAU,CAAC,kBAAkB;YAC1C,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,EAAE,yDAAyD;SAC1G,CAAC;IACJ,CAAC;CACF;AAzHD,4BAyHC","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\r\nimport * as os from \"os\";\r\nimport * as process from \"process\";\r\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n// cspell:ignore ppid elap\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.DevTools;\r\n\r\ninterface StringIndexedObject<T> {\r\n [index: string]: T;\r\n}\r\n\r\n/**\r\n * Performance and Memory statistics of backend\r\n * @internal\r\n */\r\nexport interface DevToolsStats {\r\n os: DevToolsOsStats;\r\n process: DevToolsProcessStats;\r\n}\r\n\r\n/**\r\n * OS stats of backend\r\n * @internal\r\n */\r\nexport interface DevToolsOsStats {\r\n platform: NodeJS.Platform;\r\n hostname: string;\r\n totalmem: number;\r\n freemem: number;\r\n uptime: number;\r\n cpus: os.CpuInfo[];\r\n cpuUsage: number;\r\n}\r\n\r\n/**\r\n * Process stats of backend\r\n * @internal\r\n */\r\nexport interface DevToolsProcessStats {\r\n uptime: number;\r\n pid: number;\r\n ppid: number;\r\n memoryUsage: NodeJS.MemoryUsage;\r\n}\r\n\r\n/** Utility to format the JSON created by DevTools.stats() to include the appropriate units\r\n * @internal\r\n */\r\nexport class DevToolsStatsFormatter {\r\n private static readonly _megaByteProps = [\"totalmem\", \"freemem\", \"rss\", \"heapTotal\", \"heapUsed\", \"external\"];\r\n private static readonly _percentProps = [\"user\", \"nice\", \"sys\", \"idle\", \"irq\", \"cpuUsage\"];\r\n private static readonly _mHzProps = [\"speed\"];\r\n private static readonly _secondsProps = [\"uptime\"];\r\n\r\n /** Replacer that includes units - can be used with JSON.stringify() */\r\n private static _replacer = (key: string, value: any) => {\r\n if (DevToolsStatsFormatter._megaByteProps.includes(key))\r\n return `${value.toFixed()} MB`;\r\n if (DevToolsStatsFormatter._percentProps.includes(key))\r\n return `${value.toFixed()}%`;\r\n if (DevToolsStatsFormatter._mHzProps.includes(key))\r\n return `${value.toString()} MHz`;\r\n if (DevToolsStatsFormatter._secondsProps.includes(key))\r\n return `${value.toFixed()} secs`;\r\n return value;\r\n };\r\n\r\n /** Converts the input stats to another JSON object with the appropriate units setup for various fields */\r\n public static toFormattedJson(stats: any) {\r\n // Serialize the stats to a string with a replacer that sets up units during the serialization\r\n const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);\r\n\r\n // Deserialize back to JSON\r\n return JSON.parse(statsStr);\r\n }\r\n}\r\n\r\n/**\r\n * Internal diagnostic utility\r\n * @internal\r\n */\r\nexport class DevTools {\r\n\r\n /** Receives a ping and returns true */\r\n public static ping(): boolean {\r\n Logger.logInfo(loggerCategory, \"Received ping at backend\");\r\n return true;\r\n }\r\n\r\n private static hrtimeToMS(hrtime: any) {\r\n return hrtime[0] * 1000 + hrtime[1] / 1000000;\r\n }\r\n\r\n private static bytesToMegaBytes(bytes: number): number {\r\n const megaBytes = bytes / Math.pow(1024, 2);\r\n return Math.round(megaBytes * 100) / 100;\r\n }\r\n\r\n private static evaluateCpuUsage(): number {\r\n const NUMBER_OF_CPUS = os.cpus().length;\r\n const startTime = process.hrtime();\r\n const startUsage = process.cpuUsage();\r\n\r\n // spin the CPU for 500 milliseconds\r\n const now = Date.now();\r\n while (Date.now() - now < 500)\r\n ;\r\n\r\n const elapTime = process.hrtime(startTime);\r\n const elapUsage = process.cpuUsage(startUsage);\r\n\r\n const elapTimeMS = this.hrtimeToMS(elapTime);\r\n\r\n const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds\r\n const elapSystMS = elapUsage.system / 1000;\r\n const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));\r\n\r\n return cpuPercent;\r\n }\r\n\r\n private static evaluateCpus(): os.CpuInfo[] {\r\n // Create a clone\r\n const srcCpus = os.cpus();\r\n const cpus = new Array<os.CpuInfo>(srcCpus.length);\r\n let ii = 0;\r\n for (const srcCpu of srcCpus)\r\n cpus[ii++] = { ...srcCpu };\r\n\r\n // Evaluate cpu usage as percentages\r\n for (const cpu of Object.values(cpus)) {\r\n const total = Object.values(cpu.times).reduce((_total: number, currValue) => _total += currValue, 0);\r\n const cpuTimes = cpu.times as StringIndexedObject<number>;\r\n for (const type of Object.keys(cpuTimes)) {\r\n const cpuPercent = Math.round(100 * cpuTimes[type] / total);\r\n cpuTimes[type] = cpuPercent;\r\n }\r\n }\r\n return cpus;\r\n }\r\n\r\n private static evaluateMemoryUsage() {\r\n // Create a clone\r\n const memUsage = { ...process.memoryUsage() } as NodeJS.MemoryUsage;\r\n const memUsageObj = (memUsage as any) as StringIndexedObject<number>;\r\n // Evaluate memory usage as mega bytes\r\n for (const type of Object.keys(memUsageObj)) {\r\n memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);\r\n }\r\n return memUsage;\r\n }\r\n\r\n private static evaluateProcessStats(): DevToolsProcessStats {\r\n return {\r\n uptime: process.uptime(),\r\n pid: process.pid,\r\n ppid: process.ppid,\r\n memoryUsage: this.evaluateMemoryUsage(),\r\n } as DevToolsProcessStats;\r\n }\r\n\r\n private static evaluateOsStats(): DevToolsOsStats {\r\n return {\r\n platform: os.platform(),\r\n hostname: os.hostname(),\r\n totalmem: this.bytesToMegaBytes(os.totalmem()),\r\n freemem: this.bytesToMegaBytes(os.freemem()),\r\n uptime: os.uptime(),\r\n cpus: this.evaluateCpus(),\r\n cpuUsage: this.evaluateCpuUsage(),\r\n } as DevToolsOsStats;\r\n }\r\n\r\n /** Returns JSON object with backend statistics */\r\n public static stats(): DevToolsStats {\r\n try {\r\n const stats = {\r\n os: this.evaluateOsStats(),\r\n process: this.evaluateProcessStats(),\r\n } as DevToolsStats;\r\n return stats;\r\n } catch (error) {\r\n Logger.logError(loggerCategory, \"Could not fetch stats at backend\");\r\n throw error;\r\n }\r\n }\r\n\r\n /** Sets up a log level at the backend and returns the old log level */\r\n public static setLogLevel(inLoggerCategory: string, newLevel: LogLevel): LogLevel | undefined {\r\n const oldLevel = Logger.getLevel(inLoggerCategory);\r\n Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));\r\n Logger.setLevel(inLoggerCategory, newLevel);\r\n IModelHost.platform.clearLogLevelCache();\r\n return oldLevel;\r\n }\r\n\r\n /** Obtains the backend application and iTwin.js Core versions */\r\n public static versions() {\r\n return {\r\n application: IModelHost.applicationVersion,\r\n iTwinJs: require(\"../../package.json\").version, // eslint-disable-line @typescript-eslint/no-var-requires\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"DevTools.js","sourceRoot":"","sources":["../../src/DevTools.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,mCAAmC;AACnC,sDAAuD;AACvD,mEAAgE;AAChE,6CAA0C;AAG1C,0BAA0B;AAE1B,MAAM,cAAc,GAAW,6CAAqB,CAAC,QAAQ,CAAC;AAwC9D;;GAEG;AACH,MAAa,sBAAsB;IAmBjC,0GAA0G;IACnG,MAAM,CAAC,eAAe,CAAC,KAAU;QACtC,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,sBAAsB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BAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QACtH,qBAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAC5C,uBAAU,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QACzC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,iEAAiE;IAC1D,MAAM,CAAC,KAAK,CAAC,QAAQ;QAC1B,MAAM,aAAa,GAA4B,EAAE,CAAC;QAClD,OAAO;YACL,WAAW,EAAE,uBAAU,CAAC,kBAAkB;YAC1C,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO;YAC9C,aAAa,EAAE,4BAA4B;SAC5C,CAAC;IACJ,CAAC;CACF;AA3HD,4BA2HC","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\nimport * as os from \"os\";\nimport * as process from \"process\";\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { IModelHost } from \"./IModelHost\";\nimport { RpcInterfaceEndpoints } from \"@itwin/core-common\";\n\n// cspell:ignore ppid elap\n\nconst loggerCategory: string = BackendLoggerCategory.DevTools;\n\ninterface StringIndexedObject<T> {\n [index: string]: T;\n}\n\n/**\n * Performance and Memory statistics of backend\n * @internal\n */\nexport interface DevToolsStats {\n os: DevToolsOsStats;\n process: DevToolsProcessStats;\n}\n\n/**\n * OS stats of backend\n * @internal\n */\nexport interface DevToolsOsStats {\n platform: NodeJS.Platform;\n hostname: string;\n totalmem: number;\n freemem: number;\n uptime: number;\n cpus: os.CpuInfo[];\n cpuUsage: number;\n}\n\n/**\n * Process stats of backend\n * @internal\n */\nexport interface DevToolsProcessStats {\n uptime: number;\n pid: number;\n ppid: number;\n memoryUsage: NodeJS.MemoryUsage;\n}\n\n/** Utility to format the JSON created by DevTools.stats() to include the appropriate units\n * @internal\n */\nexport class DevToolsStatsFormatter {\n private static readonly _megaByteProps = [\"totalmem\", \"freemem\", \"rss\", \"heapTotal\", \"heapUsed\", \"external\"];\n private static readonly _percentProps = [\"user\", \"nice\", \"sys\", \"idle\", \"irq\", \"cpuUsage\"];\n private static readonly _mHzProps = [\"speed\"];\n private static readonly _secondsProps = [\"uptime\"];\n\n /** Replacer that includes units - can be used with JSON.stringify() */\n private static _replacer = (key: string, value: any) => {\n if (DevToolsStatsFormatter._megaByteProps.includes(key))\n return `${value.toFixed()} MB`;\n if (DevToolsStatsFormatter._percentProps.includes(key))\n return `${value.toFixed()}%`;\n if (DevToolsStatsFormatter._mHzProps.includes(key))\n return `${value.toString()} MHz`;\n if (DevToolsStatsFormatter._secondsProps.includes(key))\n return `${value.toFixed()} secs`;\n return value;\n };\n\n /** Converts the input stats to another JSON object with the appropriate units setup for various fields */\n public static toFormattedJson(stats: any) {\n // Serialize the stats to a string with a replacer that sets up units during the serialization\n const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);\n\n // Deserialize back to JSON\n return JSON.parse(statsStr);\n }\n}\n\n/**\n * Internal diagnostic utility\n * @internal\n */\nexport class DevTools {\n\n /** Receives a ping and returns true */\n public static ping(): boolean {\n Logger.logInfo(loggerCategory, \"Received ping at backend\");\n return true;\n }\n\n private static hrtimeToMS(hrtime: any) {\n return hrtime[0] * 1000 + hrtime[1] / 1000000;\n }\n\n private static bytesToMegaBytes(bytes: number): number {\n const megaBytes = bytes / Math.pow(1024, 2);\n return Math.round(megaBytes * 100) / 100;\n }\n\n private static evaluateCpuUsage(): number {\n const NUMBER_OF_CPUS = os.cpus().length;\n const startTime = process.hrtime();\n const startUsage = process.cpuUsage();\n\n // spin the CPU for 500 milliseconds\n const now = Date.now();\n while (Date.now() - now < 500)\n ;\n\n const elapTime = process.hrtime(startTime);\n const elapUsage = process.cpuUsage(startUsage);\n\n const elapTimeMS = this.hrtimeToMS(elapTime);\n\n const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds\n const elapSystMS = elapUsage.system / 1000;\n const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));\n\n return cpuPercent;\n }\n\n private static evaluateCpus(): os.CpuInfo[] {\n // Create a clone\n const srcCpus = os.cpus();\n const cpus = new Array<os.CpuInfo>(srcCpus.length);\n let ii = 0;\n for (const srcCpu of srcCpus)\n cpus[ii++] = { ...srcCpu };\n\n // Evaluate cpu usage as percentages\n for (const cpu of Object.values(cpus)) {\n const total = Object.values(cpu.times).reduce((_total: number, currValue) => _total += currValue, 0);\n const cpuTimes = cpu.times as StringIndexedObject<number>;\n for (const type of Object.keys(cpuTimes)) {\n const cpuPercent = Math.round(100 * cpuTimes[type] / total);\n cpuTimes[type] = cpuPercent;\n }\n }\n return cpus;\n }\n\n private static evaluateMemoryUsage() {\n // Create a clone\n const memUsage = { ...process.memoryUsage() } as NodeJS.MemoryUsage;\n const memUsageObj = (memUsage as any) as StringIndexedObject<number>;\n // Evaluate memory usage as mega bytes\n for (const type of Object.keys(memUsageObj)) {\n memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);\n }\n return memUsage;\n }\n\n private static evaluateProcessStats(): DevToolsProcessStats {\n return {\n uptime: process.uptime(),\n pid: process.pid,\n ppid: process.ppid,\n memoryUsage: this.evaluateMemoryUsage(),\n } as DevToolsProcessStats;\n }\n\n private static evaluateOsStats(): DevToolsOsStats {\n return {\n platform: os.platform(),\n hostname: os.hostname(),\n totalmem: this.bytesToMegaBytes(os.totalmem()),\n freemem: this.bytesToMegaBytes(os.freemem()),\n uptime: os.uptime(),\n cpus: this.evaluateCpus(),\n cpuUsage: this.evaluateCpuUsage(),\n } as DevToolsOsStats;\n }\n\n /** Returns JSON object with backend statistics */\n public static stats(): DevToolsStats {\n try {\n const stats = {\n os: this.evaluateOsStats(),\n process: this.evaluateProcessStats(),\n } as DevToolsStats;\n return stats;\n } catch (error) {\n Logger.logError(loggerCategory, \"Could not fetch stats at backend\");\n throw error;\n }\n }\n\n /** Sets up a log level at the backend and returns the old log level */\n public static setLogLevel(inLoggerCategory: string, newLevel: LogLevel): LogLevel | undefined {\n const oldLevel = Logger.getLevel(inLoggerCategory);\n Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));\n Logger.setLevel(inLoggerCategory, newLevel);\n IModelHost.platform.clearLogLevelCache();\n return oldLevel;\n }\n\n /** Obtains the backend application and iTwin.js Core versions */\n public static async versions() {\n const availableRpcs: RpcInterfaceEndpoints[] = [];\n return {\n application: IModelHost.applicationVersion,\n iTwinJs: require(\"../../package.json\").version, // eslint-disable-line @typescript-eslint/no-var-requires\n availableRpcs, // filled in on the frontend\n };\n }\n}\n"]}
@@ -1,107 +1,105 @@
1
- /** @packageDocumentation
2
- * @module ViewDefinitions
3
- */
4
- import { Id64String } from "@itwin/core-bentley";
5
- import { Code, CodeScopeProps, ColorDef, DisplayStyle3dProps, DisplayStyle3dSettings, DisplayStyle3dSettingsProps, DisplayStyleProps, DisplayStyleSettings, EntityReferenceSet, RenderSchedule, ViewFlags } from "@itwin/core-common";
6
- import { DefinitionElement } from "./Element";
7
- import { IModelDb } from "./IModelDb";
8
- import { IModelElementCloneContext } from "./IModelElementCloneContext";
9
- /** A DisplayStyle defines the parameters for 'styling' the contents of a view.
10
- * Internally a DisplayStyle consists of a dictionary of several named 'styles' describing specific aspects of the display style as a whole.
11
- * Many ViewDefinitions may share the same DisplayStyle.
12
- * @public
13
- */
14
- export declare abstract class DisplayStyle extends DefinitionElement {
15
- /** @internal */
16
- static get className(): string;
17
- abstract get settings(): DisplayStyleSettings;
18
- /** @internal */
19
- protected constructor(props: DisplayStyleProps, iModel: IModelDb);
20
- /** Create a Code for a DisplayStyle given a name that is meant to be unique within the scope of the specified DefinitionModel.
21
- * @param iModel The IModelDb
22
- * @param scopeModelId The Id of the DefinitionModel that contains the DisplayStyle and provides the scope for its name.
23
- * @param codeValue The DisplayStyle name
24
- */
25
- static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code;
26
- /** @internal */
27
- protected collectReferenceConcreteIds(referenceIds: EntityReferenceSet): void;
28
- /** @alpha */
29
- protected static onCloned(context: IModelElementCloneContext, sourceElementProps: DisplayStyleProps, targetElementProps: DisplayStyleProps): void;
30
- loadScheduleScript(): RenderSchedule.ScriptReference | undefined;
31
- }
32
- /** A DisplayStyle for 2d views.
33
- * @public
34
- */
35
- export declare class DisplayStyle2d extends DisplayStyle {
36
- /** @internal */
37
- static get className(): string;
38
- private readonly _settings;
39
- get settings(): DisplayStyleSettings;
40
- /** @internal */
41
- constructor(props: DisplayStyleProps, iModel: IModelDb);
42
- /** Create a DisplayStyle2d for use by a ViewDefinition.
43
- * @param iModelDb The iModel
44
- * @param definitionModelId The [[DefinitionModel]]
45
- * @param name The name/CodeValue of the DisplayStyle2d
46
- * @returns The newly constructed DisplayStyle2d element.
47
- * @throws [[IModelError]] if unable to create the element.
48
- */
49
- static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DisplayStyle2d;
50
- /** Insert a DisplayStyle2d for use by a ViewDefinition.
51
- * @param iModelDb Insert into this iModel
52
- * @param definitionModelId Insert the new DisplayStyle2d into this DefinitionModel
53
- * @param name The name of the DisplayStyle2d
54
- * @returns The Id of the newly inserted DisplayStyle2d element.
55
- * @throws [[IModelError]] if unable to insert the element.
56
- */
57
- static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string): Id64String;
58
- }
59
- /** Describes initial settings for a new [[DisplayStyle3d]].
60
- * Most properties are inherited from [DisplayStyle3dSettingsProps]($common), but for backwards compatibility reasons, this interface is slightly awkward:
61
- * - It adds a `viewFlags` member that differs only in case and type from [DisplayStyleSettingsProps.viewflags]($common); and
62
- * - It extends the type of [DisplayStyleSettingsProps.backgroundColor]($common) to include [ColorDef]($common).
63
- * These idiosyncrasies will be addressed in a future version of core-backend.
64
- * @see [[DisplayStyle3d.create]].
65
- * @public
66
- */
67
- export interface DisplayStyleCreationOptions extends Omit<DisplayStyle3dSettingsProps, "backgroundColor" | "scheduleScript"> {
68
- /** If supplied, the [ViewFlags]($common) applied by the display style.
69
- * If undefined, [DisplayStyle3dSettingsProps.viewflags]($common) will be used if present (note the difference in case); otherwise, default-constructed [ViewFlags]($common) will be used.
70
- */
71
- viewFlags?: ViewFlags;
72
- backgroundColor?: ColorDef | number;
73
- }
74
- /** A DisplayStyle for 3d views.
75
- * See [how to create a DisplayStyle3d]$(docs/learning/backend/CreateElements.md#DisplayStyle3d).
76
- * @public
77
- */
78
- export declare class DisplayStyle3d extends DisplayStyle {
79
- /** @internal */
80
- static get className(): string;
81
- private readonly _settings;
82
- get settings(): DisplayStyle3dSettings;
83
- /** @internal */
84
- constructor(props: DisplayStyle3dProps, iModel: IModelDb);
85
- /** @internal */
86
- protected collectReferenceConcreteIds(referenceIds: EntityReferenceSet): void;
87
- /** @alpha */
88
- protected static onCloned(context: IModelElementCloneContext, sourceElementProps: DisplayStyle3dProps, targetElementProps: DisplayStyle3dProps): void;
89
- /** Create a DisplayStyle3d for use by a ViewDefinition.
90
- * @param iModelDb The iModel
91
- * @param definitionModelId The [[DefinitionModel]]
92
- * @param name The name/CodeValue of the DisplayStyle3d
93
- * @returns The newly constructed DisplayStyle3d element.
94
- * @throws [[IModelError]] if unable to create the element.
95
- */
96
- static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): DisplayStyle3d;
97
- /**
98
- * Insert a DisplayStyle3d for use by a ViewDefinition.
99
- * @param iModelDb Insert into this iModel
100
- * @param definitionModelId Insert the new DisplayStyle3d into this [[DefinitionModel]]
101
- * @param name The name of the DisplayStyle3d
102
- * @returns The Id of the newly inserted DisplayStyle3d element.
103
- * @throws [[IModelError]] if unable to insert the element.
104
- */
105
- static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): Id64String;
106
- }
1
+ /** @packageDocumentation
2
+ * @module ViewDefinitions
3
+ */
4
+ import { Id64String } from "@itwin/core-bentley";
5
+ import { Code, CodeScopeProps, ColorDef, DisplayStyle3dProps, DisplayStyle3dSettings, DisplayStyle3dSettingsProps, DisplayStyleProps, DisplayStyleSettings, EntityReferenceSet, RenderSchedule, ViewFlags } from "@itwin/core-common";
6
+ import { DefinitionElement } from "./Element";
7
+ import { IModelDb } from "./IModelDb";
8
+ import { IModelElementCloneContext } from "./IModelElementCloneContext";
9
+ /** A DisplayStyle defines the parameters for 'styling' the contents of a view.
10
+ * Internally a DisplayStyle consists of a dictionary of several named 'styles' describing specific aspects of the display style as a whole.
11
+ * Many ViewDefinitions may share the same DisplayStyle.
12
+ * @public
13
+ */
14
+ export declare abstract class DisplayStyle extends DefinitionElement {
15
+ /** @internal */
16
+ static get className(): string;
17
+ abstract get settings(): DisplayStyleSettings;
18
+ /** @internal */
19
+ protected constructor(props: DisplayStyleProps, iModel: IModelDb);
20
+ /** Create a Code for a DisplayStyle given a name that is meant to be unique within the scope of the specified DefinitionModel.
21
+ * @param iModel The IModelDb
22
+ * @param scopeModelId The Id of the DefinitionModel that contains the DisplayStyle and provides the scope for its name.
23
+ * @param codeValue The DisplayStyle name
24
+ */
25
+ static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code;
26
+ protected collectReferenceIds(referenceIds: EntityReferenceSet): void;
27
+ /** @alpha */
28
+ protected static onCloned(context: IModelElementCloneContext, sourceElementProps: DisplayStyleProps, targetElementProps: DisplayStyleProps): void;
29
+ loadScheduleScript(): RenderSchedule.ScriptReference | undefined;
30
+ }
31
+ /** A DisplayStyle for 2d views.
32
+ * @public
33
+ */
34
+ export declare class DisplayStyle2d extends DisplayStyle {
35
+ /** @internal */
36
+ static get className(): string;
37
+ private readonly _settings;
38
+ get settings(): DisplayStyleSettings;
39
+ /** @internal */
40
+ constructor(props: DisplayStyleProps, iModel: IModelDb);
41
+ /** Create a DisplayStyle2d for use by a ViewDefinition.
42
+ * @param iModelDb The iModel
43
+ * @param definitionModelId The [[DefinitionModel]]
44
+ * @param name The name/CodeValue of the DisplayStyle2d
45
+ * @returns The newly constructed DisplayStyle2d element.
46
+ * @throws [[IModelError]] if unable to create the element.
47
+ */
48
+ static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DisplayStyle2d;
49
+ /** Insert a DisplayStyle2d for use by a ViewDefinition.
50
+ * @param iModelDb Insert into this iModel
51
+ * @param definitionModelId Insert the new DisplayStyle2d into this DefinitionModel
52
+ * @param name The name of the DisplayStyle2d
53
+ * @returns The Id of the newly inserted DisplayStyle2d element.
54
+ * @throws [[IModelError]] if unable to insert the element.
55
+ */
56
+ static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string): Id64String;
57
+ }
58
+ /** Describes initial settings for a new [[DisplayStyle3d]].
59
+ * Most properties are inherited from [DisplayStyle3dSettingsProps]($common), but for backwards compatibility reasons, this interface is slightly awkward:
60
+ * - It adds a `viewFlags` member that differs only in case and type from [DisplayStyleSettingsProps.viewflags]($common); and
61
+ * - It extends the type of [DisplayStyleSettingsProps.backgroundColor]($common) to include [ColorDef]($common).
62
+ * These idiosyncrasies will be addressed in a future version of core-backend.
63
+ * @see [[DisplayStyle3d.create]].
64
+ * @public
65
+ */
66
+ export interface DisplayStyleCreationOptions extends Omit<DisplayStyle3dSettingsProps, "backgroundColor" | "scheduleScript"> {
67
+ /** If supplied, the [ViewFlags]($common) applied by the display style.
68
+ * If undefined, [DisplayStyle3dSettingsProps.viewflags]($common) will be used if present (note the difference in case); otherwise, default-constructed [ViewFlags]($common) will be used.
69
+ */
70
+ viewFlags?: ViewFlags;
71
+ backgroundColor?: ColorDef | number;
72
+ }
73
+ /** A DisplayStyle for 3d views.
74
+ * See [how to create a DisplayStyle3d]$(docs/learning/backend/CreateElements.md#DisplayStyle3d).
75
+ * @public
76
+ */
77
+ export declare class DisplayStyle3d extends DisplayStyle {
78
+ /** @internal */
79
+ static get className(): string;
80
+ private readonly _settings;
81
+ get settings(): DisplayStyle3dSettings;
82
+ /** @internal */
83
+ constructor(props: DisplayStyle3dProps, iModel: IModelDb);
84
+ protected collectReferenceIds(referenceIds: EntityReferenceSet): void;
85
+ /** @alpha */
86
+ protected static onCloned(context: IModelElementCloneContext, sourceElementProps: DisplayStyle3dProps, targetElementProps: DisplayStyle3dProps): void;
87
+ /** Create a DisplayStyle3d for use by a ViewDefinition.
88
+ * @param iModelDb The iModel
89
+ * @param definitionModelId The [[DefinitionModel]]
90
+ * @param name The name/CodeValue of the DisplayStyle3d
91
+ * @returns The newly constructed DisplayStyle3d element.
92
+ * @throws [[IModelError]] if unable to create the element.
93
+ */
94
+ static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): DisplayStyle3d;
95
+ /**
96
+ * Insert a DisplayStyle3d for use by a ViewDefinition.
97
+ * @param iModelDb Insert into this iModel
98
+ * @param definitionModelId Insert the new DisplayStyle3d into this [[DefinitionModel]]
99
+ * @param name The name of the DisplayStyle3d
100
+ * @returns The Id of the newly inserted DisplayStyle3d element.
101
+ * @throws [[IModelError]] if unable to insert the element.
102
+ */
103
+ static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): Id64String;
104
+ }
107
105
  //# sourceMappingURL=DisplayStyle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DisplayStyle.d.ts","sourceRoot":"","sources":["../../src/DisplayStyle.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAsC,UAAU,EAAuB,MAAM,qBAAqB,CAAC;AAC1G,OAAO,EACQ,IAAI,EAAE,cAAc,EAAY,QAAQ,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,2BAA2B,EAC/H,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAA+B,cAAc,EAAoB,SAAS,EACtI,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAkB,MAAM,WAAW,CAAC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