@itwin/core-backend 4.0.0-dev.8 → 4.0.0-dev.81

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 (259) hide show
  1. package/CHANGELOG.md +55 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +224 -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/BriefcaseManager.d.ts +170 -170
  13. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  14. package/lib/cjs/BriefcaseManager.js +408 -414
  15. package/lib/cjs/BriefcaseManager.js.map +1 -1
  16. package/lib/cjs/Category.d.ts +153 -153
  17. package/lib/cjs/Category.js +243 -243
  18. package/lib/cjs/Category.js.map +1 -1
  19. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  20. package/lib/cjs/ChangeSummaryManager.js +444 -445
  21. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  22. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  23. package/lib/cjs/ChangedElementsDb.js +165 -165
  24. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  25. package/lib/cjs/ChangedElementsManager.js +88 -88
  26. package/lib/cjs/ChannelControl.d.ts +70 -0
  27. package/lib/cjs/ChannelControl.d.ts.map +1 -0
  28. package/lib/cjs/ChannelControl.js +89 -0
  29. package/lib/cjs/ChannelControl.js.map +1 -0
  30. package/lib/cjs/CheckpointManager.d.ts +121 -121
  31. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  32. package/lib/cjs/CheckpointManager.js +351 -349
  33. package/lib/cjs/CheckpointManager.js.map +1 -1
  34. package/lib/cjs/ClassRegistry.d.ts +79 -79
  35. package/lib/cjs/ClassRegistry.js +249 -245
  36. package/lib/cjs/ClassRegistry.js.map +1 -1
  37. package/lib/cjs/CloudSqlite.d.ts +423 -350
  38. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  39. package/lib/cjs/CloudSqlite.js +189 -153
  40. package/lib/cjs/CloudSqlite.js.map +1 -1
  41. package/lib/cjs/CodeService.d.ts +437 -396
  42. package/lib/cjs/CodeService.d.ts.map +1 -1
  43. package/lib/cjs/CodeService.js +63 -63
  44. package/lib/cjs/CodeService.js.map +1 -1
  45. package/lib/cjs/CodeSpecs.d.ts +58 -55
  46. package/lib/cjs/CodeSpecs.d.ts.map +1 -1
  47. package/lib/cjs/CodeSpecs.js +154 -124
  48. package/lib/cjs/CodeSpecs.js.map +1 -1
  49. package/lib/cjs/ConcurrentQuery.d.ts +13 -13
  50. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
  51. package/lib/cjs/ConcurrentQuery.js +36 -36
  52. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  53. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  54. package/lib/cjs/CustomViewState3dCreator.js +80 -81
  55. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  56. package/lib/cjs/DevTools.d.ts +74 -71
  57. package/lib/cjs/DevTools.d.ts.map +1 -1
  58. package/lib/cjs/DevTools.js +156 -154
  59. package/lib/cjs/DevTools.js.map +1 -1
  60. package/lib/cjs/DisplayStyle.d.ts +106 -106
  61. package/lib/cjs/DisplayStyle.js +253 -256
  62. package/lib/cjs/DisplayStyle.js.map +1 -1
  63. package/lib/cjs/ECDb.d.ts +194 -191
  64. package/lib/cjs/ECDb.d.ts.map +1 -1
  65. package/lib/cjs/ECDb.js +351 -350
  66. package/lib/cjs/ECDb.js.map +1 -1
  67. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  68. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  69. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  70. package/lib/cjs/ECSqlStatement.d.ts +473 -473
  71. package/lib/cjs/ECSqlStatement.js +791 -791
  72. package/lib/cjs/Element.d.ts +1113 -1109
  73. package/lib/cjs/Element.d.ts.map +1 -1
  74. package/lib/cjs/Element.js +1424 -1427
  75. package/lib/cjs/Element.js.map +1 -1
  76. package/lib/cjs/ElementAspect.d.ts +176 -179
  77. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  78. package/lib/cjs/ElementAspect.js +203 -211
  79. package/lib/cjs/ElementAspect.js.map +1 -1
  80. package/lib/cjs/ElementGraphics.d.ts +9 -9
  81. package/lib/cjs/ElementGraphics.js +41 -41
  82. package/lib/cjs/ElementGraphics.js.map +1 -1
  83. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  84. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  85. package/lib/cjs/ElementTreeWalker.js +409 -409
  86. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  87. package/lib/cjs/Entity.d.ts +106 -106
  88. package/lib/cjs/Entity.d.ts.map +1 -1
  89. package/lib/cjs/Entity.js +135 -134
  90. package/lib/cjs/Entity.js.map +1 -1
  91. package/lib/cjs/EntityReferences.d.ts +49 -49
  92. package/lib/cjs/EntityReferences.d.ts.map +1 -1
  93. package/lib/cjs/EntityReferences.js +95 -95
  94. package/lib/cjs/ExportGraphics.d.ts +317 -317
  95. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  96. package/lib/cjs/ExportGraphics.js +208 -208
  97. package/lib/cjs/ExternalSource.d.ts +96 -96
  98. package/lib/cjs/ExternalSource.js +131 -131
  99. package/lib/cjs/ExternalSource.js.map +1 -1
  100. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  101. package/lib/cjs/GeoCoordConfig.js +85 -85
  102. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  103. package/lib/cjs/GeometrySummary.d.ts +4 -4
  104. package/lib/cjs/GeometrySummary.js +333 -333
  105. package/lib/cjs/GeometrySummary.js.map +1 -1
  106. package/lib/cjs/HubMock.d.ts +94 -94
  107. package/lib/cjs/HubMock.js +220 -222
  108. package/lib/cjs/HubMock.js.map +1 -1
  109. package/lib/cjs/IModelCloneContext.d.ts +8 -8
  110. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  111. package/lib/cjs/IModelCloneContext.js +15 -15
  112. package/lib/cjs/IModelDb.d.ts +1222 -1196
  113. package/lib/cjs/IModelDb.d.ts.map +1 -1
  114. package/lib/cjs/IModelDb.js +2389 -2392
  115. package/lib/cjs/IModelDb.js.map +1 -1
  116. package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
  117. package/lib/cjs/IModelElementCloneContext.js +159 -159
  118. package/lib/cjs/IModelHost.d.ts +368 -369
  119. package/lib/cjs/IModelHost.d.ts.map +1 -1
  120. package/lib/cjs/IModelHost.js +474 -496
  121. package/lib/cjs/IModelHost.js.map +1 -1
  122. package/lib/cjs/IModelJsFs.d.ts +62 -62
  123. package/lib/cjs/IModelJsFs.js +139 -140
  124. package/lib/cjs/IModelJsFs.js.map +1 -1
  125. package/lib/cjs/IpcHost.d.ts +104 -104
  126. package/lib/cjs/IpcHost.js +276 -278
  127. package/lib/cjs/IpcHost.js.map +1 -1
  128. package/lib/cjs/LineStyle.d.ts +311 -311
  129. package/lib/cjs/LineStyle.js +295 -295
  130. package/lib/cjs/LocalHub.d.ts +162 -162
  131. package/lib/cjs/LocalHub.d.ts.map +1 -1
  132. package/lib/cjs/LocalHub.js +579 -584
  133. package/lib/cjs/LocalHub.js.map +1 -1
  134. package/lib/cjs/LocalhostIpcHost.d.ts +21 -20
  135. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
  136. package/lib/cjs/LocalhostIpcHost.js +79 -81
  137. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  138. package/lib/cjs/Material.d.ts +131 -131
  139. package/lib/cjs/Material.js +180 -181
  140. package/lib/cjs/Material.js.map +1 -1
  141. package/lib/cjs/Model.d.ts +392 -392
  142. package/lib/cjs/Model.d.ts.map +1 -1
  143. package/lib/cjs/Model.js +489 -485
  144. package/lib/cjs/Model.js.map +1 -1
  145. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  146. package/lib/cjs/NativeAppStorage.js +202 -202
  147. package/lib/cjs/NativeAppStorage.js.map +1 -1
  148. package/lib/cjs/NativeHost.d.ts +52 -52
  149. package/lib/cjs/NativeHost.d.ts.map +1 -1
  150. package/lib/cjs/NativeHost.js +158 -163
  151. package/lib/cjs/NativeHost.js.map +1 -1
  152. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  153. package/lib/cjs/NavigationRelationship.js +225 -225
  154. package/lib/cjs/NavigationRelationship.js.map +1 -1
  155. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  156. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  157. package/lib/cjs/PromiseMemoizer.js +101 -101
  158. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  159. package/lib/cjs/PropertyStore.d.ts +132 -132
  160. package/lib/cjs/PropertyStore.js +11 -11
  161. package/lib/cjs/Relationship.d.ts +416 -416
  162. package/lib/cjs/Relationship.js +494 -494
  163. package/lib/cjs/Relationship.js.map +1 -1
  164. package/lib/cjs/RpcBackend.d.ts +5 -5
  165. package/lib/cjs/RpcBackend.js +32 -32
  166. package/lib/cjs/SQLiteDb.d.ts +219 -219
  167. package/lib/cjs/SQLiteDb.js +212 -214
  168. package/lib/cjs/SQLiteDb.js.map +1 -1
  169. package/lib/cjs/Schema.d.ts +55 -55
  170. package/lib/cjs/Schema.js +83 -83
  171. package/lib/cjs/Schema.js.map +1 -1
  172. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  173. package/lib/cjs/ServerBasedLocks.js +168 -168
  174. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  175. package/lib/cjs/SqliteStatement.d.ts +360 -360
  176. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  177. package/lib/cjs/SqliteStatement.js +586 -586
  178. package/lib/cjs/Texture.d.ts +58 -58
  179. package/lib/cjs/Texture.js +82 -82
  180. package/lib/cjs/Texture.js.map +1 -1
  181. package/lib/cjs/TileStorage.d.ts +44 -18
  182. package/lib/cjs/TileStorage.d.ts.map +1 -1
  183. package/lib/cjs/TileStorage.js +109 -90
  184. package/lib/cjs/TileStorage.js.map +1 -1
  185. package/lib/cjs/TxnManager.d.ts +202 -202
  186. package/lib/cjs/TxnManager.d.ts.map +1 -1
  187. package/lib/cjs/TxnManager.js +356 -356
  188. package/lib/cjs/TxnManager.js.map +1 -1
  189. package/lib/cjs/ViewDefinition.d.ts +435 -439
  190. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  191. package/lib/cjs/ViewDefinition.js +646 -646
  192. package/lib/cjs/ViewDefinition.js.map +1 -1
  193. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  194. package/lib/cjs/ViewStateHydrator.js +103 -103
  195. package/lib/cjs/core-backend.d.ts +183 -184
  196. package/lib/cjs/core-backend.d.ts.map +1 -1
  197. package/lib/cjs/core-backend.js +207 -204
  198. package/lib/cjs/core-backend.js.map +1 -1
  199. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  200. package/lib/cjs/domains/FunctionalElements.js +145 -145
  201. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  202. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  203. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
  204. package/lib/cjs/domains/FunctionalSchema.js +39 -40
  205. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  206. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  207. package/lib/cjs/domains/GenericElements.js +263 -263
  208. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  209. package/lib/cjs/domains/GenericSchema.js +28 -28
  210. package/lib/cjs/rpc/multipart.d.ts +11 -11
  211. package/lib/cjs/rpc/multipart.js +71 -71
  212. package/lib/cjs/rpc/tracing.d.ts +28 -28
  213. package/lib/cjs/rpc/tracing.js +73 -74
  214. package/lib/cjs/rpc/tracing.js.map +1 -1
  215. package/lib/cjs/rpc/web/logging.d.ts +9 -9
  216. package/lib/cjs/rpc/web/logging.js +43 -43
  217. package/lib/cjs/rpc/web/request.d.ts +6 -6
  218. package/lib/cjs/rpc/web/request.js +73 -74
  219. package/lib/cjs/rpc/web/request.js.map +1 -1
  220. package/lib/cjs/rpc/web/response.d.ts +6 -6
  221. package/lib/cjs/rpc/web/response.js +105 -106
  222. package/lib/cjs/rpc/web/response.js.map +1 -1
  223. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  224. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  225. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
  226. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -294
  227. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  228. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +20 -22
  229. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  230. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +190 -205
  231. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  232. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  233. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +166 -168
  234. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  235. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  236. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -43
  237. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  238. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  239. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  240. package/lib/cjs/workspace/Settings.d.ts +186 -186
  241. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  242. package/lib/cjs/workspace/Settings.js +154 -155
  243. package/lib/cjs/workspace/Settings.js.map +1 -1
  244. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  245. package/lib/cjs/workspace/SettingsSchemas.js +190 -191
  246. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  247. package/lib/cjs/workspace/Workspace.d.ts +411 -414
  248. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  249. package/lib/cjs/workspace/Workspace.js +521 -543
  250. package/lib/cjs/workspace/Workspace.js.map +1 -1
  251. package/package.json +22 -24
  252. package/lib/cjs/AliCloudStorageService.d.ts +0 -24
  253. package/lib/cjs/AliCloudStorageService.d.ts.map +0 -1
  254. package/lib/cjs/AliCloudStorageService.js +0 -72
  255. package/lib/cjs/AliCloudStorageService.js.map +0 -1
  256. package/lib/cjs/CloudStorageBackend.d.ts +0 -59
  257. package/lib/cjs/CloudStorageBackend.d.ts.map +0 -1
  258. package/lib/cjs/CloudStorageBackend.js +0 -174
  259. package/lib/cjs/CloudStorageBackend.js.map +0 -1
