@itwin/core-backend 3.0.0-dev.100

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 (245) hide show
  1. package/CHANGELOG.md +1525 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +11 -0
  4. package/lib/cjs/AliCloudStorageService.d.ts +12 -0
  5. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -0
  6. package/lib/cjs/AliCloudStorageService.js +70 -0
  7. package/lib/cjs/AliCloudStorageService.js.map +1 -0
  8. package/lib/cjs/BackendHubAccess.d.ts +208 -0
  9. package/lib/cjs/BackendHubAccess.d.ts.map +1 -0
  10. package/lib/cjs/BackendHubAccess.js +42 -0
  11. package/lib/cjs/BackendHubAccess.js.map +1 -0
  12. package/lib/cjs/BackendLoggerCategory.d.ts +83 -0
  13. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -0
  14. package/lib/cjs/BackendLoggerCategory.js +91 -0
  15. package/lib/cjs/BackendLoggerCategory.js.map +1 -0
  16. package/lib/cjs/BisCoreSchema.d.ts +22 -0
  17. package/lib/cjs/BisCoreSchema.d.ts.map +1 -0
  18. package/lib/cjs/BisCoreSchema.js +61 -0
  19. package/lib/cjs/BisCoreSchema.js.map +1 -0
  20. package/lib/cjs/BriefcaseManager.d.ts +167 -0
  21. package/lib/cjs/BriefcaseManager.d.ts.map +1 -0
  22. package/lib/cjs/BriefcaseManager.js +406 -0
  23. package/lib/cjs/BriefcaseManager.js.map +1 -0
  24. package/lib/cjs/Category.d.ts +154 -0
  25. package/lib/cjs/Category.d.ts.map +1 -0
  26. package/lib/cjs/Category.js +244 -0
  27. package/lib/cjs/Category.js.map +1 -0
  28. package/lib/cjs/ChangeSummaryManager.d.ts +188 -0
  29. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -0
  30. package/lib/cjs/ChangeSummaryManager.js +444 -0
  31. package/lib/cjs/ChangeSummaryManager.js.map +1 -0
  32. package/lib/cjs/ChangedElementsDb.d.ts +97 -0
  33. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -0
  34. package/lib/cjs/ChangedElementsDb.js +166 -0
  35. package/lib/cjs/ChangedElementsDb.js.map +1 -0
  36. package/lib/cjs/ChangedElementsManager.d.ts +40 -0
  37. package/lib/cjs/ChangedElementsManager.d.ts.map +1 -0
  38. package/lib/cjs/ChangedElementsManager.js +89 -0
  39. package/lib/cjs/ChangedElementsManager.js.map +1 -0
  40. package/lib/cjs/CheckpointManager.d.ts +101 -0
  41. package/lib/cjs/CheckpointManager.d.ts.map +1 -0
  42. package/lib/cjs/CheckpointManager.js +257 -0
  43. package/lib/cjs/CheckpointManager.js.map +1 -0
  44. package/lib/cjs/ClassRegistry.d.ts +72 -0
  45. package/lib/cjs/ClassRegistry.d.ts.map +1 -0
  46. package/lib/cjs/ClassRegistry.js +154 -0
  47. package/lib/cjs/ClassRegistry.js.map +1 -0
  48. package/lib/cjs/CloudStorageBackend.d.ts +46 -0
  49. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -0
  50. package/lib/cjs/CloudStorageBackend.js +157 -0
  51. package/lib/cjs/CloudStorageBackend.js.map +1 -0
  52. package/lib/cjs/CodeSpecs.d.ts +51 -0
  53. package/lib/cjs/CodeSpecs.d.ts.map +1 -0
  54. package/lib/cjs/CodeSpecs.js +113 -0
  55. package/lib/cjs/CodeSpecs.js.map +1 -0
  56. package/lib/cjs/ConcurrentQuery.d.ts +12 -0
  57. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -0
  58. package/lib/cjs/ConcurrentQuery.js +24 -0
  59. package/lib/cjs/ConcurrentQuery.js.map +1 -0
  60. package/lib/cjs/DevTools.d.ts +72 -0
  61. package/lib/cjs/DevTools.d.ts.map +1 -0
  62. package/lib/cjs/DevTools.js +155 -0
  63. package/lib/cjs/DevTools.js.map +1 -0
  64. package/lib/cjs/DisplayStyle.d.ts +107 -0
  65. package/lib/cjs/DisplayStyle.d.ts.map +1 -0
  66. package/lib/cjs/DisplayStyle.js +292 -0
  67. package/lib/cjs/DisplayStyle.js.map +1 -0
  68. package/lib/cjs/ECDb.d.ts +196 -0
  69. package/lib/cjs/ECDb.d.ts.map +1 -0
  70. package/lib/cjs/ECDb.js +354 -0
  71. package/lib/cjs/ECDb.js.map +1 -0
  72. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -0
  73. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -0
  74. package/lib/cjs/ECSchemaXmlContext.js +36 -0
  75. package/lib/cjs/ECSchemaXmlContext.js.map +1 -0
  76. package/lib/cjs/ECSqlStatement.d.ts +467 -0
  77. package/lib/cjs/ECSqlStatement.d.ts.map +1 -0
  78. package/lib/cjs/ECSqlStatement.js +783 -0
  79. package/lib/cjs/ECSqlStatement.js.map +1 -0
  80. package/lib/cjs/Element.d.ts +1082 -0
  81. package/lib/cjs/Element.d.ts.map +1 -0
  82. package/lib/cjs/Element.js +1392 -0
  83. package/lib/cjs/Element.js.map +1 -0
  84. package/lib/cjs/ElementAspect.d.ts +157 -0
  85. package/lib/cjs/ElementAspect.d.ts.map +1 -0
  86. package/lib/cjs/ElementAspect.js +179 -0
  87. package/lib/cjs/ElementAspect.js.map +1 -0
  88. package/lib/cjs/ElementGraphics.d.ts +10 -0
  89. package/lib/cjs/ElementGraphics.d.ts.map +1 -0
  90. package/lib/cjs/ElementGraphics.js +42 -0
  91. package/lib/cjs/ElementGraphics.js.map +1 -0
  92. package/lib/cjs/Entity.d.ts +57 -0
  93. package/lib/cjs/Entity.d.ts.map +1 -0
  94. package/lib/cjs/Entity.js +63 -0
  95. package/lib/cjs/Entity.js.map +1 -0
  96. package/lib/cjs/ExportGraphics.d.ts +302 -0
  97. package/lib/cjs/ExportGraphics.d.ts.map +1 -0
  98. package/lib/cjs/ExportGraphics.js +206 -0
  99. package/lib/cjs/ExportGraphics.js.map +1 -0
  100. package/lib/cjs/ExternalSource.d.ts +95 -0
  101. package/lib/cjs/ExternalSource.d.ts.map +1 -0
  102. package/lib/cjs/ExternalSource.js +126 -0
  103. package/lib/cjs/ExternalSource.js.map +1 -0
  104. package/lib/cjs/GeometrySummary.d.ts +5 -0
  105. package/lib/cjs/GeometrySummary.d.ts.map +1 -0
  106. package/lib/cjs/GeometrySummary.js +378 -0
  107. package/lib/cjs/GeometrySummary.js.map +1 -0
  108. package/lib/cjs/IModelCloneContext.d.ts +74 -0
  109. package/lib/cjs/IModelCloneContext.d.ts.map +1 -0
  110. package/lib/cjs/IModelCloneContext.js +130 -0
  111. package/lib/cjs/IModelCloneContext.js.map +1 -0
  112. package/lib/cjs/IModelDb.d.ts +1107 -0
  113. package/lib/cjs/IModelDb.d.ts.map +1 -0
  114. package/lib/cjs/IModelDb.js +2161 -0
  115. package/lib/cjs/IModelDb.js.map +1 -0
  116. package/lib/cjs/IModelHost.d.ts +284 -0
  117. package/lib/cjs/IModelHost.d.ts.map +1 -0
  118. package/lib/cjs/IModelHost.js +411 -0
  119. package/lib/cjs/IModelHost.js.map +1 -0
  120. package/lib/cjs/IModelJsFs.d.ts +63 -0
  121. package/lib/cjs/IModelJsFs.d.ts.map +1 -0
  122. package/lib/cjs/IModelJsFs.js +141 -0
  123. package/lib/cjs/IModelJsFs.js.map +1 -0
  124. package/lib/cjs/IModelSchemaLoader.d.ts +26 -0
  125. package/lib/cjs/IModelSchemaLoader.d.ts.map +1 -0
  126. package/lib/cjs/IModelSchemaLoader.js +95 -0
  127. package/lib/cjs/IModelSchemaLoader.js.map +1 -0
  128. package/lib/cjs/IpcHost.d.ts +99 -0
  129. package/lib/cjs/IpcHost.d.ts.map +1 -0
  130. package/lib/cjs/IpcHost.js +234 -0
  131. package/lib/cjs/IpcHost.js.map +1 -0
  132. package/lib/cjs/LineStyle.d.ts +312 -0
  133. package/lib/cjs/LineStyle.d.ts.map +1 -0
  134. package/lib/cjs/LineStyle.js +296 -0
  135. package/lib/cjs/LineStyle.js.map +1 -0
  136. package/lib/cjs/LocalhostIpcHost.d.ts +19 -0
  137. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -0
  138. package/lib/cjs/LocalhostIpcHost.js +52 -0
  139. package/lib/cjs/LocalhostIpcHost.js.map +1 -0
  140. package/lib/cjs/Material.d.ts +102 -0
  141. package/lib/cjs/Material.d.ts.map +1 -0
  142. package/lib/cjs/Material.js +146 -0
  143. package/lib/cjs/Material.js.map +1 -0
  144. package/lib/cjs/Model.d.ts +387 -0
  145. package/lib/cjs/Model.d.ts.map +1 -0
  146. package/lib/cjs/Model.js +469 -0
  147. package/lib/cjs/Model.js.map +1 -0
  148. package/lib/cjs/NativeAppStorage.d.ts +52 -0
  149. package/lib/cjs/NativeAppStorage.d.ts.map +1 -0
  150. package/lib/cjs/NativeAppStorage.js +203 -0
  151. package/lib/cjs/NativeAppStorage.js.map +1 -0
  152. package/lib/cjs/NativeHost.d.ts +71 -0
  153. package/lib/cjs/NativeHost.d.ts.map +1 -0
  154. package/lib/cjs/NativeHost.js +221 -0
  155. package/lib/cjs/NativeHost.js.map +1 -0
  156. package/lib/cjs/NavigationRelationship.d.ts +157 -0
  157. package/lib/cjs/NavigationRelationship.d.ts.map +1 -0
  158. package/lib/cjs/NavigationRelationship.js +226 -0
  159. package/lib/cjs/NavigationRelationship.js.map +1 -0
  160. package/lib/cjs/PromiseMemoizer.d.ts +52 -0
  161. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -0
  162. package/lib/cjs/PromiseMemoizer.js +93 -0
  163. package/lib/cjs/PromiseMemoizer.js.map +1 -0
  164. package/lib/cjs/Relationship.d.ts +400 -0
  165. package/lib/cjs/Relationship.d.ts.map +1 -0
  166. package/lib/cjs/Relationship.js +460 -0
  167. package/lib/cjs/Relationship.js.map +1 -0
  168. package/lib/cjs/RpcBackend.d.ts +23 -0
  169. package/lib/cjs/RpcBackend.d.ts.map +1 -0
  170. package/lib/cjs/RpcBackend.js +94 -0
  171. package/lib/cjs/RpcBackend.js.map +1 -0
  172. package/lib/cjs/SQLiteDb.d.ts +66 -0
  173. package/lib/cjs/SQLiteDb.d.ts.map +1 -0
  174. package/lib/cjs/SQLiteDb.js +140 -0
  175. package/lib/cjs/SQLiteDb.js.map +1 -0
  176. package/lib/cjs/Schema.d.ts +56 -0
  177. package/lib/cjs/Schema.d.ts.map +1 -0
  178. package/lib/cjs/Schema.js +84 -0
  179. package/lib/cjs/Schema.js.map +1 -0
  180. package/lib/cjs/ServerBasedLocks.d.ts +64 -0
  181. package/lib/cjs/ServerBasedLocks.d.ts.map +1 -0
  182. package/lib/cjs/ServerBasedLocks.js +177 -0
  183. package/lib/cjs/ServerBasedLocks.js.map +1 -0
  184. package/lib/cjs/SqliteStatement.d.ts +264 -0
  185. package/lib/cjs/SqliteStatement.d.ts.map +1 -0
  186. package/lib/cjs/SqliteStatement.js +417 -0
  187. package/lib/cjs/SqliteStatement.js.map +1 -0
  188. package/lib/cjs/Texture.d.ts +59 -0
  189. package/lib/cjs/Texture.d.ts.map +1 -0
  190. package/lib/cjs/Texture.js +83 -0
  191. package/lib/cjs/Texture.js.map +1 -0
  192. package/lib/cjs/TxnManager.d.ts +203 -0
  193. package/lib/cjs/TxnManager.d.ts.map +1 -0
  194. package/lib/cjs/TxnManager.js +354 -0
  195. package/lib/cjs/TxnManager.js.map +1 -0
  196. package/lib/cjs/ViewDefinition.d.ts +432 -0
  197. package/lib/cjs/ViewDefinition.d.ts.map +1 -0
  198. package/lib/cjs/ViewDefinition.js +623 -0
  199. package/lib/cjs/ViewDefinition.js.map +1 -0
  200. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -0
  201. package/lib/cjs/core-backend.d.ts +162 -0
  202. package/lib/cjs/core-backend.d.ts.map +1 -0
  203. package/lib/cjs/core-backend.js +181 -0
  204. package/lib/cjs/core-backend.js.map +1 -0
  205. package/lib/cjs/domains/FunctionalElements.d.ts +102 -0
  206. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -0
  207. package/lib/cjs/domains/FunctionalElements.js +146 -0
  208. package/lib/cjs/domains/FunctionalElements.js.map +1 -0
  209. package/lib/cjs/domains/FunctionalSchema.d.ts +14 -0
  210. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -0
  211. package/lib/cjs/domains/FunctionalSchema.js +41 -0
  212. package/lib/cjs/domains/FunctionalSchema.js.map +1 -0
  213. package/lib/cjs/domains/GenericElements.d.ts +178 -0
  214. package/lib/cjs/domains/GenericElements.d.ts.map +1 -0
  215. package/lib/cjs/domains/GenericElements.js +264 -0
  216. package/lib/cjs/domains/GenericElements.js.map +1 -0
  217. package/lib/cjs/domains/GenericSchema.d.ts +11 -0
  218. package/lib/cjs/domains/GenericSchema.d.ts.map +1 -0
  219. package/lib/cjs/domains/GenericSchema.js +29 -0
  220. package/lib/cjs/domains/GenericSchema.js.map +1 -0
  221. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +16 -0
  222. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts.map +1 -0
  223. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +33 -0
  224. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -0
  225. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +40 -0
  226. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -0
  227. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +207 -0
  228. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -0
  229. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +21 -0
  230. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -0
  231. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -0
  232. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -0
  233. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +37 -0
  234. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -0
  235. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +162 -0
  236. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -0
  237. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +17 -0
  238. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts.map +1 -0
  239. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +44 -0
  240. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -0
  241. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +16 -0
  242. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts.map +1 -0
  243. package/lib/cjs/rpc-impl/WipRpcImpl.js +35 -0
  244. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -0
  245. package/package.json +101 -0
@@ -0,0 +1,411 @@
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 IModelHost
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FileNameResolver = exports.KnownLocations = exports.Platform = exports.IModelHost = exports.IModelHostConfiguration = void 0;
11
+ const os = require("os");
12
+ const path = require("path");
13
+ const semver = require("semver");
14
+ const imodeljs_native_1 = require("@bentley/imodeljs-native");
15
+ const telemetry_client_1 = require("@bentley/telemetry-client");
16
+ const core_bentley_1 = require("@itwin/core-bentley");
17
+ const core_common_1 = require("@itwin/core-common");
18
+ const AliCloudStorageService_1 = require("./AliCloudStorageService");
19
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
20
+ const BisCoreSchema_1 = require("./BisCoreSchema");
21
+ const BriefcaseManager_1 = require("./BriefcaseManager");
22
+ const CloudStorageBackend_1 = require("./CloudStorageBackend");
23
+ const FunctionalSchema_1 = require("./domains/FunctionalSchema");
24
+ const GenericSchema_1 = require("./domains/GenericSchema");
25
+ const IModelJsFs_1 = require("./IModelJsFs");
26
+ const DevToolsRpcImpl_1 = require("./rpc-impl/DevToolsRpcImpl");
27
+ const IModelReadRpcImpl_1 = require("./rpc-impl/IModelReadRpcImpl");
28
+ const IModelTileRpcImpl_1 = require("./rpc-impl/IModelTileRpcImpl");
29
+ const SnapshotIModelRpcImpl_1 = require("./rpc-impl/SnapshotIModelRpcImpl");
30
+ const WipRpcImpl_1 = require("./rpc-impl/WipRpcImpl");
31
+ const RpcBackend_1 = require("./RpcBackend");
32
+ const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.IModelHost;
33
+ /** Configuration of core-backend.
34
+ * @public
35
+ */
36
+ class IModelHostConfiguration {
37
+ constructor() {
38
+ /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a "pending" status.
39
+ * @internal
40
+ */
41
+ this.tileTreeRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;
42
+ /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a "pending" status.
43
+ * @internal
44
+ */
45
+ this.tileContentRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;
46
+ /** The backend will log when a tile took longer to load than this threshold in seconds.
47
+ * @internal
48
+ */
49
+ this.logTileLoadTimeThreshold = IModelHostConfiguration.defaultLogTileLoadTimeThreshold;
50
+ /** The backend will log when a tile is loaded with a size in bytes above this threshold.
51
+ * @internal
52
+ */
53
+ this.logTileSizeThreshold = IModelHostConfiguration.defaultLogTileSizeThreshold;
54
+ }
55
+ }
56
+ exports.IModelHostConfiguration = IModelHostConfiguration;
57
+ /** The default time, in milliseconds, used for [[tileTreeRequestTimeout]] and [[tileContentRequestTimeout]]. To change this, override one or both of those properties.
58
+ * @internal
59
+ */
60
+ IModelHostConfiguration.defaultTileRequestTimeout = 20 * 1000;
61
+ /** The default time, in seconds, used for [[logTileLoadTimeThreshold]]. To change this, override that property.
62
+ * @internal
63
+ */
64
+ IModelHostConfiguration.defaultLogTileLoadTimeThreshold = 40;
65
+ /** The default size, in bytes, used for [[logTileSizeThreshold]]. To change this, override that property.
66
+ * @internal
67
+ */
68
+ IModelHostConfiguration.defaultLogTileSizeThreshold = 20 * 1000000;
69
+ /** IModelHost initializes ($backend) and captures its configuration. A backend must call [[IModelHost.startup]] before using any backend classes.
70
+ * See [the learning article]($docs/learning/backend/IModelHost.md)
71
+ * @public
72
+ */
73
+ class IModelHost {
74
+ constructor() { }
75
+ /** @internal */
76
+ static get platform() {
77
+ if (this._platform === undefined)
78
+ throw new Error("IModelHost.startup must be called first");
79
+ return this._platform;
80
+ }
81
+ /** A uniqueId for this session */
82
+ static get sessionId() { return this.session.sessionId; }
83
+ static set sessionId(id) { this.session.sessionId = id; }
84
+ /** The Id of this application - needs to be set only if it is an agent application. The applicationId will otherwise originate at the frontend. */
85
+ static get applicationId() { return this.session.applicationId; }
86
+ static set applicationId(id) { this.session.applicationId = id; }
87
+ /** The version of this application - needs to be set if is an agent application. The applicationVersion will otherwise originate at the frontend. */
88
+ static get applicationVersion() { return this.session.applicationVersion; }
89
+ static set applicationVersion(version) { this.session.applicationVersion = version; }
90
+ /** Root of the directory holding all the files that iModel.js caches */
91
+ static get cacheDir() { return this._cacheDir; }
92
+ /** Get the current access token for this IModelHost, or a blank string if none is available.
93
+ * @note for web backends, this will *always* return a blank string because the backend itself has no token (but never needs one either.)
94
+ * For all IpcHosts, where this backend is servicing a single frontend, this will be the user's token. For ElectronHost, the backend
95
+ * obtains the token and forwards it to the frontend.
96
+ * @note accessTokens expire periodically and are automatically refreshed, if possible. Therefore tokens should not be saved, and the value
97
+ * returned by this method may change over time throughout the course of a session.
98
+ */
99
+ static async getAccessToken() {
100
+ var _a, _b;
101
+ try {
102
+ return (_b = (await ((_a = this.authorizationClient) === null || _a === void 0 ? void 0 : _a.getAccessToken()))) !== null && _b !== void 0 ? _b : "";
103
+ }
104
+ catch (e) {
105
+ return "";
106
+ }
107
+ }
108
+ /** @internal */
109
+ static flushLog() {
110
+ return this.platform.DgnDb.flushLog();
111
+ }
112
+ /** @internal */
113
+ static loadNative() {
114
+ const platform = Platform.load();
115
+ this.registerPlatform(platform);
116
+ }
117
+ static registerPlatform(platform) {
118
+ this._platform = platform;
119
+ if (undefined === platform)
120
+ return;
121
+ if (!core_bentley_1.ProcessDetector.isMobileAppBackend)
122
+ this.validateNativePlatformVersion();
123
+ platform.logger = core_bentley_1.Logger;
124
+ }
125
+ static validateNativePlatformVersion() {
126
+ const requiredVersion = require("../../package.json").dependencies["@bentley/imodeljs-native"]; // eslint-disable-line @typescript-eslint/no-var-requires
127
+ const thisVersion = this.platform.version;
128
+ if (semver.satisfies(thisVersion, requiredVersion))
129
+ return;
130
+ if (IModelJsFs_1.IModelJsFs.existsSync(path.join(__dirname, "DevBuild.txt"))) {
131
+ console.log("Bypassing version checks for development build"); // eslint-disable-line no-console
132
+ return;
133
+ }
134
+ this._platform = undefined;
135
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, `imodeljs-native version is (${thisVersion}). core-backend requires version (${requiredVersion})`);
136
+ }
137
+ /** @internal */
138
+ static setHubAccess(hubAccess) { this._hubAccess = hubAccess; }
139
+ /** Provides access to the IModelHub for this IModelHost
140
+ * @beta
141
+ */
142
+ static get hubAccess() { return this._hubAccess; }
143
+ /** Returns true if IModelHost is started. */
144
+ static get isValid() { return this._isValid; }
145
+ /** This method must be called before any iModel.js services are used.
146
+ * @param configuration Host configuration data.
147
+ * Raises [[onAfterStartup]].
148
+ * @see [[shutdown]].
149
+ */
150
+ static async startup(configuration = new IModelHostConfiguration()) {
151
+ if (this._isValid)
152
+ return; // we're already initialized
153
+ this._isValid = true;
154
+ if (IModelHost.sessionId === "")
155
+ IModelHost.sessionId = core_bentley_1.Guid.createValue();
156
+ this.logStartup();
157
+ this.backendVersion = require("../../package.json").version; // eslint-disable-line @typescript-eslint/no-var-requires
158
+ (0, RpcBackend_1.initializeRpcBackend)();
159
+ if (this._platform === undefined) {
160
+ try {
161
+ this.loadNative();
162
+ }
163
+ catch (error) {
164
+ core_bentley_1.Logger.logError(loggerCategory, "Error registering/loading the native platform API", () => (configuration));
165
+ throw error;
166
+ }
167
+ }
168
+ if (configuration.crashReportingConfig && configuration.crashReportingConfig.crashDir && !core_bentley_1.ProcessDetector.isElectronAppBackend && !core_bentley_1.ProcessDetector.isMobileAppBackend) {
169
+ this.platform.setCrashReporting(configuration.crashReportingConfig);
170
+ core_bentley_1.Logger.logTrace(loggerCategory, "Configured crash reporting", () => {
171
+ var _a, _b, _c, _d;
172
+ return ({
173
+ enableCrashDumps: (_a = configuration.crashReportingConfig) === null || _a === void 0 ? void 0 : _a.enableCrashDumps,
174
+ wantFullMemoryDumps: (_b = configuration.crashReportingConfig) === null || _b === void 0 ? void 0 : _b.wantFullMemoryDumps,
175
+ enableNodeReport: (_c = configuration.crashReportingConfig) === null || _c === void 0 ? void 0 : _c.enableNodeReport,
176
+ uploadToBentley: (_d = configuration.crashReportingConfig) === null || _d === void 0 ? void 0 : _d.uploadToBentley,
177
+ });
178
+ });
179
+ if (configuration.crashReportingConfig.enableNodeReport) {
180
+ try {
181
+ // node-report reports on V8 fatal errors and unhandled exceptions/Promise rejections.
182
+ const nodereport = require("node-report/api"); // eslint-disable-line @typescript-eslint/no-var-requires
183
+ nodereport.setEvents("exception+fatalerror+apicall");
184
+ nodereport.setDirectory(configuration.crashReportingConfig.crashDir);
185
+ nodereport.setVerbose("yes");
186
+ core_bentley_1.Logger.logTrace(loggerCategory, "Configured native crash reporting (node-report)");
187
+ }
188
+ catch (err) {
189
+ core_bentley_1.Logger.logWarning(loggerCategory, "node-report is not installed.");
190
+ }
191
+ }
192
+ }
193
+ this.setupCacheDirs(configuration);
194
+ BriefcaseManager_1.BriefcaseManager.initialize(this._briefcaseCacheDir);
195
+ [
196
+ IModelReadRpcImpl_1.IModelReadRpcImpl,
197
+ IModelTileRpcImpl_1.IModelTileRpcImpl,
198
+ SnapshotIModelRpcImpl_1.SnapshotIModelRpcImpl,
199
+ WipRpcImpl_1.WipRpcImpl,
200
+ DevToolsRpcImpl_1.DevToolsRpcImpl,
201
+ ].forEach((rpc) => rpc.register()); // register all of the RPC implementations
202
+ [
203
+ BisCoreSchema_1.BisCoreSchema,
204
+ GenericSchema_1.GenericSchema,
205
+ FunctionalSchema_1.FunctionalSchema,
206
+ ].forEach((schema) => schema.registerSchema()); // register all of the schemas
207
+ if (undefined !== configuration.hubAccess)
208
+ IModelHost._hubAccess = configuration.hubAccess;
209
+ IModelHost.configuration = configuration;
210
+ IModelHost.setupTileCache();
211
+ this.platform.setUseTileCache(configuration.tileCacheCredentials ? false : true);
212
+ process.once("beforeExit", IModelHost.shutdown);
213
+ IModelHost.onAfterStartup.raiseEvent();
214
+ }
215
+ static logStartup() {
216
+ if (!core_bentley_1.Logger.isEnabled(loggerCategory, core_bentley_1.LogLevel.Trace))
217
+ return;
218
+ // Extract the iModel details from environment - note this is very specific to Bentley hosted backends, but is quite useful for tracing
219
+ let startupInfo = {};
220
+ const serviceName = process.env.FABRIC_SERVICE_NAME;
221
+ if (serviceName) {
222
+ // e.g., fabric:/iModelWebViewer3.0/iModelJSGuest/1/08daaeb3-b56f-480b-9051-7efc834d18ae/512d971d-b641-4735-bb1c-c07ab3e44ce7/c1315fcce125ca40b2d405bb7809214daf8b4c85
223
+ const serviceNameComponents = serviceName.split("/");
224
+ if (serviceNameComponents.length === 7) {
225
+ startupInfo = {
226
+ ...startupInfo,
227
+ iTwinId: serviceNameComponents[4],
228
+ iModelId: serviceNameComponents[5],
229
+ changesetId: serviceNameComponents[6],
230
+ };
231
+ }
232
+ }
233
+ core_bentley_1.Logger.logTrace(loggerCategory, "IModelHost.startup", () => startupInfo);
234
+ }
235
+ static setupCacheDirs(configuration) {
236
+ this._cacheDir = configuration.cacheDir ? path.normalize(configuration.cacheDir) : imodeljs_native_1.NativeLibrary.defaultCacheDir;
237
+ IModelJsFs_1.IModelJsFs.recursiveMkDirSync(this._cacheDir); // make sure the directory for cacheDir exists.
238
+ this._briefcaseCacheDir = path.join(this._cacheDir, "imodels");
239
+ }
240
+ /** This method must be called when an iModel.js services is shut down. Raises [[onBeforeShutdown]] */
241
+ static async shutdown() {
242
+ // NB: This method is set as a node listener where `this` is unbound
243
+ if (!IModelHost._isValid)
244
+ return;
245
+ IModelHost._isValid = false;
246
+ IModelHost.onBeforeShutdown.raiseEvent();
247
+ IModelHost.configuration = undefined;
248
+ process.removeListener("beforeExit", IModelHost.shutdown);
249
+ }
250
+ /**
251
+ * Add or update a property that should be included in a crash report.
252
+ * @param name The name of the property
253
+ * @param value The value of the property
254
+ * @alpha
255
+ */
256
+ static setCrashReportProperty(name, value) {
257
+ (0, core_bentley_1.assert)(undefined !== this._platform);
258
+ this._platform.setCrashReportProperty(name, value);
259
+ }
260
+ /**
261
+ * Remove a previously defined property so that will not be included in a crash report.
262
+ * @param name The name of the property
263
+ * @alpha
264
+ */
265
+ static removeCrashReportProperty(name) {
266
+ (0, core_bentley_1.assert)(undefined !== this._platform);
267
+ this._platform.setCrashReportProperty(name, undefined);
268
+ }
269
+ /**
270
+ * Get all properties that will be included in a crash report.
271
+ * @alpha
272
+ */
273
+ static getCrashReportProperties() {
274
+ (0, core_bentley_1.assert)(undefined !== this._platform);
275
+ return this._platform.getCrashReportProperties();
276
+ }
277
+ /** The directory where application assets may be found */
278
+ static get appAssetsDir() { return undefined !== IModelHost.configuration ? IModelHost.configuration.appAssetsDir : undefined; }
279
+ /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a "pending" status.
280
+ * @internal
281
+ */
282
+ static get tileTreeRequestTimeout() {
283
+ return undefined !== IModelHost.configuration ? IModelHost.configuration.tileTreeRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;
284
+ }
285
+ /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a "pending" status.
286
+ * @internal
287
+ */
288
+ static get tileContentRequestTimeout() {
289
+ return undefined !== IModelHost.configuration ? IModelHost.configuration.tileContentRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;
290
+ }
291
+ /** The backend will log when a tile took longer to load than this threshold in seconds. */
292
+ static get logTileLoadTimeThreshold() { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileLoadTimeThreshold : IModelHostConfiguration.defaultLogTileLoadTimeThreshold; }
293
+ /** The backend will log when a tile is loaded with a size in bytes above this threshold. */
294
+ static get logTileSizeThreshold() { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileSizeThreshold : IModelHostConfiguration.defaultLogTileSizeThreshold; }
295
+ /** Whether external tile caching is active.
296
+ * @internal
297
+ */
298
+ static get usingExternalTileCache() {
299
+ var _a;
300
+ return undefined !== ((_a = IModelHost.configuration) === null || _a === void 0 ? void 0 : _a.tileCacheCredentials);
301
+ }
302
+ /** Whether to restrict tile cache URLs by client IP address.
303
+ * @internal
304
+ */
305
+ static get restrictTileUrlsByClientIp() { return undefined !== IModelHost.configuration && (IModelHost.configuration.restrictTileUrlsByClientIp ? true : false); }
306
+ /** Whether to compress cached tiles.
307
+ * @internal
308
+ */
309
+ static get compressCachedTiles() { var _a; return false !== ((_a = IModelHost.configuration) === null || _a === void 0 ? void 0 : _a.compressCachedTiles); }
310
+ static setupTileCache() {
311
+ const config = IModelHost.configuration;
312
+ const credentials = config.tileCacheCredentials;
313
+ if (undefined === credentials)
314
+ return;
315
+ IModelHost.tileUploader = new CloudStorageBackend_1.CloudStorageTileUploader();
316
+ if (credentials.service === "azure" && !IModelHost.tileCacheService) {
317
+ IModelHost.tileCacheService = new CloudStorageBackend_1.AzureBlobStorage(credentials);
318
+ }
319
+ else if (credentials.service === "alicloud") {
320
+ IModelHost.tileCacheService = new AliCloudStorageService_1.AliCloudStorageService(credentials);
321
+ }
322
+ else if (credentials.service !== "external") {
323
+ throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "Unsupported cloud service credentials for tile cache.");
324
+ }
325
+ }
326
+ }
327
+ exports.IModelHost = IModelHost;
328
+ /** @alpha */
329
+ IModelHost.telemetry = new telemetry_client_1.TelemetryManager();
330
+ IModelHost.backendVersion = "";
331
+ IModelHost._cacheDir = "";
332
+ /** Event raised just after the backend IModelHost was started */
333
+ IModelHost.onAfterStartup = new core_bentley_1.BeEvent();
334
+ /** Event raised just before the backend IModelHost is to be shut down */
335
+ IModelHost.onBeforeShutdown = new core_bentley_1.BeEvent();
336
+ /** @internal */
337
+ IModelHost.session = { applicationId: "2686", applicationVersion: "1.0.0", sessionId: "" };
338
+ IModelHost._isValid = false;
339
+ /** Information about the platform on which the app is running. Also see [[KnownLocations]] and [[IModelJsFs]].
340
+ * @public
341
+ */
342
+ class Platform {
343
+ /** Get the name of the platform. */
344
+ static get platformName() {
345
+ return process.platform;
346
+ }
347
+ /** @internal */
348
+ static load() {
349
+ return core_bentley_1.ProcessDetector.isMobileAppBackend ? process._linkedBinding("iModelJsNative") : imodeljs_native_1.NativeLibrary.load();
350
+ }
351
+ }
352
+ exports.Platform = Platform;
353
+ /** Well known directories that may be used by the application. Also see [[Platform]]
354
+ * @public
355
+ */
356
+ class KnownLocations {
357
+ /** The directory where the imodeljs-native assets are stored. */
358
+ static get nativeAssetsDir() { return IModelHost.platform.DgnDb.getAssetsDir(); }
359
+ /** The directory where the core-backend assets are stored. */
360
+ static get packageAssetsDir() {
361
+ return path.join(__dirname, "assets");
362
+ }
363
+ /** The temporary directory. */
364
+ static get tmpdir() {
365
+ return os.tmpdir();
366
+ }
367
+ }
368
+ exports.KnownLocations = KnownLocations;
369
+ /** Extend this class to provide custom file name resolution behavior.
370
+ * @note Only `tryResolveKey` and/or `tryResolveFileName` need to be overridden as the implementations of `resolveKey` and `resolveFileName` work for most purposes.
371
+ * @see [[IModelHost.snapshotFileNameResolver]]
372
+ * @public
373
+ */
374
+ class FileNameResolver {
375
+ /** Resolve a file name from the specified key.
376
+ * @param _fileKey The key that identifies the file name in a `Map` or other similar data structure.
377
+ * @returns The resolved file name or `undefined` if not found.
378
+ */
379
+ tryResolveKey(_fileKey) { return undefined; }
380
+ /** Resolve a file name from the specified key.
381
+ * @param fileKey The key that identifies the file name in a `Map` or other similar data structure.
382
+ * @returns The resolved file name.
383
+ * @throws [[IModelError]] if not found.
384
+ */
385
+ resolveKey(fileKey) {
386
+ const resolvedFileName = this.tryResolveKey(fileKey);
387
+ if (undefined === resolvedFileName) {
388
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, `${fileKey} not resolved`);
389
+ }
390
+ return resolvedFileName;
391
+ }
392
+ /** Resolve the input file name, which may be a partial name, into a full path file name.
393
+ * @param inFileName The partial file name.
394
+ * @returns The resolved full path file name or `undefined` if not found.
395
+ */
396
+ tryResolveFileName(inFileName) { return inFileName; }
397
+ /** Resolve the input file name, which may be a partial name, into a full path file name.
398
+ * @param inFileName The partial file name.
399
+ * @returns The resolved full path file name.
400
+ * @throws [[IModelError]] if not found.
401
+ */
402
+ resolveFileName(inFileName) {
403
+ const resolvedFileName = this.tryResolveFileName(inFileName);
404
+ if (undefined === resolvedFileName) {
405
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, `${inFileName} not resolved`);
406
+ }
407
+ return resolvedFileName;
408
+ }
409
+ }
410
+ exports.FileNameResolver = FileNameResolver;
411
+ //# sourceMappingURL=IModelHost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IModelHost.js","sourceRoot":"","sources":["../../src/IModelHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yBAAyB;AACzB,6BAA6B;AAC7B,iCAAiC;AACjC,8DAAyE;AACzE,gEAA6D;AAC7D,sDAA+I;AAC/I,oDAAmG;AACnG,qEAAkE;AAElE,mEAAgE;AAChE,mDAAgD;AAChD,yDAAsD;AACtD,+DAAwI;AACxI,iEAA8D;AAC9D,2DAAwD;AACxD,6CAA0C;AAC1C,gEAA6D;AAC7D,oEAAiE;AACjE,oEAAiE;AACjE,4EAAyE;AACzE,sDAAmD;AACnD,6CAAoD;AAEpD,MAAM,cAAc,GAAG,6CAAqB,CAAC,UAAU,CAAC;AAqCxD;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,CAAC,CAAC;IAChF;;;;OAIG;IACI,UAAU,CAAC,OAAe;QAC/B,MAAM,gBAAgB,GAAuB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACzE,IAAI,SAAS,KAAK,gBAAgB,EAAE;YAClC,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,QAAQ,EAAE,GAAG,OAAO,eAAe,CAAC,CAAC;SACzE;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IACD;;;OAGG;IACI,kBAAkB,CAAC,UAAkB,IAAwB,OAAO,UAAU,CAAC,CAAC,CAAC;IACxF;;;;OAIG;IACI,eAAe,CAAC,UAAkB;QACvC,MAAM,gBAAgB,GAAuB,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACjF,IAAI,SAAS,KAAK,gBAAgB,EAAE;YAClC,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,QAAQ,EAAE,GAAG,UAAU,eAAe,CAAC,CAAC;SAC5E;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAnCD,4CAmCC","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 IModelHost\r\n */\r\n\r\nimport * as os from \"os\";\r\nimport * as path from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative, NativeLibrary } from \"@bentley/imodeljs-native\";\r\nimport { TelemetryManager } from \"@bentley/telemetry-client\";\r\nimport { AccessToken, assert, BeEvent, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport { AuthorizationClient, BentleyStatus, IModelError, SessionProps } from \"@itwin/core-common\";\r\nimport { AliCloudStorageService } from \"./AliCloudStorageService\";\r\nimport { BackendHubAccess } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BisCoreSchema } from \"./BisCoreSchema\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { AzureBlobStorage, CloudStorageService, CloudStorageServiceCredentials, CloudStorageTileUploader } from \"./CloudStorageBackend\";\r\nimport { FunctionalSchema } from \"./domains/FunctionalSchema\";\r\nimport { GenericSchema } from \"./domains/GenericSchema\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { DevToolsRpcImpl } from \"./rpc-impl/DevToolsRpcImpl\";\r\nimport { IModelReadRpcImpl } from \"./rpc-impl/IModelReadRpcImpl\";\r\nimport { IModelTileRpcImpl } from \"./rpc-impl/IModelTileRpcImpl\";\r\nimport { SnapshotIModelRpcImpl } from \"./rpc-impl/SnapshotIModelRpcImpl\";\r\nimport { WipRpcImpl } from \"./rpc-impl/WipRpcImpl\";\r\nimport { initializeRpcBackend } from \"./RpcBackend\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelHost;\r\n\r\n// cspell:ignore nodereport fatalerror apicall alicloud rpcs\r\n\r\n/** @alpha */\r\nexport interface CrashReportingConfigNameValuePair {\r\n name: string;\r\n value: string;\r\n}\r\n\r\n/** Configuration of the crash-reporting system.\r\n * @alpha\r\n */\r\nexport interface CrashReportingConfig {\r\n /** The directory to which *.dmp and/or iModelJsNativeCrash*.properties.txt files are written. This directory will be created if it does not already exist. */\r\n crashDir: string;\r\n /** max # .dmp files that may exist in crashDir. The default is 50. */\r\n maxDumpsInDir?: number;\r\n /** Enable crash-dumps? If so, .dmp and .properties.txt files will be generated and written to crashDir in the event of an unhandled native-code exception. If not, only .properties.txt files will be written. The default is false. */\r\n enableCrashDumps?: boolean;\r\n /** If enableCrashDumps is true, do you want a full-memory dump? Defaults to false. */\r\n wantFullMemoryDumps?: boolean;\r\n /** Enable node-report? If so, node-report files will be generated in the event of an unhandled exception or fatal error and written to crashDir. The default is false. */\r\n enableNodeReport?: boolean;\r\n /** Additional name, value pairs to write to iModelJsNativeCrash*.properties.txt file in the event of a crash. */\r\n params?: CrashReportingConfigNameValuePair[];\r\n /** Run this .js file to process .dmp and node-report files in the event of a crash.\r\n * This script will be executed with a single command-line parameter: the name of the dump or node-report file.\r\n * In the case of a dump file, there will be a second file with the same basename and the extension \".properties.txt\".\r\n * Since it runs in a separate process, this script will have no access to the Javascript\r\n * context of the exiting backend. No default.\r\n */\r\n dumpProcessorScriptFileName?: string;\r\n /** Upload crash dump and node-reports to Bentley's crash-reporting service? Defaults to false */\r\n uploadToBentley?: boolean;\r\n}\r\n\r\n/** Configuration of core-backend.\r\n * @public\r\n */\r\nexport class IModelHostConfiguration {\r\n\r\n /**\r\n * Root of the directory holding all the files that iModel.js caches\r\n * - If not specified at startup a platform specific default is used -\r\n * - Windows: $(HOMEDIR)/AppData/Local/iModelJs/\r\n * - Mac/iOS: $(HOMEDIR)/Library/Caches/iModelJs/\r\n * - Linux: $(HOMEDIR)/.cache/iModelJs/\r\n * where $(HOMEDIR) is documented [here](https://nodejs.org/api/os.html#os_os_homedir)\r\n * - if specified, ensure it is set to a folder with read/write access.\r\n * - Sub-folders within this folder organize various caches -\r\n * - bc/ -> Briefcases\r\n * - appSettings/ -> Offline application settings (only relevant in native applications)\r\n * - etc.\r\n * @see [[IModelHost.cacheDir]] for the value it's set to after startup\r\n */\r\n public cacheDir?: string;\r\n\r\n /** The directory where the app's assets are found. */\r\n public appAssetsDir?: string;\r\n\r\n /** The kind of iModel hub server to use.\r\n * @beta\r\n */\r\n public hubAccess?: BackendHubAccess;\r\n\r\n /** The credentials to use for the tile cache service. If omitted, a local cache will be used.\r\n * @beta\r\n */\r\n public tileCacheCredentials?: CloudStorageServiceCredentials;\r\n\r\n /** Whether to restrict tile cache URLs by client IP address (if available).\r\n * @beta\r\n */\r\n public restrictTileUrlsByClientIp?: boolean;\r\n\r\n /** Whether to compress cached tiles.\r\n * Defaults to `true`.\r\n */\r\n public compressCachedTiles?: boolean;\r\n\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public tileTreeRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public tileContentRequestTimeout = IModelHostConfiguration.defaultTileRequestTimeout;\r\n /** The default time, in milliseconds, used for [[tileTreeRequestTimeout]] and [[tileContentRequestTimeout]]. To change this, override one or both of those properties.\r\n * @internal\r\n */\r\n public static defaultTileRequestTimeout = 20 * 1000;\r\n\r\n /** The default time, in seconds, used for [[logTileLoadTimeThreshold]]. To change this, override that property.\r\n * @internal\r\n */\r\n public static defaultLogTileLoadTimeThreshold = 40;\r\n /** The backend will log when a tile took longer to load than this threshold in seconds.\r\n * @internal\r\n */\r\n public logTileLoadTimeThreshold: number = IModelHostConfiguration.defaultLogTileLoadTimeThreshold;\r\n\r\n /** The default size, in bytes, used for [[logTileSizeThreshold]]. To change this, override that property.\r\n * @internal\r\n */\r\n public static defaultLogTileSizeThreshold = 20 * 1000000;\r\n /** The backend will log when a tile is loaded with a size in bytes above this threshold.\r\n * @internal\r\n */\r\n public logTileSizeThreshold: number = IModelHostConfiguration.defaultLogTileSizeThreshold;\r\n\r\n /** Crash-reporting configuration\r\n * @alpha\r\n */\r\n public crashReportingConfig?: CrashReportingConfig;\r\n\r\n}\r\n\r\n/** IModelHost initializes ($backend) and captures its configuration. A backend must call [[IModelHost.startup]] before using any backend classes.\r\n * See [the learning article]($docs/learning/backend/IModelHost.md)\r\n * @public\r\n */\r\nexport class IModelHost {\r\n private constructor() { }\r\n public static authorizationClient?: AuthorizationClient;\r\n\r\n /** @alpha */\r\n public static readonly telemetry = new TelemetryManager();\r\n\r\n public static backendVersion = \"\";\r\n private static _cacheDir = \"\";\r\n\r\n private static _platform?: typeof IModelJsNative;\r\n /** @internal */\r\n public static get platform(): typeof IModelJsNative {\r\n if (this._platform === undefined)\r\n throw new Error(\"IModelHost.startup must be called first\");\r\n return this._platform;\r\n }\r\n\r\n public static configuration?: IModelHostConfiguration;\r\n /** Event raised just after the backend IModelHost was started */\r\n public static readonly onAfterStartup = new BeEvent<() => void>();\r\n\r\n /** Event raised just before the backend IModelHost is to be shut down */\r\n public static readonly onBeforeShutdown = new BeEvent<() => void>();\r\n\r\n /** @internal */\r\n public static readonly session: Mutable<SessionProps> = { applicationId: \"2686\", applicationVersion: \"1.0.0\", sessionId: \"\" };\r\n\r\n /** A uniqueId for this session */\r\n public static get sessionId() { return this.session.sessionId; }\r\n public static set sessionId(id: GuidString) { this.session.sessionId = id; }\r\n\r\n /** The Id of this application - needs to be set only if it is an agent application. The applicationId will otherwise originate at the frontend. */\r\n public static get applicationId() { return this.session.applicationId; }\r\n public static set applicationId(id: string) { this.session.applicationId = id; }\r\n\r\n /** The version of this application - needs to be set if is an agent application. The applicationVersion will otherwise originate at the frontend. */\r\n public static get applicationVersion() { return this.session.applicationVersion; }\r\n public static set applicationVersion(version: string) { this.session.applicationVersion = version; }\r\n\r\n /** Root of the directory holding all the files that iModel.js caches */\r\n public static get cacheDir(): string { return this._cacheDir; }\r\n\r\n /** The optional [[FileNameResolver]] that resolves keys and partial file names for snapshot iModels. */\r\n public static snapshotFileNameResolver?: FileNameResolver;\r\n\r\n /** Get the current access token for this IModelHost, or a blank string if none is available.\r\n * @note for web backends, this will *always* return a blank string because the backend itself has no token (but never needs one either.)\r\n * For all IpcHosts, where this backend is servicing a single frontend, this will be the user's token. For ElectronHost, the backend\r\n * obtains the token and forwards it to the frontend.\r\n * @note accessTokens expire periodically and are automatically refreshed, if possible. Therefore tokens should not be saved, and the value\r\n * returned by this method may change over time throughout the course of a session.\r\n */\r\n public static async getAccessToken(): Promise<AccessToken> {\r\n try {\r\n return (await this.authorizationClient?.getAccessToken()) ?? \"\";\r\n } catch (e) {\r\n return \"\";\r\n }\r\n }\r\n\r\n /** @internal */\r\n public static flushLog() {\r\n return this.platform.DgnDb.flushLog();\r\n }\r\n /** @internal */\r\n public static loadNative(): void {\r\n const platform = Platform.load();\r\n this.registerPlatform(platform);\r\n }\r\n\r\n private static registerPlatform(platform: typeof IModelJsNative): void {\r\n this._platform = platform;\r\n if (undefined === platform)\r\n return;\r\n\r\n if (!ProcessDetector.isMobileAppBackend)\r\n this.validateNativePlatformVersion();\r\n\r\n platform.logger = Logger;\r\n }\r\n\r\n private static validateNativePlatformVersion(): void {\r\n const requiredVersion = require(\"../../package.json\").dependencies[\"@bentley/imodeljs-native\"]; // eslint-disable-line @typescript-eslint/no-var-requires\r\n const thisVersion = this.platform.version;\r\n if (semver.satisfies(thisVersion, requiredVersion))\r\n return;\r\n if (IModelJsFs.existsSync(path.join(__dirname, \"DevBuild.txt\"))) {\r\n console.log(\"Bypassing version checks for development build\"); // eslint-disable-line no-console\r\n return;\r\n }\r\n this._platform = undefined;\r\n throw new IModelError(IModelStatus.BadRequest, `imodeljs-native version is (${thisVersion}). core-backend requires version (${requiredVersion})`);\r\n }\r\n\r\n /**\r\n * @beta\r\n * @note A reference implementation is set by default for [AzureBlobStorage]. To supply a different implementation for any service provider (such as AWS),\r\n * set this property with a custom [CloudStorageService] and also set [IModelHostConfiguration.tileCacheCredentials] using \"external\" for the service name.\r\n * Note that the account and access key members of [CloudStorageServiceCredentials] may have blank values unless the custom service implementation uses them.\r\n */\r\n public static tileCacheService: CloudStorageService;\r\n\r\n /** @internal */\r\n public static tileUploader: CloudStorageTileUploader;\r\n\r\n private static _hubAccess: BackendHubAccess;\r\n /** @internal */\r\n public static setHubAccess(hubAccess: BackendHubAccess) { this._hubAccess = hubAccess; }\r\n\r\n /** Provides access to the IModelHub for this IModelHost\r\n * @beta\r\n */\r\n public static get hubAccess(): BackendHubAccess { return this._hubAccess; }\r\n\r\n private static _isValid = false;\r\n /** Returns true if IModelHost is started. */\r\n public static get isValid() { return this._isValid; }\r\n /** This method must be called before any iModel.js services are used.\r\n * @param configuration Host configuration data.\r\n * Raises [[onAfterStartup]].\r\n * @see [[shutdown]].\r\n */\r\n public static async startup(configuration: IModelHostConfiguration = new IModelHostConfiguration()): Promise<void> {\r\n if (this._isValid)\r\n return; // we're already initialized\r\n this._isValid = true;\r\n\r\n if (IModelHost.sessionId === \"\")\r\n IModelHost.sessionId = Guid.createValue();\r\n\r\n this.logStartup();\r\n\r\n this.backendVersion = require(\"../../package.json\").version; // eslint-disable-line @typescript-eslint/no-var-requires\r\n initializeRpcBackend();\r\n\r\n if (this._platform === undefined) {\r\n try {\r\n this.loadNative();\r\n } catch (error) {\r\n Logger.logError(loggerCategory, \"Error registering/loading the native platform API\", () => (configuration));\r\n throw error;\r\n }\r\n }\r\n\r\n if (configuration.crashReportingConfig && configuration.crashReportingConfig.crashDir && !ProcessDetector.isElectronAppBackend && !ProcessDetector.isMobileAppBackend) {\r\n this.platform.setCrashReporting(configuration.crashReportingConfig);\r\n\r\n Logger.logTrace(loggerCategory, \"Configured crash reporting\", () => ({\r\n enableCrashDumps: configuration.crashReportingConfig?.enableCrashDumps,\r\n wantFullMemoryDumps: configuration.crashReportingConfig?.wantFullMemoryDumps,\r\n enableNodeReport: configuration.crashReportingConfig?.enableNodeReport,\r\n uploadToBentley: configuration.crashReportingConfig?.uploadToBentley,\r\n }));\r\n\r\n if (configuration.crashReportingConfig.enableNodeReport) {\r\n try {\r\n // node-report reports on V8 fatal errors and unhandled exceptions/Promise rejections.\r\n const nodereport = require(\"node-report/api\"); // eslint-disable-line @typescript-eslint/no-var-requires\r\n nodereport.setEvents(\"exception+fatalerror+apicall\");\r\n nodereport.setDirectory(configuration.crashReportingConfig.crashDir);\r\n nodereport.setVerbose(\"yes\");\r\n Logger.logTrace(loggerCategory, \"Configured native crash reporting (node-report)\");\r\n } catch (err) {\r\n Logger.logWarning(loggerCategory, \"node-report is not installed.\");\r\n }\r\n }\r\n }\r\n\r\n this.setupCacheDirs(configuration);\r\n BriefcaseManager.initialize(this._briefcaseCacheDir);\r\n\r\n [\r\n IModelReadRpcImpl,\r\n IModelTileRpcImpl,\r\n SnapshotIModelRpcImpl,\r\n WipRpcImpl,\r\n DevToolsRpcImpl,\r\n ].forEach((rpc) => rpc.register()); // register all of the RPC implementations\r\n\r\n [\r\n BisCoreSchema,\r\n GenericSchema,\r\n FunctionalSchema,\r\n ].forEach((schema) => schema.registerSchema()); // register all of the schemas\r\n\r\n if (undefined !== configuration.hubAccess)\r\n IModelHost._hubAccess = configuration.hubAccess;\r\n IModelHost.configuration = configuration;\r\n IModelHost.setupTileCache();\r\n\r\n this.platform.setUseTileCache(configuration.tileCacheCredentials ? false : true);\r\n\r\n process.once(\"beforeExit\", IModelHost.shutdown);\r\n IModelHost.onAfterStartup.raiseEvent();\r\n }\r\n\r\n private static _briefcaseCacheDir: string;\r\n\r\n private static logStartup() {\r\n if (!Logger.isEnabled(loggerCategory, LogLevel.Trace))\r\n return;\r\n\r\n // Extract the iModel details from environment - note this is very specific to Bentley hosted backends, but is quite useful for tracing\r\n let startupInfo: any = {};\r\n const serviceName = process.env.FABRIC_SERVICE_NAME;\r\n if (serviceName) {\r\n // e.g., fabric:/iModelWebViewer3.0/iModelJSGuest/1/08daaeb3-b56f-480b-9051-7efc834d18ae/512d971d-b641-4735-bb1c-c07ab3e44ce7/c1315fcce125ca40b2d405bb7809214daf8b4c85\r\n const serviceNameComponents = serviceName.split(\"/\");\r\n if (serviceNameComponents.length === 7) {\r\n startupInfo = {\r\n ...startupInfo,\r\n iTwinId: serviceNameComponents[4],\r\n iModelId: serviceNameComponents[5],\r\n changesetId: serviceNameComponents[6],\r\n };\r\n }\r\n }\r\n\r\n Logger.logTrace(loggerCategory, \"IModelHost.startup\", () => startupInfo);\r\n }\r\n\r\n private static setupCacheDirs(configuration: IModelHostConfiguration) {\r\n this._cacheDir = configuration.cacheDir ? path.normalize(configuration.cacheDir) : NativeLibrary.defaultCacheDir;\r\n IModelJsFs.recursiveMkDirSync(this._cacheDir); // make sure the directory for cacheDir exists.\r\n this._briefcaseCacheDir = path.join(this._cacheDir, \"imodels\");\r\n }\r\n\r\n /** This method must be called when an iModel.js services is shut down. Raises [[onBeforeShutdown]] */\r\n public static async shutdown(): Promise<void> {\r\n // NB: This method is set as a node listener where `this` is unbound\r\n if (!IModelHost._isValid)\r\n return;\r\n\r\n IModelHost._isValid = false;\r\n IModelHost.onBeforeShutdown.raiseEvent();\r\n IModelHost.configuration = undefined;\r\n process.removeListener(\"beforeExit\", IModelHost.shutdown);\r\n }\r\n\r\n /**\r\n * Add or update a property that should be included in a crash report.\r\n * @param name The name of the property\r\n * @param value The value of the property\r\n * @alpha\r\n */\r\n public static setCrashReportProperty(name: string, value: string): void {\r\n assert(undefined !== this._platform);\r\n this._platform.setCrashReportProperty(name, value);\r\n }\r\n\r\n /**\r\n * Remove a previously defined property so that will not be included in a crash report.\r\n * @param name The name of the property\r\n * @alpha\r\n */\r\n public static removeCrashReportProperty(name: string): void {\r\n assert(undefined !== this._platform);\r\n this._platform.setCrashReportProperty(name, undefined);\r\n }\r\n\r\n /**\r\n * Get all properties that will be included in a crash report.\r\n * @alpha\r\n */\r\n public static getCrashReportProperties(): CrashReportingConfigNameValuePair[] {\r\n assert(undefined !== this._platform);\r\n return this._platform.getCrashReportProperties();\r\n }\r\n\r\n /** The directory where application assets may be found */\r\n public static get appAssetsDir(): string | undefined { return undefined !== IModelHost.configuration ? IModelHost.configuration.appAssetsDir : undefined; }\r\n\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileTreeProps]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public static get tileTreeRequestTimeout(): number {\r\n return undefined !== IModelHost.configuration ? IModelHost.configuration.tileTreeRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;\r\n }\r\n /** The time, in milliseconds, for which [IModelTileRpcInterface.requestTileContent]($common) should wait before returning a \"pending\" status.\r\n * @internal\r\n */\r\n public static get tileContentRequestTimeout(): number {\r\n return undefined !== IModelHost.configuration ? IModelHost.configuration.tileContentRequestTimeout : IModelHostConfiguration.defaultTileRequestTimeout;\r\n }\r\n\r\n /** The backend will log when a tile took longer to load than this threshold in seconds. */\r\n public static get logTileLoadTimeThreshold(): number { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileLoadTimeThreshold : IModelHostConfiguration.defaultLogTileLoadTimeThreshold; }\r\n /** The backend will log when a tile is loaded with a size in bytes above this threshold. */\r\n public static get logTileSizeThreshold(): number { return undefined !== IModelHost.configuration ? IModelHost.configuration.logTileSizeThreshold : IModelHostConfiguration.defaultLogTileSizeThreshold; }\r\n\r\n /** Whether external tile caching is active.\r\n * @internal\r\n */\r\n public static get usingExternalTileCache(): boolean {\r\n return undefined !== IModelHost.configuration?.tileCacheCredentials;\r\n }\r\n\r\n /** Whether to restrict tile cache URLs by client IP address.\r\n * @internal\r\n */\r\n public static get restrictTileUrlsByClientIp(): boolean { return undefined !== IModelHost.configuration && (IModelHost.configuration.restrictTileUrlsByClientIp ? true : false); }\r\n\r\n /** Whether to compress cached tiles.\r\n * @internal\r\n */\r\n public static get compressCachedTiles(): boolean { return false !== IModelHost.configuration?.compressCachedTiles; }\r\n\r\n private static setupTileCache() {\r\n const config = IModelHost.configuration!;\r\n const credentials = config.tileCacheCredentials;\r\n if (undefined === credentials)\r\n return;\r\n\r\n IModelHost.tileUploader = new CloudStorageTileUploader();\r\n\r\n if (credentials.service === \"azure\" && !IModelHost.tileCacheService) {\r\n IModelHost.tileCacheService = new AzureBlobStorage(credentials);\r\n } else if (credentials.service === \"alicloud\") {\r\n IModelHost.tileCacheService = new AliCloudStorageService(credentials);\r\n } else if (credentials.service !== \"external\") {\r\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported cloud service credentials for tile cache.\");\r\n }\r\n }\r\n}\r\n\r\n/** Information about the platform on which the app is running. Also see [[KnownLocations]] and [[IModelJsFs]].\r\n * @public\r\n */\r\nexport class Platform {\r\n /** Get the name of the platform. */\r\n public static get platformName(): \"win32\" | \"linux\" | \"darwin\" | \"ios\" | \"android\" | \"uwp\" {\r\n return process.platform as any;\r\n }\r\n\r\n /** @internal */\r\n public static load(): typeof IModelJsNative {\r\n return ProcessDetector.isMobileAppBackend ? (process as any)._linkedBinding(\"iModelJsNative\") : NativeLibrary.load();\r\n }\r\n}\r\n\r\n/** Well known directories that may be used by the application. Also see [[Platform]]\r\n * @public\r\n */\r\nexport class KnownLocations {\r\n\r\n /** The directory where the imodeljs-native assets are stored. */\r\n public static get nativeAssetsDir(): string { return IModelHost.platform.DgnDb.getAssetsDir(); }\r\n\r\n /** The directory where the core-backend assets are stored. */\r\n public static get packageAssetsDir(): string {\r\n return path.join(__dirname, \"assets\");\r\n }\r\n\r\n /** The temporary directory. */\r\n public static get tmpdir(): string {\r\n return os.tmpdir();\r\n }\r\n}\r\n\r\n/** Extend this class to provide custom file name resolution behavior.\r\n * @note Only `tryResolveKey` and/or `tryResolveFileName` need to be overridden as the implementations of `resolveKey` and `resolveFileName` work for most purposes.\r\n * @see [[IModelHost.snapshotFileNameResolver]]\r\n * @public\r\n */\r\nexport abstract class FileNameResolver {\r\n /** Resolve a file name from the specified key.\r\n * @param _fileKey The key that identifies the file name in a `Map` or other similar data structure.\r\n * @returns The resolved file name or `undefined` if not found.\r\n */\r\n public tryResolveKey(_fileKey: string): string | undefined { return undefined; }\r\n /** Resolve a file name from the specified key.\r\n * @param fileKey The key that identifies the file name in a `Map` or other similar data structure.\r\n * @returns The resolved file name.\r\n * @throws [[IModelError]] if not found.\r\n */\r\n public resolveKey(fileKey: string): string {\r\n const resolvedFileName: string | undefined = this.tryResolveKey(fileKey);\r\n if (undefined === resolvedFileName) {\r\n throw new IModelError(IModelStatus.NotFound, `${fileKey} not resolved`);\r\n }\r\n return resolvedFileName;\r\n }\r\n /** Resolve the input file name, which may be a partial name, into a full path file name.\r\n * @param inFileName The partial file name.\r\n * @returns The resolved full path file name or `undefined` if not found.\r\n */\r\n public tryResolveFileName(inFileName: string): string | undefined { return inFileName; }\r\n /** Resolve the input file name, which may be a partial name, into a full path file name.\r\n * @param inFileName The partial file name.\r\n * @returns The resolved full path file name.\r\n * @throws [[IModelError]] if not found.\r\n */\r\n public resolveFileName(inFileName: string): string {\r\n const resolvedFileName: string | undefined = this.tryResolveFileName(inFileName);\r\n if (undefined === resolvedFileName) {\r\n throw new IModelError(IModelStatus.NotFound, `${inFileName} not resolved`);\r\n }\r\n return resolvedFileName;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,63 @@
1
+ /// <reference types="node" />
2
+ /** Information about a file. See [[IModelJsFs.lstatSync]]
3
+ * @public
4
+ */
5
+ export declare class IModelJsFsStats {
6
+ size: number;
7
+ atimeMs: number;
8
+ mtimeMs: number;
9
+ birthtimeMs: number;
10
+ isDirectory: boolean;
11
+ isFile: boolean;
12
+ isSocket: boolean;
13
+ isSymbolicLink: boolean;
14
+ isReadOnly: boolean;
15
+ constructor(size: number, atimeMs: number, mtimeMs: number, birthtimeMs: number, isDirectory: boolean, isFile: boolean, isSocket: boolean, isSymbolicLink: boolean, isReadOnly: boolean);
16
+ }
17
+ /** File system operations that are defined on all platforms. See also [[Platform]] and [[KnownLocations]]
18
+ * @public
19
+ */
20
+ export declare class IModelJsFs {
21
+ /** Does file or directory exist? */
22
+ static existsSync(pathname: string): boolean;
23
+ /** Delete a file. */
24
+ static unlinkSync(pathname: string): void;
25
+ /** Delete a file or remove a directory (rm -r). */
26
+ static removeSync(pathname: string): void;
27
+ /** Create a directory. */
28
+ static mkdirSync(pathname: string): void;
29
+ /** Remove a directory. */
30
+ static rmdirSync(pathname: string): void;
31
+ /** Write to a file. */
32
+ static writeFileSync(pathname: string, data: string | Uint8Array, wflag?: string): void;
33
+ /** Append to a file. */
34
+ static appendFileSync(pathname: string, str: string): void;
35
+ /** Make a copy of a file */
36
+ static copySync(src: string, dest: string, opts?: any): void;
37
+ /** Get the file and directory names in the specified directory. Excludes "." and "..". */
38
+ static readdirSync(pathname: string): string[];
39
+ /** Read file */
40
+ static readFileSync(pathname: string): string | Buffer;
41
+ /** Test if the current user has permission to write to a file. */
42
+ private static isFileWritable;
43
+ /** Get information about a file. */
44
+ static lstatSync(pathname: string): IModelJsFsStats | undefined;
45
+ /**
46
+ * Finds files recursively based on a pattern
47
+ * @param rootDir Directory from where to start searching for files.
48
+ * @param pattern A Regex that would be match to basename of files including extension
49
+ * @returns list of file that match the pattern.
50
+ */
51
+ static recursiveFindSync(rootDir: string, pattern: RegExp): string[];
52
+ /**
53
+ * Walks a directory in breadth first fashion
54
+ * @param rootDir directory from where the traversal starts
55
+ * @param cb callback that would be called with full path of file or directory
56
+ */
57
+ static walkDirSync(rootDir: string, cb: (pathname: string, isDir: boolean) => boolean): void;
58
+ /** Create a directory, recursively setting up the path as necessary */
59
+ static recursiveMkDirSync(dirPath: string): void;
60
+ /** Remove a directory, recursively */
61
+ static purgeDirSync(dirPath: string): void;
62
+ }
63
+ //# sourceMappingURL=IModelJsFs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IModelJsFs.d.ts","sourceRoot":"","sources":["../../src/IModelJsFs.ts"],"names":[],"mappings":";AAeA;;GAEG;AACH,qBAAa,eAAe;IAEjB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,OAAO;IACpB,MAAM,EAAE,OAAO;IACf,QAAQ,EAAE,OAAO;IACjB,cAAc,EAAE,OAAO;IACvB,UAAU,EAAE,OAAO;gBARnB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,OAAO,EACvB,UAAU,EAAE,OAAO;CAE7B;AAED;;GAEG;AACH,qBAAa,UAAU;IAErB,oCAAoC;WACtB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAEnD,qBAAqB;WACP,UAAU,CA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