@@ -1,351 +1,424 @@
1
- /** @packageDocumentation
2
- * @module SQLiteDb
3
- */
4
- import { GuidString } from "@itwin/core-bentley";
5
- import { LocalDirName, LocalFileName } from "@itwin/core-common";
6
- /** Types for using SQLite files stored in cloud containers.
7
- * @beta
8
- */
9
- export declare namespace CloudSqlite {
10
- function createCloudContainer(args: ContainerAccessProps): CloudContainer;
11
- function createCloudCache(args: CloudSqlite.CacheProps): CloudSqlite.CloudCache;
12
- function startCloudPrefetch(container: CloudSqlite.CloudContainer, dbName: string, args?: CloudSqlite.PrefetchProps): CloudSqlite.CloudPrefetch;
13
- /** Properties that specify how to access the account for a cloud blob-store container. */
14
- interface AccountAccessProps {
15
- /** blob storage module: e.g. "azure", "google", "aws". May also include URI style parameters. */
16
- storageType: string;
17
- /** blob store account name, or a URI for custom domains. */
18
- accessName: string;
19
- }
20
- /** Properties of a CloudContainer. */
21
- interface ContainerProps {
22
- /** the name of the container. */
23
- containerId: string;
24
- /** an alias for the container. Defaults to `containerId` */
25
- alias?: string;
26
- /** token that grants access to the container. For sas=1 `storageType`s, this is the sasToken. For sas=0, this is the account key */
27
- accessToken: string;
28
- /** if true, container is attached with write permissions, and accessToken must provide write access to the cloud container. */
29
- writeable?: boolean;
30
- /** if true, container is attached in "secure" mode (blocks are encrypted). Only supported in daemon mode. */
31
- secure?: boolean;
32
- }
33
- /** Returned from `CloudContainer.queryDatabase` describing one database in the container */
34
- interface CachedDbProps {
35
- /** The total of (4Mb) blocks in the database. */
36
- readonly totalBlocks: number;
37
- /** the number of blocks of the database that have been downloaded into the CloudCache */
38
- readonly localBlocks: number;
39
- /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */
40
- readonly dirtyBlocks: number;
41
- /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */
42
- readonly transactions: boolean;
43
- /** the state of this database. Indicates whether the database is new or deleted since last upload */
44
- readonly state: "" | "copied" | "deleted";
45
- }
46
- /** Properties for accessing a CloudContainer */
47
- type ContainerAccessProps = AccountAccessProps & ContainerProps & {
48
- /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */
49
- durationSeconds?: number;
50
- };
51
- /** The name of a CloudSqlite database within a CloudContainer. */
52
- interface DbNameProp {
53
- /** the name of the database within the CloudContainer.
54
- * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/
55
- dbName: string;
56
- }
57
- /** Properties for accessing a database within a CloudContainer */
58
- interface DbProps extends DbNameProp {
59
- /** the name of the local file to access the database. */
60
- localFileName: LocalFileName;
61
- }
62
- type TransferDirection = "upload" | "download";
63
- interface TransferProgress {
64
- /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */
65
- onProgress?: (loaded: number, total: number) => number;
66
- }
67
- interface CloudHttpProps {
68
- /** The number of simultaneous HTTP requests. Default is 6. */
69
- nRequests?: number;
70
- }
71
- interface PrefetchProps extends CloudHttpProps {
72
- /** timeout between requests, in milliseconds. Default is 100. */
73
- timeout?: number;
74
- /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */
75
- minRequests?: number;
76
- }
77
- type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;
78
- /** Properties for creating a CloudCache. */
79
- interface CacheProps extends CloudHttpProps {
80
- /** full path of directory for cache to store its files. Must be on a (preferably fast) local drive, and must be empty when the cache is first created. */
81
- rootDir: string;
82
- /** name of this cache. It is possible to have more than one CloudCache in the same session. */
83
- name: string;
84
- /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */
85
- cacheSize?: string;
86
- /** turn on diagnostics for `curl` (outputs to stderr) */
87
- curlDiagnostics?: boolean;
88
- }
89
- /** Parameters used to obtain the write lock on a cloud container
90
- * @internal
91
- */
92
- interface ObtainLockParams {
93
- /** The name of the user attempting to acquire the write lock. This name will be shown to other users while the lock is held. */
94
- user?: string;
95
- /** number of times to retry in the event the lock currently held by someone else.
96
- * After this number of attempts, `onFailure` is called. Default is 20.
97
- */
98
- nRetries: number;
99
- /** Delay between retries, in milliseconds. Default is 100. */
100
- retryDelayMs: number;
101
- /** function called if lock cannot be obtained after all retries. It is called with the name of the user currently holding the lock and
102
- * generally is expected that the user will be consulted whether to wait further.
103
- * If this function returns "stop", an exception will be thrown. Otherwise the retry cycle is restarted.
104
- */
105
- onFailure?: WriteLockBusyHandler;
106
- }
107
- /** @internal */
108
- interface LockAndOpenArgs {
109
- /** the name to be displayed in the event of lock collisions */
110
- user: string;
111
- /** the name of the database within the container */
112
- dbName: string;
113
- /** the CloudContainer on which the operation will be performed */
114
- container: CloudContainer;
115
- /** if present, function called when the write lock is currently held by another user. */
116
- busyHandler?: WriteLockBusyHandler;
117
- }
118
- /** Logging categories for `CloudCache.setLogMask` */
119
- enum LoggingMask {
120
- /** log all HTTP requests and responses */
121
- HTTP = 1,
122
- /** log as blocks become dirty and must be uploaded */
123
- DirtyBlocks = 2,
124
- /** log as blocks are added to the delete list */
125
- AddToDelete = 4,
126
- /** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */
127
- LifecycleEvents = 8,
128
- /** Turn on all logging categories */
129
- All = 255,
130
- /** Disable logging */
131
- None = 0
132
- }
133
- /**
134
- * A cache for storing data from CloudSqlite databases. This object refers to a directory on a local filesystem
135
- * and is used to **connect** CloudContainers so they may be accessed. The contents of the cache directory are entirely
136
- * controlled by CloudSqlite and should be empty when the cache is first created and never modified directly. It maintains
137
- * the state of the local data across sessions.
138
- */
139
- interface CloudCache {
140
- /** `true` if this CloudCache is connected to a daemon process */
141
- get isDaemon(): boolean;
142
- /** The name for this CloudCache. */
143
- get name(): string;
144
- /** The root directory of this CloudCache on a local drive. */
145
- get rootDir(): LocalDirName;
146
- /** The guid for this CloudCache. Used for acquiring write lock. */
147
- get guid(): GuidString;
148
- /** Configure logging for this CloudCache.
149
- * @param mask A bitmask of `LoggingMask` values
150
- * @note this method does nothing if [[isDaemon]] is true. Daemon logging is configured when the daemon is started.
151
- * @note HTTP logging can be happen on multiple threads and may be buffered. To see buffered log messages, periodically call
152
- * `IModelHost.flushLog`
153
- */
154
- setLogMask(mask: number): void;
155
- /** destroy this CloudCache. All CloudContainers should be detached before calling this. */
156
- destroy(): void;
157
- }
158
- /** A CloudSqlite container that may be connected to a CloudCache. */
159
- interface CloudContainer {
160
- readonly cache?: CloudCache;
161
- /** The ContainerId. */
162
- get containerId(): string;
163
- /** The *alias* to identify this CloudContainer in a CloudCache. Usually just the ContainerId. */
164
- get alias(): string;
165
- /** true if this CloudContainer is currently connected to a CloudCache via the `connect` method. */
166
- get isConnected(): boolean;
167
- /** true if this CloudContainer was created with the `writeable` flag (and its `accessToken` supplies write access). */
168
- get isWriteable(): boolean;
169
- /** true if this CloudContainer currently holds the write lock for its container in the cloud. */
170
- get hasWriteLock(): boolean;
171
- /** true if this CloudContainer has local changes that have not be uploaded to its container in the cloud. */
172
- get hasLocalChanges(): boolean;
173
- /** The current accessToken providing access to the cloud container */
174
- get accessToken(): string;
175
- set accessToken(val: string);
176
- /** Get the number of garbage blocks in this container that can be purged. */
177
- get garbageBlocks(): number;
178
- /** The block size for this CloudContainer. */
179
- get blockSize(): number;
180
- /**
181
- * initialize a cloud blob-store container to be used as a new Sqlite CloudContainer. This creates the manifest, and should be
182
- * performed on an empty container. If an existing manifest is present, it is destroyed and a new one is created (essentially emptying the container.)
183
- */
184
- initializeContainer(opts?: {
185
- checksumBlockNames?: boolean;
186
- blockSize?: number;
187
- }): void;
188
- /**
189
- * Attempt to acquire the write lock for this CloudContainer. For this to succeed:
190
- * 1. it must be connected to a `CloudCache`
191
- * 2. this CloudContainer must have been constructed with `writeable: true`
192
- * 3. the `accessToken` must authorize write access
193
- * 4. no other process may be holding an unexpired write lock
194
- * @throws exception if any of the above conditions fail
195
- * @note Write locks *expire* after the duration specified in the `durationSeconds` property of the constructor argument, in case a process
196
- * crashes or otherwise fails to release the lock. Calling `acquireWriteLock` with the lock already held resets the lock duration from the current time,
197
- * so long running processes should call this method periodically to ensure their lock doesn't expire (they should also make sure their accessToken is refreshed
198
- * before it expires.)
199
- * @note on success, the manifest is polled before the promise resolves.
200
- * @param user An identifier of the process/user locking the CloudContainer. In the event of a write lock
201
- * collision, this string will be included in the exception string of the *other* process attempting to obtain a write lock.
202
- */
203
- acquireWriteLock(user: string): void;
204
- /**
205
- * Release the write lock if it is currently held.
206
- * @note if there are local changes that have not been uploaded, they are automatically uploaded before the write lock is released.
207
- * @note if the write lock is not held, this method does nothing.
208
- */
209
- releaseWriteLock(): void;
210
- /**
211
- * Destroy any currently valid write lock from this or any other process. This is obviously very dangerous and defeats the purpose of write locking.
212
- * This method exists only for administrator tools to clear a failed process without waiting for the expiration period. It can also be useful for tests.
213
- * For this to succeed, all of the conditions of `acquireWriteLock` must be true other than #4.
214
- */
215
- clearWriteLock(): void;
216
- /**
217
- * Abandon any local changes in this container. If the write lock is currently held, it is released.
218
- * This function fails with BE_SQLITE_BUSY if one or more clients have open read or write transactions
219
- * on any database in the container.
220
- */
221
- abandonChanges(): void;
222
- /**
223
- * Connect this CloudContainer to a CloudCache for reading or writing its manifest, write lock, and databases.
224
- * @note A CloudCache is a local directory holding copies of information from the cloud. Its content is persistent across sessions,
225
- * but this method must be called each session to (re)establish the connection to the cache. If the CloudCache was previously populated,
226
- * this method may be called and will succeed *even when offline* or without a valid `accessToken`.
227
- * @note all operations that access the contents of databases or the manifest require this method be called (`isConnected === true`).
228
- */
229
- connect(cache: CloudCache): void;
230
- /**
231
- * Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container. Leaves the container attached to the
232
- * CloudCache so it is available for future sessions.
233
- */
234
- disconnect(): void;
235
- /**
236
- * Permanently Detach and Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container.
237
- */
238
- detach(): void;
239
- /**
240
- * Poll cloud storage for changes from other processes. *No changes* made by other processes are visible to
241
- * this CloudContainer unless/until this method is called.
242
- * @note this is automatically called whenever the write lock is obtained to ensure all changes are against the latest version.
243
- */
244
- checkForChanges(): void;
245
- /**
246
- * Upload any changed blocks from all databases in this CloudContainer.
247
- * @note this is called automatically from `releaseWriteLock` before the write lock is released. It is only necessary to call this directly if you
248
- * wish to upload changes while the write lock is still held.
249
- * @see hasLocalChanges
250
- */
251
- uploadChanges(): Promise<void>;
252
- /**
253
- * Clean any unused deleted blocks from cloud storage. When a database is written, a subset of its blocks are replaced
254
- * by new versions, sometimes leaving the originals unused. In this case, they are not deleted immediately.
255
- * Instead, they are scheduled for deletion at some later time. Calling this method deletes all blocks in the cloud container
256
- * for which the scheduled deletion time has passed.
257
- * @param nSeconds Any block that was marked as unused before this number of seconds ago will be deleted. Specifying a non-zero
258
- * value gives a period of time for other clients to refresh their manifests and stop using the now-garbage blocks. Otherwise they may get
259
- * a 404 error. Default is 1 hour.
260
- */
261
- cleanDeletedBlocks(nSeconds?: number): Promise<void>;
262
- /**
263
- * Create a copy of an existing database within this CloudContainer with a new name.
264
- * @note CloudSqlite uses copy-on-write semantics for this operation. That is, this method merely makes a
265
- * new entry in the manifest with the new name that *shares* all of its blocks with the original database.
266
- * If either database subsequently changes, the only modified blocks are not shared.
267
- */
268
- copyDatabase(dbName: string, toAlias: string): Promise<void>;
269
- /** Remove a database from this CloudContainer.
270
- * @see cleanDeletedBlocks
271
- */
272
- deleteDatabase(dbName: string): Promise<void>;
273
- /** Get the list of database names in this CloudContainer.
274
- * @param globArg if present, filter the results with SQLite [GLOB](https://www.sqlite.org/lang_expr.html#glob) operator.
275
- */
276
- queryDatabases(globArg?: string): string[];
277
- /**
278
- * Get the status of a specific database in this CloudContainer.
279
- * @param dbName the name of the database of interest
280
- */
281
- queryDatabase(dbName: string): CloudSqlite.CachedDbProps | undefined;
282
- /**
283
- * Get the SHA1 hash of the content of a database.
284
- * @param dbName the name of the database of interest
285
- * @note the hash will be empty if the database does not exist
286
- */
287
- queryDatabaseHash(dbName: string): string;
288
- }
289
- /** @internal */
290
- interface CloudPrefetch {
291
- readonly cloudContainer: CloudContainer;
292
- readonly dbName: string;
293
- /** Cancel a currently pending prefetch. The promise will be resolved immediately after this call. */
294
- cancel(): void;
295
- /**
296
- * Promise that is resolved when the prefetch completes or is cancelled. Await this promise to ensure that the
297
- * database has been fully downloaded before going offline, for example.
298
- * @returns a Promise that resolves to `true` if the prefetch completed and the entire database is local, or `false` if it was aborted or failed.
299
- * @note the promise is *not* rejected on `cancel`. Some progress may (or may not) have been made by the request.
300
- * @note To monitor the progress being made during prefetch, call `CloudContainer.queryDatabase` periodically.
301
- */
302
- promise: Promise<boolean>;
303
- }
304
- /** @internal */
305
- function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps): Promise<void>;
306
- /** Upload a database into a CloudContainer
307
- * @param container the CloudContainer holding the database. Must be connected.
308
- * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
309
- * @note this function requires that the write lock be held on the container
310
- */
311
- function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
312
- /** Download a database from a CloudContainer
313
- * @param container the CloudContainer holding the database. Must be connected.
314
- * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
315
- * @returns a Promise that is resolved when the download completes.
316
- * @note the download is "restartable." If the transfer is aborted and then re-requested, it will continue from where
317
- * it left off rather than re-downloading the entire file.
318
- */
319
- function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
320
- /** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.
321
- * @param lockedBy The identifier supplied by the application/user that currently holds the lock.
322
- * @param expires a stringified Date (in local time) indicating when the lock will expire.
323
- * @return "stop" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.
324
- */
325
- type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | "stop">;
326
- /**
327
- * Attempt to acquire the write lock for a container, with retries.
328
- * If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns "stop", throw. Otherwise try again.
329
- * @note if write lock is already held, this function does nothing.
330
- * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us
331
- * @param container the CloudContainer for which the lock is to be acquired
332
- * @param busyHandler if present, function called when the write lock is currently held by another user.
333
- */
334
- function acquireWriteLock(user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler): Promise<void>;
335
- /**
336
- * Perform an asynchronous write operation on a CloudContainer with the write lock held.
337
- * 1. if write lock is already held, call operation and return.
338
- * 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
339
- * 3. perform the operation
340
- * 3.a if the operation throws, abandon all changes and re-throw
341
- * 4. release the write lock.
342
- * 5. return value from operation
343
- * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us
344
- * @param container the CloudContainer for which the lock is to be acquired
345
- * @param operation an asynchronous operation performed with the write lock held.
346
- * @param busyHandler if present, function called when the write lock is currently held by another user.
347
- * @returns a Promise with the result of `operation`
348
- */
349
- function withWriteLock<T>(user: string, container: CloudContainer, operation: () => T, busyHandler?: WriteLockBusyHandler): Promise<T>;
350
- }
1
+ /** @packageDocumentation
2
+ * @module SQLiteDb
3
+ */
4
+ import { GuidString } from "@itwin/core-bentley";
5
+ import { LocalDirName, LocalFileName } from "@itwin/core-common";
6
+ /**
7
+ * Types for using SQLite files stored in cloud containers.
8
+ * @beta
9
+ */
10
+ export declare namespace CloudSqlite {
11
+ function createCloudContainer(args: ContainerAccessProps): CloudContainer;
12
+ /** Begin prefetching all blocks for a database in a CloudContainer in the background. */
13
+ function startCloudPrefetch(container: CloudContainer, dbName: string, args?: PrefetchProps): CloudPrefetch;
14
+ /** Properties that specify how to access the account for a cloud blob-store container. */
15
+ interface AccountAccessProps {
16
+ /** blob storage module: e.g. "azure", "google", "aws". May also include URI style parameters. */
17
+ storageType: string;
18
+ /** blob store account name, or a URI for custom domains. */
19
+ accessName: string;
20
+ }
21
+ /** Properties of a CloudContainer. */
22
+ interface ContainerProps {
23
+ /** the name of the container. */
24
+ containerId: string;
25
+ /** an alias for the container. Defaults to `containerId` */
26
+ alias?: string;
27
+ /** SAS token that grants access to the container. */
28
+ accessToken: string;
29
+ /** if true, container is attached with write permissions, and accessToken must provide write access to the cloud container. */
30
+ writeable?: boolean;
31
+ /** if true, container is attached in "secure" mode (blocks are encrypted). Only supported in daemon mode. */
32
+ secure?: boolean;
33
+ }
34
+ /** Returned from `CloudContainer.queryDatabase` describing one database in the container */
35
+ interface CachedDbProps {
36
+ /** The total of (4Mb) blocks in the database. */
37
+ readonly totalBlocks: number;
38
+ /** the number of blocks of the database that have been downloaded into the CloudCache */
39
+ readonly localBlocks: number;
40
+ /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */
41
+ readonly dirtyBlocks: number;
42
+ /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */
43
+ readonly transactions: boolean;
44
+ /** the state of this database. Indicates whether the database is new or deleted since last upload */
45
+ readonly state: "" | "copied" | "deleted";
46
+ }
47
+ /** Properties for accessing a CloudContainer */
48
+ type ContainerAccessProps = AccountAccessProps & ContainerProps & {
49
+ /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */
50
+ durationSeconds?: number;
51
+ };
52
+ /** The name of a CloudSqlite database within a CloudContainer. */
53
+ interface DbNameProp {
54
+ /** the name of the database within the CloudContainer.
55
+ * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/
56
+ dbName: string;
57
+ }
58
+ /** Properties for accessing a database within a CloudContainer */
59
+ interface DbProps extends DbNameProp {
60
+ /** the name of the local file to access the database. */
61
+ localFileName: LocalFileName;
62
+ }
63
+ type TransferDirection = "upload" | "download";
64
+ interface TransferProgress {
65
+ /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */
66
+ onProgress?: (loaded: number, total: number) => number;
67
+ }
68
+ interface CloudHttpProps {
69
+ /** The number of simultaneous HTTP requests. Default is 6. */
70
+ nRequests?: number;
71
+ }
72
+ interface PrefetchProps extends CloudHttpProps {
73
+ /** timeout between requests, in milliseconds. Default is 100. */
74
+ timeout?: number;
75
+ /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */
76
+ minRequests?: number;
77
+ }
78
+ type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;
79
+ /** Properties for creating a CloudCache. */
80
+ interface CacheProps extends CloudHttpProps {
81
+ /** full path of directory for cache to store its files. Must be on a (preferably fast) local drive, and must be empty when the cache is first created. */
82
+ rootDir: string;
83
+ /** name of this cache. It is possible to have more than one CloudCache in the same session, but each must have a unique name. */
84
+ name: string;
85
+ /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */
86
+ cacheSize?: string;
87
+ /** turn on diagnostics for `curl` (outputs to stderr) */
88
+ curlDiagnostics?: boolean;
89
+ }
90
+ /** Parameters used to obtain the write lock on a cloud container
91
+ * @internal
92
+ */
93
+ interface ObtainLockParams {
94
+ /** The name of the user attempting to acquire the write lock. This name will be shown to other users while the lock is held. */
95
+ user?: string;
96
+ /** number of times to retry in the event the lock currently held by someone else.
97
+ * After this number of attempts, `onFailure` is called. Default is 20.
98
+ */
99
+ nRetries: number;
100
+ /** Delay between retries, in milliseconds. Default is 100. */
101
+ retryDelayMs: number;
102
+ /** function called if lock cannot be obtained after all retries. It is called with the name of the user currently holding the lock and
103
+ * generally is expected that the user will be consulted whether to wait further.
104
+ * If this function returns "stop", an exception will be thrown. Otherwise the retry cycle is restarted.
105
+ */
106
+ onFailure?: WriteLockBusyHandler;
107
+ }
108
+ /** @internal */
109
+ interface LockAndOpenArgs {
110
+ /** the name to be displayed in the event of lock collisions */
111
+ user: string;
112
+ /** the name of the database within the container */
113
+ dbName: string;
114
+ /** the CloudContainer on which the operation will be performed */
115
+ container: CloudContainer;
116
+ /** if present, function called when the write lock is currently held by another user. */
117
+ busyHandler?: WriteLockBusyHandler;
118
+ }
119
+ /** Logging categories for `CloudCache.setLogMask` */
120
+ enum LoggingMask {
121
+ /** log all HTTP requests and responses */
122
+ HTTP = 1,
123
+ /** log as blocks become dirty and must be uploaded */
124
+ DirtyBlocks = 2,
125
+ /** log as blocks are added to the delete list */
126
+ AddToDelete = 4,
127
+ /** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */
128
+ LifecycleEvents = 8,
129
+ /** Turn on all logging categories */
130
+ All = 255,
131
+ /** Disable logging */
132
+ None = 0
133
+ }
134
+ /**
135
+ * A local cache for storing data downloaded from many CloudSqlite databases. This object refers to a directory on the local filesystem
136
+ * and is used to **connect** CloudContainers so they may be accessed. It maintains the state of the local copy of
137
+ * the downloaded data from SQLiteDbs in CloudContainers across sessions.
138
+ *
139
+ * Notes:
140
+ * - CloudCaches have a name, used internally by CloudSqlite, that must be unique. CloudCaches are created and maintained via [[CloudCaches.getCache]].
141
+ * - All CloudContainers connected to a given CloudCache must have the same block size, as determined by the first CloudContainer connected.
142
+ * - they have a maximum size that limits the amount of disk space they can consume. When the maximum size of a CloudCache is reached,
143
+ * the least recently used blocks are removed to make room for new blocks.
144
+ * - CloudCaches may only be used by a single process at a time. An exception is thrown if you attempt to access a CloudCache from a
145
+ * second process if it is already in use by another process. Note: for a readonly CloudCache, a "daemon" process can be used to
146
+ * share a CloudCache across processes. See its documentation for details.
147
+ * - Generally, it is expected that there only be a few CloudCaches and they be shared by all applications. Each CloudCache can consume
148
+ * its maximum disk space, so controlling system-wide disk usage is complicated. The only reason to make a new CloudCache is either
149
+ * for containers with a different block size, or to purposely control local disk space usage for a specific set of containers.
150
+ * - The contents of the cache directory are entirely controlled by CloudSqlite and should be empty when the cache is
151
+ * first created and never modified directly thereafter.
152
+ */
153
+ interface CloudCache {
154
+ /** `true` if this CloudCache is connected to a daemon process */
155
+ get isDaemon(): boolean;
156
+ /** The name for this CloudCache. */
157
+ get name(): string;
158
+ /** The root directory of this CloudCache on a local drive. */
159
+ get rootDir(): LocalDirName;
160
+ /** A guid for this CloudCache. It is assigned when the CloudCache is first created and used for acquiring write locks. */
161
+ get guid(): GuidString;
162
+ /** Configure logging for this CloudCache.
163
+ * @param mask A bitmask of `LoggingMask` values
164
+ * @note this method does nothing if [[isDaemon]] is true. Daemon logging is configured when the daemon is started.
165
+ * @note HTTP logging can be happen on multiple threads and may be buffered. To see buffered log messages, periodically call
166
+ * `[[IModelHost.flushLog]]
167
+ */
168
+ setLogMask(mask: number): void;
169
+ /**
170
+ * destroy this CloudCache to end this session. All currently connected CloudContainers are disconnected first.
171
+ * @note this does *not* delete the local directory. Its contents are maintained so it can be used in future sessions.
172
+ * @note this function is automatically called on [[IModelHost.shutdown]], so it is only called directly for tests.
173
+ * @internal
174
+ */
175
+ destroy(): void;
176
+ }
177
+ /**
178
+ * A CloudSqlite container that may be connected to a CloudCache. A CloudContainer maps a container in a cloud blob-storage
179
+ * account to a local cache, so that the contents of a database in the container may be accessed as if it were a local file.
180
+ *
181
+ * Notes:
182
+ * - all methods and accessors of this interface (other than `initializeContainer`) require that the `connect` method be successfully called first.
183
+ * Otherwise they will throw an exception or return meaningless values.
184
+ * - before a SQLiteDb in a container may be opened for write access, the container's write lock must be held (see [[acquireWriteLock]].)
185
+ * - a single CloudContainer may hold more than one SQLiteDb, but often they are 1:1.
186
+ * - the write lock is per-Container, not per-SQLiteDb (which is the reason they are often 1:1)
187
+ * - the accessToken (a SAS key) member provides time limited, restricted, access to the container. It must be refreshed before it expires.
188
+ * - when a CloudContainer is created, it may either be readonly or writeable. If a container is never meant to be used for writes,
189
+ * it is slightly more efficient to indicate that by passing `writeable: false`
190
+ */
191
+ interface CloudContainer {
192
+ onConnect?: (container: CloudContainer, cache: CloudCache) => void;
193
+ onConnected?: (container: CloudContainer) => void;
194
+ onDisconnect?: (container: CloudContainer, detach: boolean) => void;
195
+ onDisconnected?: (container: CloudContainer, detach: boolean) => void;
196
+ readonly cache?: CloudCache;
197
+ /** The ContainerId within the storage account. */
198
+ get containerId(): string;
199
+ /** The *alias* to identify this CloudContainer in a CloudCache. Usually just the ContainerId. */
200
+ get alias(): string;
201
+ /** true if this CloudContainer is currently connected to a CloudCache via the `connect` method. */
202
+ get isConnected(): boolean;
203
+ /** true if this CloudContainer was created with the `writeable` flag (and its `accessToken` supplies write access). */
204
+ get isWriteable(): boolean;
205
+ /** true if this CloudContainer currently holds the write lock for its container in the cloud. */
206
+ get hasWriteLock(): boolean;
207
+ /** true if this CloudContainer has local changes that have not be uploaded to its container in the cloud. */
208
+ get hasLocalChanges(): boolean;
209
+ /** The current accessToken providing access to the cloud container */
210
+ get accessToken(): string;
211
+ set accessToken(val: string);
212
+ /** Get the number of garbage blocks in this container that can be purged. */
213
+ get garbageBlocks(): number;
214
+ /** The block size for this CloudContainer. */
215
+ get blockSize(): number;
216
+ /**
217
+ * initialize a cloud blob-store container to be used as a new CloudContainer. This creates the container's manifest of its contents, and should be
218
+ * performed on an empty container. If an existing manifest is present, it is destroyed and a new one is created (essentially emptying the container.)
219
+ */
220
+ initializeContainer(opts?: {
221
+ checksumBlockNames?: boolean;
222
+ blockSize?: number;
223
+ }): void;
224
+ /**
225
+ * Connect this CloudContainer to a CloudCache for accessing and/or modifying its contents.
226
+ * @note A CloudCache is a local directory holding copies of information from the cloud. It is persistent across sessions,
227
+ * but this method must be called each session to (re)establish the connection to the CloudCache. If the CloudCache was previously populated,
228
+ * this method may be called and will succeed *even when offline* or without a valid `accessToken`.
229
+ */
230
+ connect(cache: CloudCache): void;
231
+ /**
232
+ * Attempt to acquire the write lock for this CloudContainer. For this to succeed:
233
+ * 1. it must be connected to a `CloudCache`
234
+ * 2. this CloudContainer must have been constructed with `writeable: true`
235
+ * 3. the `accessToken` must authorize write access
236
+ * 4. no other process may be holding an unexpired write lock
237
+ * @throws if any of the above conditions fail
238
+ * @note Write locks *expire* after the duration specified in the `durationSeconds` property of the constructor argument, in case a process
239
+ * crashes or otherwise fails to release the lock. Calling `acquireWriteLock` with the lock already held resets the lock duration from the current time,
240
+ * so long running processes should call this method periodically to ensure their lock doesn't expire (they should also make sure their accessToken is refreshed
241
+ * before it expires.)
242
+ * @note on success, the container is synchronized with its contents in the cloud before the promise resolves.
243
+ * @param user An identifier of the process/user locking the CloudContainer. In the event of a write lock
244
+ * collision, this string will be included in the exception string of the *other* process attempting to obtain a write lock so that users may identify who currently holds
245
+ * the lock.
246
+ */
247
+ acquireWriteLock(user: string): void;
248
+ /**
249
+ * Release the write lock if it is currently held.
250
+ *
251
+ * Notes:
252
+ * - if there are local changes that have not been uploaded, they are automatically uploaded before the write lock is released.
253
+ * - if the write lock is not held, this method does nothing.
254
+ */
255
+ releaseWriteLock(): void;
256
+ /**
257
+ * Destroy any currently valid write lock from this or any other process. This is obviously very dangerous and defeats the purpose of write locking.
258
+ * This method exists only for administrator tools to clear a failed process without waiting for the expiration period. It can also be useful for tests.
259
+ * For this to succeed, all of the conditions of `acquireWriteLock` must be true other than #4.
260
+ */
261
+ clearWriteLock(): void;
262
+ /**
263
+ * Abandon any local changes in this container. If the write lock is currently held, it is released.
264
+ * This function fails with BE_SQLITE_BUSY if there are any open read or write transactions on *any* database in the container.
265
+ */
266
+ abandonChanges(): void;
267
+ /**
268
+ * Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container. Leaves the container's contents in the
269
+ * CloudCache so it is available for future sessions.
270
+ * @note This function does nothing (and does not throw) if the CloudContainer is not connected to a CloudCache.
271
+ */
272
+ disconnect(args?: {
273
+ /** if true removes the container from the CloudCache, otherwise Leaves the container in the CloudCache so it is available for future sessions. */
274
+ detach?: boolean;
275
+ }): void;
276
+ /**
277
+ * Poll cloud storage for changes from other processes.
278
+ *
279
+ * Notes:
280
+ * - no changes made by other processes are visible to this CloudContainer unless/until this method is called.
281
+ * - note this is automatically called whenever the write lock is obtained to ensure all changes are against the latest version.
282
+ */
283
+ checkForChanges(): void;
284
+ /**
285
+ * Upload any changed blocks from the databases in this CloudContainer.
286
+ * @note this is called automatically from `releaseWriteLock` before the write lock is released. It is only necessary to call this directly if you
287
+ * wish to upload changes while the write lock is still held.
288
+ * @see hasLocalChanges
289
+ */
290
+ uploadChanges(): Promise<void>;
291
+ /**
292
+ * Clean any unused deleted blocks from cloud storage. When a database is written, a subset of its blocks are replaced
293
+ * by new versions, sometimes leaving the originals unused. In this case, they are not deleted immediately.
294
+ * Instead, they are scheduled for deletion at some later time. Calling this method deletes all blocks in the cloud container
295
+ * for which the scheduled deletion time has passed.
296
+ * @param nSeconds Any block that was marked as unused before this number of seconds ago will be deleted. Specifying a non-zero
297
+ * value gives a period of time for other clients to refresh their manifests and stop using the now-garbage blocks. Otherwise they may get
298
+ * a 404 error. Default is 1 hour.
299
+ */
300
+ cleanDeletedBlocks(nSeconds?: number): Promise<void>;
301
+ /**
302
+ * Create a copy of an existing database within this CloudContainer with a new name.
303
+ * @note CloudSqlite uses copy-on-write semantics for this operation. That is, this method merely makes a
304
+ * new entry in the manifest with the new name that *shares* all of its blocks with the original database.
305
+ * If either database subsequently changes, the only modified blocks are not shared.
306
+ */
307
+ copyDatabase(dbName: string, toAlias: string): Promise<void>;
308
+ /** Remove a database from this CloudContainer.
309
+ * @see cleanDeletedBlocks
310
+ */
311
+ deleteDatabase(dbName: string): Promise<void>;
312
+ /** Get the list of database names in this CloudContainer.
313
+ * @param globArg if present, filter the results with SQLite [GLOB](https://www.sqlite.org/lang_expr.html#glob) operator.
314
+ */
315
+ queryDatabases(globArg?: string): string[];
316
+ /**
317
+ * Get the status of a specific database in this CloudContainer.
318
+ * @param dbName the name of the database of interest
319
+ */
320
+ queryDatabase(dbName: string): CloudSqlite.CachedDbProps | undefined;
321
+ /**
322
+ * Get the SHA1 hash of the content of a database.
323
+ * @param dbName the name of the database of interest
324
+ * @note the hash will be empty if the database does not exist
325
+ */
326
+ queryDatabaseHash(dbName: string): string;
327
+ }
328
+ /**
329
+ * Object returned by [[CloudSqlite.startCloudPrefetch]].
330
+ * It holds a promise that is fulfilled when a Prefetch is completed. May also be used to cancel an in-progress prefetch.
331
+ */
332
+ interface CloudPrefetch {
333
+ readonly cloudContainer: CloudContainer;
334
+ readonly dbName: string;
335
+ /** Cancel a currently pending prefetch. The promise will be resolved immediately after this call. */
336
+ cancel(): void;
337
+ /**
338
+ * Promise that is resolved when the prefetch completes or is cancelled. Await this promise to ensure that the
339
+ * database has been fully downloaded before going offline, for example.
340
+ *
341
+ * Notes:
342
+ * - resolves to `true` if the prefetch completed and the entire database is local, or `false` if it was aborted or failed.
343
+ * - it is *not* rejected on `cancel`. Some progress may (or may not) have been made by the request.
344
+ * - To monitor the progress being made during prefetch, call `CloudContainer.queryDatabase` periodically.
345
+ */
346
+ promise: Promise<boolean>;
347
+ }
348
+ /** @internal */
349
+ function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps): Promise<void>;
350
+ /** Upload a local SQLite database file into a CloudContainer.
351
+ * @param container the CloudContainer holding the database. Must be connected.
352
+ * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
353
+ * @note this function requires that the write lock be held on the container
354
+ */
355
+ function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
356
+ /** Download a database from a CloudContainer.
357
+ * @param container the CloudContainer holding the database. Must be connected.
358
+ * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
359
+ * @returns a Promise that is resolved when the download completes.
360
+ * @note the download is "restartable." If the transfer is aborted and then re-requested, it will continue from where
361
+ * it left off rather than re-downloading the entire file.
362
+ */
363
+ function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
364
+ /** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.
365
+ * @param lockedBy The identifier supplied by the application/user that currently holds the lock.
366
+ * @param expires a stringified Date (in local time) indicating when the lock will expire.
367
+ * @return "stop" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.
368
+ */
369
+ type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | "stop">;
370
+ /**
371
+ * Attempt to acquire the write lock for a container, with retries.
372
+ * If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns "stop", throw. Otherwise try again.
373
+ * @note if write lock is already held, this function does nothing.
374
+ * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us
375
+ * @param container the CloudContainer for which the lock is to be acquired
376
+ * @param busyHandler if present, function called when the write lock is currently held by another user.
377
+ * @throws if [[container]] is not connected to a CloudCache.
378
+ */
379
+ function acquireWriteLock(user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler): Promise<void>;
380
+ /**
381
+ * Perform an asynchronous write operation on a CloudContainer with the write lock held.
382
+ * 1. if write lock is already held, call operation and return.
383
+ * 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
384
+ * 3. perform the operation
385
+ * 3.a if the operation throws, abandon all changes and re-throw
386
+ * 4. release the write lock.
387
+ * 5. return value from operation
388
+ * @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us
389
+ * @param container the CloudContainer for which the lock is to be acquired
390
+ * @param operation an asynchronous operation performed with the write lock held.
391
+ * @param busyHandler if present, function called when the write lock is currently held by another user.
392
+ * @returns a Promise with the result of `operation`
393
+ */
394
+ function withWriteLock<T>(user: string, container: CloudContainer, operation: () => T, busyHandler?: WriteLockBusyHandler): Promise<T>;
395
+ /** Arguments to create or find a CloudCache */
396
+ interface CreateCloudCacheArg {
397
+ /** The name of the CloudCache. CloudCache names must be unique. */
398
+ cacheName: string;
399
+ /** A string that specifies the maximum size of the CloudCache. It should be a number followed by "K",
400
+ * "M" "G", or "T". Default is "10G". */
401
+ cacheSize?: string;
402
+ /** A local directory in temporary storage for the CloudCache. If not supplied, it is a subdirectory called `cacheName`
403
+ * in the `CloudCaches` temporary directory.
404
+ * If the directory does not exist, it is created. */
405
+ cacheDir?: string;
406
+ }
407
+ /** The collection of currently extant CloudCaches, by name. */
408
+ class CloudCaches {
409
+ private static readonly cloudCaches;
410
+ /** create a new CloudCache */
411
+ private static makeCache;
412
+ /** find a CloudCache by name if it exists */
413
+ static findCache(cacheName: string): CloudCache | undefined;
414
+ /** @internal */
415
+ static dropCache(cacheName: string): CloudCache | undefined;
416
+ /** called by IModelHost after shutdown.
417
+ * @internal
418
+ */
419
+ static destroy(): void;
420
+ /** Get an CloudCache by name. If the CloudCache doesn't yet exist, it is created. */
421
+ static getCache(args: CreateCloudCacheArg): CloudCache;
422
+ }
423
+ }
351
424
  //# sourceMappingURL=CloudSqlite.d.ts.map