@itwin/core-backend 3.6.0 → 3.7.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/AliCloudStorageService.d.ts +23 -23
- package/lib/cjs/AliCloudStorageService.js +71 -71
- package/lib/cjs/AliCloudStorageService.js.map +1 -1
- package/lib/cjs/BackendHubAccess.d.ts +224 -224
- package/lib/cjs/BackendHubAccess.js +41 -41
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BackendLoggerCategory.d.ts +91 -91
- package/lib/cjs/BackendLoggerCategory.js +99 -99
- package/lib/cjs/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/BisCoreSchema.d.ts +21 -21
- package/lib/cjs/BisCoreSchema.js +60 -60
- package/lib/cjs/BisCoreSchema.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts +170 -170
- package/lib/cjs/BriefcaseManager.js +414 -414
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/Category.d.ts +153 -153
- package/lib/cjs/Category.js +243 -243
- package/lib/cjs/Category.js.map +1 -1
- package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
- package/lib/cjs/ChangeSummaryManager.js +447 -447
- package/lib/cjs/ChangeSummaryManager.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +99 -99
- package/lib/cjs/ChangedElementsDb.js +165 -165
- package/lib/cjs/ChangedElementsDb.js.map +1 -1
- package/lib/cjs/ChangedElementsManager.d.ts +39 -39
- package/lib/cjs/ChangedElementsManager.js +88 -88
- package/lib/cjs/ChangedElementsManager.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts +121 -121
- package/lib/cjs/CheckpointManager.js +349 -349
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts +79 -79
- package/lib/cjs/ClassRegistry.js +250 -250
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +350 -350
- package/lib/cjs/CloudSqlite.js +153 -153
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/CloudStorageBackend.d.ts +58 -58
- package/lib/cjs/CloudStorageBackend.js +173 -173
- package/lib/cjs/CloudStorageBackend.js.map +1 -1
- package/lib/cjs/CodeService.d.ts +396 -396
- package/lib/cjs/CodeService.js +63 -63
- package/lib/cjs/CodeService.js.map +1 -1
- package/lib/cjs/CodeSpecs.d.ts +55 -55
- package/lib/cjs/CodeSpecs.js +124 -124
- package/lib/cjs/CodeSpecs.js.map +1 -1
- package/lib/cjs/ConcurrentQuery.d.ts +13 -13
- package/lib/cjs/ConcurrentQuery.js +36 -36
- package/lib/cjs/ConcurrentQuery.js.map +1 -1
- package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
- package/lib/cjs/CustomViewState3dCreator.js +81 -81
- package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
- package/lib/cjs/DevTools.d.ts +71 -71
- package/lib/cjs/DevTools.js +154 -154
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +106 -106
- package/lib/cjs/DisplayStyle.js +256 -256
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +191 -191
- package/lib/cjs/ECDb.js +350 -350
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
- package/lib/cjs/ECSchemaXmlContext.js +41 -41
- package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
- package/lib/cjs/ECSqlStatement.d.ts +473 -473
- package/lib/cjs/ECSqlStatement.js +791 -791
- package/lib/cjs/ECSqlStatement.js.map +1 -1
- package/lib/cjs/Element.d.ts +1109 -1109
- package/lib/cjs/Element.js +1427 -1427
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +179 -179
- package/lib/cjs/ElementAspect.js +211 -211
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/ElementGraphics.d.ts +9 -9
- package/lib/cjs/ElementGraphics.js +41 -41
- package/lib/cjs/ElementGraphics.js.map +1 -1
- package/lib/cjs/ElementTreeWalker.d.ts +162 -162
- package/lib/cjs/ElementTreeWalker.js +409 -409
- package/lib/cjs/ElementTreeWalker.js.map +1 -1
- package/lib/cjs/Entity.d.ts +106 -106
- package/lib/cjs/Entity.js +134 -134
- package/lib/cjs/Entity.js.map +1 -1
- package/lib/cjs/EntityReferences.d.ts +49 -49
- package/lib/cjs/EntityReferences.js +95 -95
- package/lib/cjs/EntityReferences.js.map +1 -1
- package/lib/cjs/ExportGraphics.d.ts +317 -317
- package/lib/cjs/ExportGraphics.js +208 -208
- package/lib/cjs/ExportGraphics.js.map +1 -1
- package/lib/cjs/ExternalSource.d.ts +96 -96
- package/lib/cjs/ExternalSource.js +131 -131
- package/lib/cjs/ExternalSource.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts +19 -19
- package/lib/cjs/GeoCoordConfig.js +85 -85
- package/lib/cjs/GeoCoordConfig.js.map +1 -1
- package/lib/cjs/GeometrySummary.d.ts +4 -4
- package/lib/cjs/GeometrySummary.js +380 -380
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/HubMock.d.ts +94 -94
- package/lib/cjs/HubMock.js +222 -222
- package/lib/cjs/HubMock.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +8 -8
- package/lib/cjs/IModelCloneContext.js +15 -15
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +1210 -1210
- package/lib/cjs/IModelDb.js +2386 -2386
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
- package/lib/cjs/IModelElementCloneContext.js +159 -159
- package/lib/cjs/IModelElementCloneContext.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +369 -369
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +496 -496
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IModelJsFs.d.ts +62 -62
- package/lib/cjs/IModelJsFs.js +140 -140
- package/lib/cjs/IModelJsFs.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts +104 -104
- package/lib/cjs/IpcHost.js +278 -278
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LineStyle.d.ts +311 -311
- package/lib/cjs/LineStyle.js +295 -295
- package/lib/cjs/LineStyle.js.map +1 -1
- package/lib/cjs/LocalHub.d.ts +162 -162
- package/lib/cjs/LocalHub.js +585 -585
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
- package/lib/cjs/LocalhostIpcHost.js +81 -81
- package/lib/cjs/LocalhostIpcHost.js.map +1 -1
- package/lib/cjs/Material.d.ts +131 -131
- package/lib/cjs/Material.js +181 -181
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +392 -392
- package/lib/cjs/Model.js +485 -485
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/NativeAppStorage.d.ts +51 -51
- package/lib/cjs/NativeAppStorage.js +202 -202
- package/lib/cjs/NativeAppStorage.js.map +1 -1
- package/lib/cjs/NativeHost.d.ts +52 -52
- package/lib/cjs/NativeHost.js +163 -163
- package/lib/cjs/NativeHost.js.map +1 -1
- package/lib/cjs/NavigationRelationship.d.ts +156 -156
- package/lib/cjs/NavigationRelationship.js +225 -225
- package/lib/cjs/NavigationRelationship.js.map +1 -1
- package/lib/cjs/PromiseMemoizer.d.ts +51 -51
- package/lib/cjs/PromiseMemoizer.js +101 -101
- package/lib/cjs/PromiseMemoizer.js.map +1 -1
- package/lib/cjs/PropertyStore.d.ts +132 -132
- package/lib/cjs/PropertyStore.js +11 -11
- package/lib/cjs/PropertyStore.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +416 -416
- package/lib/cjs/Relationship.js +494 -494
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/RpcBackend.d.ts +5 -5
- package/lib/cjs/RpcBackend.js +32 -32
- package/lib/cjs/RpcBackend.js.map +1 -1
- package/lib/cjs/SQLiteDb.d.ts +219 -219
- package/lib/cjs/SQLiteDb.js +214 -214
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/Schema.d.ts +55 -55
- package/lib/cjs/Schema.js +83 -83
- package/lib/cjs/Schema.js.map +1 -1
- package/lib/cjs/ServerBasedLocks.d.ts +57 -57
- package/lib/cjs/ServerBasedLocks.js +168 -168
- package/lib/cjs/ServerBasedLocks.js.map +1 -1
- package/lib/cjs/SqliteStatement.d.ts +360 -360
- package/lib/cjs/SqliteStatement.js +586 -586
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/Texture.d.ts +58 -58
- package/lib/cjs/Texture.js +82 -82
- package/lib/cjs/Texture.js.map +1 -1
- package/lib/cjs/TileStorage.d.ts +18 -18
- package/lib/cjs/TileStorage.js +90 -90
- package/lib/cjs/TileStorage.js.map +1 -1
- package/lib/cjs/TxnManager.d.ts +202 -202
- package/lib/cjs/TxnManager.js +356 -356
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +439 -439
- package/lib/cjs/ViewDefinition.js +646 -646
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/ViewStateHydrator.d.ts +13 -13
- package/lib/cjs/ViewStateHydrator.js +103 -103
- package/lib/cjs/ViewStateHydrator.js.map +1 -1
- package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
- package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
- package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
- package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
- package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
- package/lib/cjs/core-backend.d.ts +184 -184
- package/lib/cjs/core-backend.js +204 -204
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
- package/lib/cjs/domains/FunctionalElements.js +145 -145
- package/lib/cjs/domains/FunctionalElements.js.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
- package/lib/cjs/domains/FunctionalSchema.js +40 -40
- package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
- package/lib/cjs/domains/GenericElements.d.ts +177 -177
- package/lib/cjs/domains/GenericElements.js +263 -263
- package/lib/cjs/domains/GenericElements.js.map +1 -1
- package/lib/cjs/domains/GenericSchema.d.ts +10 -10
- package/lib/cjs/domains/GenericSchema.js +28 -28
- package/lib/cjs/domains/GenericSchema.js.map +1 -1
- package/lib/cjs/rpc/multipart.d.ts +11 -11
- package/lib/cjs/rpc/multipart.js +71 -71
- package/lib/cjs/rpc/multipart.js.map +1 -1
- package/lib/cjs/rpc/tracing.d.ts +28 -28
- package/lib/cjs/rpc/tracing.js +74 -74
- package/lib/cjs/rpc/tracing.js.map +1 -1
- package/lib/cjs/rpc/web/logging.d.ts +9 -9
- package/lib/cjs/rpc/web/logging.js +43 -43
- package/lib/cjs/rpc/web/logging.js.map +1 -1
- package/lib/cjs/rpc/web/request.d.ts +6 -6
- package/lib/cjs/rpc/web/request.js +74 -74
- package/lib/cjs/rpc/web/request.js.map +1 -1
- package/lib/cjs/rpc/web/response.d.ts +6 -6
- package/lib/cjs/rpc/web/response.js +106 -106
- package/lib/cjs/rpc/web/response.js.map +1 -1
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +294 -294
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -22
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +205 -205
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -168
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
- package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
- package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
- package/lib/cjs/workspace/Settings.d.ts +186 -186
- package/lib/cjs/workspace/Settings.js +155 -155
- package/lib/cjs/workspace/Settings.js.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
- package/lib/cjs/workspace/SettingsSchemas.js +191 -191
- package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +414 -414
- package/lib/cjs/workspace/Workspace.js +543 -543
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +11 -11
package/lib/cjs/CloudSqlite.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
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 SQLiteDb
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.CloudSqlite = void 0;
|
|
11
|
-
const fs_1 = require("fs");
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
const imodeljs_native_1 = require("@bentley/imodeljs-native");
|
|
14
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
15
|
-
/** Types for using SQLite files stored in cloud containers.
|
|
16
|
-
* @beta
|
|
17
|
-
*/
|
|
18
|
-
var CloudSqlite;
|
|
19
|
-
(function (CloudSqlite) {
|
|
20
|
-
function createCloudContainer(args) {
|
|
21
|
-
return new imodeljs_native_1.NativeLibrary.nativeLib.CloudContainer(args);
|
|
22
|
-
}
|
|
23
|
-
CloudSqlite.createCloudContainer = createCloudContainer;
|
|
24
|
-
function createCloudCache(args) {
|
|
25
|
-
return new imodeljs_native_1.NativeLibrary.nativeLib.CloudCache(args);
|
|
26
|
-
}
|
|
27
|
-
CloudSqlite.createCloudCache = createCloudCache;
|
|
28
|
-
function startCloudPrefetch(container, dbName, args) {
|
|
29
|
-
return new imodeljs_native_1.NativeLibrary.nativeLib.CloudPrefetch(container, dbName, args);
|
|
30
|
-
}
|
|
31
|
-
CloudSqlite.startCloudPrefetch = startCloudPrefetch;
|
|
32
|
-
/** Logging categories for `CloudCache.setLogMask` */
|
|
33
|
-
let LoggingMask;
|
|
34
|
-
(function (LoggingMask) {
|
|
35
|
-
/** log all HTTP requests and responses */
|
|
36
|
-
LoggingMask[LoggingMask["HTTP"] = 1] = "HTTP";
|
|
37
|
-
/** log as blocks become dirty and must be uploaded */
|
|
38
|
-
LoggingMask[LoggingMask["DirtyBlocks"] = 2] = "DirtyBlocks";
|
|
39
|
-
/** log as blocks are added to the delete list */
|
|
40
|
-
LoggingMask[LoggingMask["AddToDelete"] = 4] = "AddToDelete";
|
|
41
|
-
/** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */
|
|
42
|
-
LoggingMask[LoggingMask["LifecycleEvents"] = 8] = "LifecycleEvents";
|
|
43
|
-
/** Turn on all logging categories */
|
|
44
|
-
LoggingMask[LoggingMask["All"] = 255] = "All";
|
|
45
|
-
/** Disable logging */
|
|
46
|
-
LoggingMask[LoggingMask["None"] = 0] = "None";
|
|
47
|
-
})(LoggingMask = CloudSqlite.LoggingMask || (CloudSqlite.LoggingMask = {}));
|
|
48
|
-
/** @internal */
|
|
49
|
-
async function transferDb(direction, container, props) {
|
|
50
|
-
if (direction === "download")
|
|
51
|
-
(0, fs_1.mkdirSync)((0, path_1.dirname)(props.localFileName), { recursive: true }); // make sure the directory exists before starting download
|
|
52
|
-
let timer;
|
|
53
|
-
try {
|
|
54
|
-
const transfer = new imodeljs_native_1.NativeLibrary.nativeLib.CloudDbTransfer(direction, container, props);
|
|
55
|
-
let total = 0;
|
|
56
|
-
const onProgress = props.onProgress;
|
|
57
|
-
if (onProgress) {
|
|
58
|
-
timer = setInterval(async () => {
|
|
59
|
-
const progress = transfer.getProgress();
|
|
60
|
-
total = progress.total;
|
|
61
|
-
if (onProgress(progress.loaded, progress.total))
|
|
62
|
-
transfer.cancelTransfer();
|
|
63
|
-
}, 250);
|
|
64
|
-
}
|
|
65
|
-
await transfer.promise;
|
|
66
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress(total, total); // make sure we call progress func one last time when download completes
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
if (err.message === "cancelled")
|
|
70
|
-
err.errorNumber = core_bentley_1.BriefcaseStatus.DownloadCancelled;
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
if (timer)
|
|
75
|
-
clearInterval(timer);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
CloudSqlite.transferDb = transferDb;
|
|
79
|
-
/** Upload a database into a CloudContainer
|
|
80
|
-
* @param container the CloudContainer holding the database. Must be connected.
|
|
81
|
-
* @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
|
|
82
|
-
* @note this function requires that the write lock be held on the container
|
|
83
|
-
*/
|
|
84
|
-
async function uploadDb(container, props) {
|
|
85
|
-
await transferDb("upload", container, props);
|
|
86
|
-
container.checkForChanges(); // re-read the manifest so the database is available locally.
|
|
87
|
-
}
|
|
88
|
-
CloudSqlite.uploadDb = uploadDb;
|
|
89
|
-
/** Download a database from a CloudContainer
|
|
90
|
-
* @param container the CloudContainer holding the database. Must be connected.
|
|
91
|
-
* @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
|
|
92
|
-
* @returns a Promise that is resolved when the download completes.
|
|
93
|
-
* @note the download is "restartable." If the transfer is aborted and then re-requested, it will continue from where
|
|
94
|
-
* it left off rather than re-downloading the entire file.
|
|
95
|
-
*/
|
|
96
|
-
async function downloadDb(container, props) {
|
|
97
|
-
await transferDb("download", container, props);
|
|
98
|
-
}
|
|
99
|
-
CloudSqlite.downloadDb = downloadDb;
|
|
100
|
-
/**
|
|
101
|
-
* Attempt to acquire the write lock for a container, with retries.
|
|
102
|
-
* If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns "stop", throw. Otherwise try again.
|
|
103
|
-
* @note if write lock is already held, this function does nothing.
|
|
104
|
-
* @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
|
|
105
|
-
* @param container the CloudContainer for which the lock is to be acquired
|
|
106
|
-
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
107
|
-
*/
|
|
108
|
-
async function acquireWriteLock(user, container, busyHandler) {
|
|
109
|
-
if (container.hasWriteLock)
|
|
110
|
-
return;
|
|
111
|
-
while (true) {
|
|
112
|
-
try {
|
|
113
|
-
return container.acquireWriteLock(user);
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
if (e.errorNumber === 5 && busyHandler && "stop" !== await busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY
|
|
117
|
-
continue; // busy handler wants to try again
|
|
118
|
-
throw e;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
CloudSqlite.acquireWriteLock = acquireWriteLock;
|
|
123
|
-
/**
|
|
124
|
-
* Perform an asynchronous write operation on a CloudContainer with the write lock held.
|
|
125
|
-
* 1. if write lock is already held, call operation and return.
|
|
126
|
-
* 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
|
|
127
|
-
* 3. perform the operation
|
|
128
|
-
* 3.a if the operation throws, abandon all changes and re-throw
|
|
129
|
-
* 4. release the write lock.
|
|
130
|
-
* 5. return value from operation
|
|
131
|
-
* @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
|
|
132
|
-
* @param container the CloudContainer for which the lock is to be acquired
|
|
133
|
-
* @param operation an asynchronous operation performed with the write lock held.
|
|
134
|
-
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
135
|
-
* @returns a Promise with the result of `operation`
|
|
136
|
-
*/
|
|
137
|
-
async function withWriteLock(user, container, operation, busyHandler) {
|
|
138
|
-
if (container.hasWriteLock)
|
|
139
|
-
return operation();
|
|
140
|
-
await acquireWriteLock(user, container, busyHandler);
|
|
141
|
-
try {
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
143
|
-
const val = await operation(); // wait for work to finish or fail
|
|
144
|
-
container.releaseWriteLock();
|
|
145
|
-
return val;
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
container.abandonChanges(); // if operation threw, abandon all changes
|
|
149
|
-
throw e;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
CloudSqlite.withWriteLock = withWriteLock;
|
|
153
|
-
})(CloudSqlite = exports.CloudSqlite || (exports.CloudSqlite = {}));
|
|
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 SQLiteDb
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CloudSqlite = void 0;
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const imodeljs_native_1 = require("@bentley/imodeljs-native");
|
|
14
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
15
|
+
/** Types for using SQLite files stored in cloud containers.
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
var CloudSqlite;
|
|
19
|
+
(function (CloudSqlite) {
|
|
20
|
+
function createCloudContainer(args) {
|
|
21
|
+
return new imodeljs_native_1.NativeLibrary.nativeLib.CloudContainer(args);
|
|
22
|
+
}
|
|
23
|
+
CloudSqlite.createCloudContainer = createCloudContainer;
|
|
24
|
+
function createCloudCache(args) {
|
|
25
|
+
return new imodeljs_native_1.NativeLibrary.nativeLib.CloudCache(args);
|
|
26
|
+
}
|
|
27
|
+
CloudSqlite.createCloudCache = createCloudCache;
|
|
28
|
+
function startCloudPrefetch(container, dbName, args) {
|
|
29
|
+
return new imodeljs_native_1.NativeLibrary.nativeLib.CloudPrefetch(container, dbName, args);
|
|
30
|
+
}
|
|
31
|
+
CloudSqlite.startCloudPrefetch = startCloudPrefetch;
|
|
32
|
+
/** Logging categories for `CloudCache.setLogMask` */
|
|
33
|
+
let LoggingMask;
|
|
34
|
+
(function (LoggingMask) {
|
|
35
|
+
/** log all HTTP requests and responses */
|
|
36
|
+
LoggingMask[LoggingMask["HTTP"] = 1] = "HTTP";
|
|
37
|
+
/** log as blocks become dirty and must be uploaded */
|
|
38
|
+
LoggingMask[LoggingMask["DirtyBlocks"] = 2] = "DirtyBlocks";
|
|
39
|
+
/** log as blocks are added to the delete list */
|
|
40
|
+
LoggingMask[LoggingMask["AddToDelete"] = 4] = "AddToDelete";
|
|
41
|
+
/** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */
|
|
42
|
+
LoggingMask[LoggingMask["LifecycleEvents"] = 8] = "LifecycleEvents";
|
|
43
|
+
/** Turn on all logging categories */
|
|
44
|
+
LoggingMask[LoggingMask["All"] = 255] = "All";
|
|
45
|
+
/** Disable logging */
|
|
46
|
+
LoggingMask[LoggingMask["None"] = 0] = "None";
|
|
47
|
+
})(LoggingMask = CloudSqlite.LoggingMask || (CloudSqlite.LoggingMask = {}));
|
|
48
|
+
/** @internal */
|
|
49
|
+
async function transferDb(direction, container, props) {
|
|
50
|
+
if (direction === "download")
|
|
51
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(props.localFileName), { recursive: true }); // make sure the directory exists before starting download
|
|
52
|
+
let timer;
|
|
53
|
+
try {
|
|
54
|
+
const transfer = new imodeljs_native_1.NativeLibrary.nativeLib.CloudDbTransfer(direction, container, props);
|
|
55
|
+
let total = 0;
|
|
56
|
+
const onProgress = props.onProgress;
|
|
57
|
+
if (onProgress) {
|
|
58
|
+
timer = setInterval(async () => {
|
|
59
|
+
const progress = transfer.getProgress();
|
|
60
|
+
total = progress.total;
|
|
61
|
+
if (onProgress(progress.loaded, progress.total))
|
|
62
|
+
transfer.cancelTransfer();
|
|
63
|
+
}, 250);
|
|
64
|
+
}
|
|
65
|
+
await transfer.promise;
|
|
66
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(total, total); // make sure we call progress func one last time when download completes
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (err.message === "cancelled")
|
|
70
|
+
err.errorNumber = core_bentley_1.BriefcaseStatus.DownloadCancelled;
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
if (timer)
|
|
75
|
+
clearInterval(timer);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
CloudSqlite.transferDb = transferDb;
|
|
79
|
+
/** Upload a database into a CloudContainer
|
|
80
|
+
* @param container the CloudContainer holding the database. Must be connected.
|
|
81
|
+
* @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
|
|
82
|
+
* @note this function requires that the write lock be held on the container
|
|
83
|
+
*/
|
|
84
|
+
async function uploadDb(container, props) {
|
|
85
|
+
await transferDb("upload", container, props);
|
|
86
|
+
container.checkForChanges(); // re-read the manifest so the database is available locally.
|
|
87
|
+
}
|
|
88
|
+
CloudSqlite.uploadDb = uploadDb;
|
|
89
|
+
/** Download a database from a CloudContainer
|
|
90
|
+
* @param container the CloudContainer holding the database. Must be connected.
|
|
91
|
+
* @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
|
|
92
|
+
* @returns a Promise that is resolved when the download completes.
|
|
93
|
+
* @note the download is "restartable." If the transfer is aborted and then re-requested, it will continue from where
|
|
94
|
+
* it left off rather than re-downloading the entire file.
|
|
95
|
+
*/
|
|
96
|
+
async function downloadDb(container, props) {
|
|
97
|
+
await transferDb("download", container, props);
|
|
98
|
+
}
|
|
99
|
+
CloudSqlite.downloadDb = downloadDb;
|
|
100
|
+
/**
|
|
101
|
+
* Attempt to acquire the write lock for a container, with retries.
|
|
102
|
+
* If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns "stop", throw. Otherwise try again.
|
|
103
|
+
* @note if write lock is already held, this function does nothing.
|
|
104
|
+
* @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
|
|
105
|
+
* @param container the CloudContainer for which the lock is to be acquired
|
|
106
|
+
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
107
|
+
*/
|
|
108
|
+
async function acquireWriteLock(user, container, busyHandler) {
|
|
109
|
+
if (container.hasWriteLock)
|
|
110
|
+
return;
|
|
111
|
+
while (true) {
|
|
112
|
+
try {
|
|
113
|
+
return container.acquireWriteLock(user);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (e.errorNumber === 5 && busyHandler && "stop" !== await busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY
|
|
117
|
+
continue; // busy handler wants to try again
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
CloudSqlite.acquireWriteLock = acquireWriteLock;
|
|
123
|
+
/**
|
|
124
|
+
* Perform an asynchronous write operation on a CloudContainer with the write lock held.
|
|
125
|
+
* 1. if write lock is already held, call operation and return.
|
|
126
|
+
* 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
|
|
127
|
+
* 3. perform the operation
|
|
128
|
+
* 3.a if the operation throws, abandon all changes and re-throw
|
|
129
|
+
* 4. release the write lock.
|
|
130
|
+
* 5. return value from operation
|
|
131
|
+
* @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
|
|
132
|
+
* @param container the CloudContainer for which the lock is to be acquired
|
|
133
|
+
* @param operation an asynchronous operation performed with the write lock held.
|
|
134
|
+
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
135
|
+
* @returns a Promise with the result of `operation`
|
|
136
|
+
*/
|
|
137
|
+
async function withWriteLock(user, container, operation, busyHandler) {
|
|
138
|
+
if (container.hasWriteLock)
|
|
139
|
+
return operation();
|
|
140
|
+
await acquireWriteLock(user, container, busyHandler);
|
|
141
|
+
try {
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
143
|
+
const val = await operation(); // wait for work to finish or fail
|
|
144
|
+
container.releaseWriteLock();
|
|
145
|
+
return val;
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
container.abandonChanges(); // if operation threw, abandon all changes
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
CloudSqlite.withWriteLock = withWriteLock;
|
|
153
|
+
})(CloudSqlite = exports.CloudSqlite || (exports.CloudSqlite = {}));
|
|
154
154
|
//# sourceMappingURL=CloudSqlite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../src/CloudSqlite.ts"],"names":[],"mappings":"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","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module SQLiteDb\n */\n\nimport { mkdirSync } from \"fs\";\nimport { dirname } from \"path\";\nimport { NativeLibrary } from \"@bentley/imodeljs-native\";\nimport { BriefcaseStatus, GuidString } from \"@itwin/core-bentley\";\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\n\n/** Types for using SQLite files stored in cloud containers.\n * @beta\n */\nexport namespace CloudSqlite {\n export function createCloudContainer(args: ContainerAccessProps): CloudContainer {\n return new NativeLibrary.nativeLib.CloudContainer(args);\n }\n export function createCloudCache(args: CloudSqlite.CacheProps): CloudSqlite.CloudCache {\n return new NativeLibrary.nativeLib.CloudCache(args);\n }\n export function startCloudPrefetch(container: CloudSqlite.CloudContainer, dbName: string, args?: CloudSqlite.PrefetchProps): CloudSqlite.CloudPrefetch {\n return new NativeLibrary.nativeLib.CloudPrefetch(container, dbName, args);\n }\n\n /** Properties that specify how to access the account for a cloud blob-store container. */\n export interface AccountAccessProps {\n /** blob storage module: e.g. \"azure\", \"google\", \"aws\". May also include URI style parameters. */\n storageType: string;\n /** blob store account name, or a URI for custom domains. */\n accessName: string;\n }\n\n /** Properties of a CloudContainer. */\n export interface ContainerProps {\n /** the name of the container. */\n containerId: string;\n /** an alias for the container. Defaults to `containerId` */\n alias?: string;\n /** token that grants access to the container. For sas=1 `storageType`s, this is the sasToken. For sas=0, this is the account key */\n accessToken: string;\n /** if true, container is attached with write permissions, and accessToken must provide write access to the cloud container. */\n writeable?: boolean;\n /** if true, container is attached in \"secure\" mode (blocks are encrypted). Only supported in daemon mode. */\n secure?: boolean;\n }\n\n /** Returned from `CloudContainer.queryDatabase` describing one database in the container */\n export interface CachedDbProps {\n /** The total of (4Mb) blocks in the database. */\n readonly totalBlocks: number;\n /** the number of blocks of the database that have been downloaded into the CloudCache */\n readonly localBlocks: number;\n /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */\n readonly dirtyBlocks: number;\n /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */\n readonly transactions: boolean;\n /** the state of this database. Indicates whether the database is new or deleted since last upload */\n readonly state: \"\" | \"copied\" | \"deleted\";\n }\n\n /** Properties for accessing a CloudContainer */\n export type ContainerAccessProps = AccountAccessProps & ContainerProps & {\n /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */\n durationSeconds?: number;\n };\n\n /** The name of a CloudSqlite database within a CloudContainer. */\n export interface DbNameProp {\n /** the name of the database within the CloudContainer.\n * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/\n dbName: string;\n }\n\n /** Properties for accessing a database within a CloudContainer */\n export interface DbProps extends DbNameProp {\n /** the name of the local file to access the database. */\n localFileName: LocalFileName;\n }\n\n export type TransferDirection = \"upload\" | \"download\";\n export interface TransferProgress {\n /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */\n onProgress?: (loaded: number, total: number) => number;\n }\n\n export interface CloudHttpProps {\n /** The number of simultaneous HTTP requests. Default is 6. */\n nRequests?: number;\n }\n\n export interface PrefetchProps extends CloudHttpProps {\n /** timeout between requests, in milliseconds. Default is 100. */\n timeout?: number;\n /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */\n minRequests?: number;\n }\n\n export type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;\n\n /** Properties for creating a CloudCache. */\n export interface CacheProps extends CloudHttpProps {\n /** 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. */\n rootDir: string;\n /** name of this cache. It is possible to have more than one CloudCache in the same session. */\n name: string;\n /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */\n cacheSize?: string;\n /** turn on diagnostics for `curl` (outputs to stderr) */\n curlDiagnostics?: boolean;\n }\n\n /** Parameters used to obtain the write lock on a cloud container\n * @internal\n */\n export interface ObtainLockParams {\n /** The name of the user attempting to acquire the write lock. This name will be shown to other users while the lock is held. */\n user?: string;\n /** number of times to retry in the event the lock currently held by someone else.\n * After this number of attempts, `onFailure` is called. Default is 20.\n */\n nRetries: number;\n /** Delay between retries, in milliseconds. Default is 100. */\n retryDelayMs: number;\n /** function called if lock cannot be obtained after all retries. It is called with the name of the user currently holding the lock and\n * generally is expected that the user will be consulted whether to wait further.\n * If this function returns \"stop\", an exception will be thrown. Otherwise the retry cycle is restarted.\n */\n onFailure?: WriteLockBusyHandler;\n }\n\n /** @internal */\n export interface LockAndOpenArgs {\n /** the name to be displayed in the event of lock collisions */\n user: string;\n /** the name of the database within the container */\n dbName: string;\n /** the CloudContainer on which the operation will be performed */\n container: CloudContainer;\n /** if present, function called when the write lock is currently held by another user. */\n busyHandler?: WriteLockBusyHandler;\n }\n\n /** Logging categories for `CloudCache.setLogMask` */\n export enum LoggingMask {\n /** log all HTTP requests and responses */\n HTTP = 0x01,\n /** log as blocks become dirty and must be uploaded */\n DirtyBlocks = 0x02,\n /** log as blocks are added to the delete list */\n AddToDelete = 0x04,\n /** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */\n LifecycleEvents = 0x08,\n /** Turn on all logging categories */\n All = 0xff,\n /** Disable logging */\n None = 0,\n }\n\n /**\n * A cache for storing data from CloudSqlite databases. This object refers to a directory on a local filesystem\n * and is used to **connect** CloudContainers so they may be accessed. The contents of the cache directory are entirely\n * controlled by CloudSqlite and should be empty when the cache is first created and never modified directly. It maintains\n * the state of the local data across sessions.\n */\n export interface CloudCache {\n /** `true` if this CloudCache is connected to a daemon process */\n get isDaemon(): boolean;\n /** The name for this CloudCache. */\n get name(): string;\n /** The root directory of this CloudCache on a local drive. */\n get rootDir(): LocalDirName;\n /** The guid for this CloudCache. Used for acquiring write lock. */\n get guid(): GuidString;\n /** Configure logging for this CloudCache.\n * @param mask A bitmask of `LoggingMask` values\n * @note this method does nothing if [[isDaemon]] is true. Daemon logging is configured when the daemon is started.\n * @note HTTP logging can be happen on multiple threads and may be buffered. To see buffered log messages, periodically call\n * `IModelHost.flushLog`\n */\n setLogMask(mask: number): void;\n /** destroy this CloudCache. All CloudContainers should be detached before calling this. */\n destroy(): void;\n }\n\n /** A CloudSqlite container that may be connected to a CloudCache. */\n export interface CloudContainer {\n readonly cache?: CloudCache;\n /** The ContainerId. */\n get containerId(): string;\n /** The *alias* to identify this CloudContainer in a CloudCache. Usually just the ContainerId. */\n get alias(): string;\n /** true if this CloudContainer is currently connected to a CloudCache via the `connect` method. */\n get isConnected(): boolean;\n /** true if this CloudContainer was created with the `writeable` flag (and its `accessToken` supplies write access). */\n get isWriteable(): boolean;\n /** true if this CloudContainer currently holds the write lock for its container in the cloud. */\n get hasWriteLock(): boolean;\n /** true if this CloudContainer has local changes that have not be uploaded to its container in the cloud. */\n get hasLocalChanges(): boolean;\n /** The current accessToken providing access to the cloud container */\n get accessToken(): string;\n set accessToken(val: string);\n /** Get the number of garbage blocks in this container that can be purged. */\n get garbageBlocks(): number;\n /** The block size for this CloudContainer. */\n get blockSize(): number;\n\n /**\n * initialize a cloud blob-store container to be used as a new Sqlite CloudContainer. This creates the manifest, and should be\n * performed on an empty container. If an existing manifest is present, it is destroyed and a new one is created (essentially emptying the container.)\n */\n initializeContainer(opts?: { checksumBlockNames?: boolean, blockSize?: number }): void;\n\n /**\n * Attempt to acquire the write lock for this CloudContainer. For this to succeed:\n * 1. it must be connected to a `CloudCache`\n * 2. this CloudContainer must have been constructed with `writeable: true`\n * 3. the `accessToken` must authorize write access\n * 4. no other process may be holding an unexpired write lock\n * @throws exception if any of the above conditions fail\n * @note Write locks *expire* after the duration specified in the `durationSeconds` property of the constructor argument, in case a process\n * crashes or otherwise fails to release the lock. Calling `acquireWriteLock` with the lock already held resets the lock duration from the current time,\n * 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\n * before it expires.)\n * @note on success, the manifest is polled before the promise resolves.\n * @param user An identifier of the process/user locking the CloudContainer. In the event of a write lock\n * collision, this string will be included in the exception string of the *other* process attempting to obtain a write lock.\n */\n acquireWriteLock(user: string): void;\n\n /**\n * Release the write lock if it is currently held.\n * @note if there are local changes that have not been uploaded, they are automatically uploaded before the write lock is released.\n * @note if the write lock is not held, this method does nothing.\n */\n releaseWriteLock(): void;\n\n /**\n * Destroy any currently valid write lock from this or any other process. This is obviously very dangerous and defeats the purpose of write locking.\n * 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.\n * For this to succeed, all of the conditions of `acquireWriteLock` must be true other than #4.\n */\n clearWriteLock(): void;\n\n /**\n * Abandon any local changes in this container. If the write lock is currently held, it is released.\n * This function fails with BE_SQLITE_BUSY if one or more clients have open read or write transactions\n * on any database in the container.\n */\n abandonChanges(): void;\n\n /**\n * Connect this CloudContainer to a CloudCache for reading or writing its manifest, write lock, and databases.\n * @note A CloudCache is a local directory holding copies of information from the cloud. Its content is persistent across sessions,\n * but this method must be called each session to (re)establish the connection to the cache. If the CloudCache was previously populated,\n * this method may be called and will succeed *even when offline* or without a valid `accessToken`.\n * @note all operations that access the contents of databases or the manifest require this method be called (`isConnected === true`).\n */\n connect(cache: CloudCache): void;\n\n /**\n * Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container. Leaves the container attached to the\n * CloudCache so it is available for future sessions.\n */\n disconnect(): void;\n\n /**\n * Permanently Detach and Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container.\n */\n detach(): void;\n\n /**\n * Poll cloud storage for changes from other processes. *No changes* made by other processes are visible to\n * this CloudContainer unless/until this method is called.\n * @note this is automatically called whenever the write lock is obtained to ensure all changes are against the latest version.\n */\n checkForChanges(): void;\n\n /**\n * Upload any changed blocks from all databases in this CloudContainer.\n * @note this is called automatically from `releaseWriteLock` before the write lock is released. It is only necessary to call this directly if you\n * wish to upload changes while the write lock is still held.\n * @see hasLocalChanges\n */\n uploadChanges(): Promise<void>;\n\n /**\n * Clean any unused deleted blocks from cloud storage. When a database is written, a subset of its blocks are replaced\n * by new versions, sometimes leaving the originals unused. In this case, they are not deleted immediately.\n * Instead, they are scheduled for deletion at some later time. Calling this method deletes all blocks in the cloud container\n * for which the scheduled deletion time has passed.\n * @param nSeconds Any block that was marked as unused before this number of seconds ago will be deleted. Specifying a non-zero\n * value gives a period of time for other clients to refresh their manifests and stop using the now-garbage blocks. Otherwise they may get\n * a 404 error. Default is 1 hour.\n */\n cleanDeletedBlocks(nSeconds?: number): Promise<void>;\n\n /**\n * Create a copy of an existing database within this CloudContainer with a new name.\n * @note CloudSqlite uses copy-on-write semantics for this operation. That is, this method merely makes a\n * new entry in the manifest with the new name that *shares* all of its blocks with the original database.\n * If either database subsequently changes, the only modified blocks are not shared.\n */\n copyDatabase(dbName: string, toAlias: string): Promise<void>;\n\n /** Remove a database from this CloudContainer.\n * @see cleanDeletedBlocks\n */\n deleteDatabase(dbName: string): Promise<void>;\n\n /** Get the list of database names in this CloudContainer.\n * @param globArg if present, filter the results with SQLite [GLOB](https://www.sqlite.org/lang_expr.html#glob) operator.\n */\n queryDatabases(globArg?: string): string[];\n\n /**\n * Get the status of a specific database in this CloudContainer.\n * @param dbName the name of the database of interest\n */\n queryDatabase(dbName: string): CloudSqlite.CachedDbProps | undefined;\n\n /**\n * Get the SHA1 hash of the content of a database.\n * @param dbName the name of the database of interest\n * @note the hash will be empty if the database does not exist\n */\n queryDatabaseHash(dbName: string): string;\n }\n\n /** @internal */\n export interface CloudPrefetch {\n readonly cloudContainer: CloudContainer;\n readonly dbName: string;\n\n /** Cancel a currently pending prefetch. The promise will be resolved immediately after this call. */\n cancel(): void;\n\n /**\n * Promise that is resolved when the prefetch completes or is cancelled. Await this promise to ensure that the\n * database has been fully downloaded before going offline, for example.\n * @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.\n * @note the promise is *not* rejected on `cancel`. Some progress may (or may not) have been made by the request.\n * @note To monitor the progress being made during prefetch, call `CloudContainer.queryDatabase` periodically.\n */\n promise: Promise<boolean>;\n }\n\n /** @internal */\n export async function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps) {\n if (direction === \"download\")\n mkdirSync(dirname(props.localFileName), { recursive: true }); // make sure the directory exists before starting download\n\n let timer: NodeJS.Timeout | undefined;\n try {\n const transfer = new NativeLibrary.nativeLib.CloudDbTransfer(direction, container, props);\n let total = 0;\n const onProgress = props.onProgress;\n if (onProgress) {\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\n const progress = transfer.getProgress();\n total = progress.total;\n if (onProgress(progress.loaded, progress.total))\n transfer.cancelTransfer();\n }, 250);\n }\n await transfer.promise;\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\n } catch (err: any) {\n if (err.message === \"cancelled\")\n err.errorNumber = BriefcaseStatus.DownloadCancelled;\n\n throw err;\n } finally {\n if (timer)\n clearInterval(timer);\n }\n }\n\n /** Upload a database into a CloudContainer\n * @param container the CloudContainer holding the database. Must be connected.\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\n * @note this function requires that the write lock be held on the container\n */\n export async function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\n await transferDb(\"upload\", container, props);\n container.checkForChanges(); // re-read the manifest so the database is available locally.\n }\n\n /** Download a database from a CloudContainer\n * @param container the CloudContainer holding the database. Must be connected.\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\n * @returns a Promise that is resolved when the download completes.\n * @note the download is \"restartable.\" If the transfer is aborted and then re-requested, it will continue from where\n * it left off rather than re-downloading the entire file.\n */\n export async function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\n await transferDb(\"download\", container, props);\n }\n\n /** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.\n * @param lockedBy The identifier supplied by the application/user that currently holds the lock.\n * @param expires a stringified Date (in local time) indicating when the lock will expire.\n * @return \"stop\" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.\n */\n export type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | \"stop\">;\n\n /**\n * Attempt to acquire the write lock for a container, with retries.\n * If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns \"stop\", throw. Otherwise try again.\n * @note if write lock is already held, this function does nothing.\n * @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\n * @param container the CloudContainer for which the lock is to be acquired\n * @param busyHandler if present, function called when the write lock is currently held by another user.\n */\n export async function acquireWriteLock(user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler) {\n if (container.hasWriteLock)\n return;\n\n while (true) {\n try {\n return container.acquireWriteLock(user);\n } catch (e: any) {\n if (e.errorNumber === 5 && busyHandler && \"stop\" !== await busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY\n continue; // busy handler wants to try again\n throw e;\n }\n }\n }\n\n /**\n * Perform an asynchronous write operation on a CloudContainer with the write lock held.\n * 1. if write lock is already held, call operation and return.\n * 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.\n * 3. perform the operation\n * 3.a if the operation throws, abandon all changes and re-throw\n * 4. release the write lock.\n * 5. return value from operation\n * @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\n * @param container the CloudContainer for which the lock is to be acquired\n * @param operation an asynchronous operation performed with the write lock held.\n * @param busyHandler if present, function called when the write lock is currently held by another user.\n * @returns a Promise with the result of `operation`\n */\n export async function withWriteLock<T>(user: string, container: CloudContainer, operation: () => T, busyHandler?: WriteLockBusyHandler) {\n if (container.hasWriteLock)\n return operation();\n\n await acquireWriteLock(user, container, busyHandler);\n try {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const val = await operation(); // wait for work to finish or fail\n container.releaseWriteLock();\n return val;\n } catch (e) {\n container.abandonChanges(); // if operation threw, abandon all changes\n throw e;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../src/CloudSqlite.ts"],"names":[],"mappings":"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","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 SQLiteDb\r\n */\r\n\r\nimport { mkdirSync } from \"fs\";\r\nimport { dirname } from \"path\";\r\nimport { NativeLibrary } from \"@bentley/imodeljs-native\";\r\nimport { BriefcaseStatus, GuidString } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\n\r\n/** Types for using SQLite files stored in cloud containers.\r\n * @beta\r\n */\r\nexport namespace CloudSqlite {\r\n export function createCloudContainer(args: ContainerAccessProps): CloudContainer {\r\n return new NativeLibrary.nativeLib.CloudContainer(args);\r\n }\r\n export function createCloudCache(args: CloudSqlite.CacheProps): CloudSqlite.CloudCache {\r\n return new NativeLibrary.nativeLib.CloudCache(args);\r\n }\r\n export function startCloudPrefetch(container: CloudSqlite.CloudContainer, dbName: string, args?: CloudSqlite.PrefetchProps): CloudSqlite.CloudPrefetch {\r\n return new NativeLibrary.nativeLib.CloudPrefetch(container, dbName, args);\r\n }\r\n\r\n /** Properties that specify how to access the account for a cloud blob-store container. */\r\n export interface AccountAccessProps {\r\n /** blob storage module: e.g. \"azure\", \"google\", \"aws\". May also include URI style parameters. */\r\n storageType: string;\r\n /** blob store account name, or a URI for custom domains. */\r\n accessName: string;\r\n }\r\n\r\n /** Properties of a CloudContainer. */\r\n export interface ContainerProps {\r\n /** the name of the container. */\r\n containerId: string;\r\n /** an alias for the container. Defaults to `containerId` */\r\n alias?: string;\r\n /** token that grants access to the container. For sas=1 `storageType`s, this is the sasToken. For sas=0, this is the account key */\r\n accessToken: string;\r\n /** if true, container is attached with write permissions, and accessToken must provide write access to the cloud container. */\r\n writeable?: boolean;\r\n /** if true, container is attached in \"secure\" mode (blocks are encrypted). Only supported in daemon mode. */\r\n secure?: boolean;\r\n }\r\n\r\n /** Returned from `CloudContainer.queryDatabase` describing one database in the container */\r\n export interface CachedDbProps {\r\n /** The total of (4Mb) blocks in the database. */\r\n readonly totalBlocks: number;\r\n /** the number of blocks of the database that have been downloaded into the CloudCache */\r\n readonly localBlocks: number;\r\n /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */\r\n readonly dirtyBlocks: number;\r\n /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */\r\n readonly transactions: boolean;\r\n /** the state of this database. Indicates whether the database is new or deleted since last upload */\r\n readonly state: \"\" | \"copied\" | \"deleted\";\r\n }\r\n\r\n /** Properties for accessing a CloudContainer */\r\n export type ContainerAccessProps = AccountAccessProps & ContainerProps & {\r\n /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */\r\n durationSeconds?: number;\r\n };\r\n\r\n /** The name of a CloudSqlite database within a CloudContainer. */\r\n export interface DbNameProp {\r\n /** the name of the database within the CloudContainer.\r\n * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/\r\n dbName: string;\r\n }\r\n\r\n /** Properties for accessing a database within a CloudContainer */\r\n export interface DbProps extends DbNameProp {\r\n /** the name of the local file to access the database. */\r\n localFileName: LocalFileName;\r\n }\r\n\r\n export type TransferDirection = \"upload\" | \"download\";\r\n export interface TransferProgress {\r\n /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */\r\n onProgress?: (loaded: number, total: number) => number;\r\n }\r\n\r\n export interface CloudHttpProps {\r\n /** The number of simultaneous HTTP requests. Default is 6. */\r\n nRequests?: number;\r\n }\r\n\r\n export interface PrefetchProps extends CloudHttpProps {\r\n /** timeout between requests, in milliseconds. Default is 100. */\r\n timeout?: number;\r\n /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */\r\n minRequests?: number;\r\n }\r\n\r\n export type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;\r\n\r\n /** Properties for creating a CloudCache. */\r\n export interface CacheProps extends CloudHttpProps {\r\n /** 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. */\r\n rootDir: string;\r\n /** name of this cache. It is possible to have more than one CloudCache in the same session. */\r\n name: string;\r\n /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */\r\n cacheSize?: string;\r\n /** turn on diagnostics for `curl` (outputs to stderr) */\r\n curlDiagnostics?: boolean;\r\n }\r\n\r\n /** Parameters used to obtain the write lock on a cloud container\r\n * @internal\r\n */\r\n export interface ObtainLockParams {\r\n /** The name of the user attempting to acquire the write lock. This name will be shown to other users while the lock is held. */\r\n user?: string;\r\n /** number of times to retry in the event the lock currently held by someone else.\r\n * After this number of attempts, `onFailure` is called. Default is 20.\r\n */\r\n nRetries: number;\r\n /** Delay between retries, in milliseconds. Default is 100. */\r\n retryDelayMs: number;\r\n /** function called if lock cannot be obtained after all retries. It is called with the name of the user currently holding the lock and\r\n * generally is expected that the user will be consulted whether to wait further.\r\n * If this function returns \"stop\", an exception will be thrown. Otherwise the retry cycle is restarted.\r\n */\r\n onFailure?: WriteLockBusyHandler;\r\n }\r\n\r\n /** @internal */\r\n export interface LockAndOpenArgs {\r\n /** the name to be displayed in the event of lock collisions */\r\n user: string;\r\n /** the name of the database within the container */\r\n dbName: string;\r\n /** the CloudContainer on which the operation will be performed */\r\n container: CloudContainer;\r\n /** if present, function called when the write lock is currently held by another user. */\r\n busyHandler?: WriteLockBusyHandler;\r\n }\r\n\r\n /** Logging categories for `CloudCache.setLogMask` */\r\n export enum LoggingMask {\r\n /** log all HTTP requests and responses */\r\n HTTP = 0x01,\r\n /** log as blocks become dirty and must be uploaded */\r\n DirtyBlocks = 0x02,\r\n /** log as blocks are added to the delete list */\r\n AddToDelete = 0x04,\r\n /** log container lifecycle events (e.g. authorization requests, disconnects, and state transitions) */\r\n LifecycleEvents = 0x08,\r\n /** Turn on all logging categories */\r\n All = 0xff,\r\n /** Disable logging */\r\n None = 0,\r\n }\r\n\r\n /**\r\n * A cache for storing data from CloudSqlite databases. This object refers to a directory on a local filesystem\r\n * and is used to **connect** CloudContainers so they may be accessed. The contents of the cache directory are entirely\r\n * controlled by CloudSqlite and should be empty when the cache is first created and never modified directly. It maintains\r\n * the state of the local data across sessions.\r\n */\r\n export interface CloudCache {\r\n /** `true` if this CloudCache is connected to a daemon process */\r\n get isDaemon(): boolean;\r\n /** The name for this CloudCache. */\r\n get name(): string;\r\n /** The root directory of this CloudCache on a local drive. */\r\n get rootDir(): LocalDirName;\r\n /** The guid for this CloudCache. Used for acquiring write lock. */\r\n get guid(): GuidString;\r\n /** Configure logging for this CloudCache.\r\n * @param mask A bitmask of `LoggingMask` values\r\n * @note this method does nothing if [[isDaemon]] is true. Daemon logging is configured when the daemon is started.\r\n * @note HTTP logging can be happen on multiple threads and may be buffered. To see buffered log messages, periodically call\r\n * `IModelHost.flushLog`\r\n */\r\n setLogMask(mask: number): void;\r\n /** destroy this CloudCache. All CloudContainers should be detached before calling this. */\r\n destroy(): void;\r\n }\r\n\r\n /** A CloudSqlite container that may be connected to a CloudCache. */\r\n export interface CloudContainer {\r\n readonly cache?: CloudCache;\r\n /** The ContainerId. */\r\n get containerId(): string;\r\n /** The *alias* to identify this CloudContainer in a CloudCache. Usually just the ContainerId. */\r\n get alias(): string;\r\n /** true if this CloudContainer is currently connected to a CloudCache via the `connect` method. */\r\n get isConnected(): boolean;\r\n /** true if this CloudContainer was created with the `writeable` flag (and its `accessToken` supplies write access). */\r\n get isWriteable(): boolean;\r\n /** true if this CloudContainer currently holds the write lock for its container in the cloud. */\r\n get hasWriteLock(): boolean;\r\n /** true if this CloudContainer has local changes that have not be uploaded to its container in the cloud. */\r\n get hasLocalChanges(): boolean;\r\n /** The current accessToken providing access to the cloud container */\r\n get accessToken(): string;\r\n set accessToken(val: string);\r\n /** Get the number of garbage blocks in this container that can be purged. */\r\n get garbageBlocks(): number;\r\n /** The block size for this CloudContainer. */\r\n get blockSize(): number;\r\n\r\n /**\r\n * initialize a cloud blob-store container to be used as a new Sqlite CloudContainer. This creates the manifest, and should be\r\n * performed on an empty container. If an existing manifest is present, it is destroyed and a new one is created (essentially emptying the container.)\r\n */\r\n initializeContainer(opts?: { checksumBlockNames?: boolean, blockSize?: number }): void;\r\n\r\n /**\r\n * Attempt to acquire the write lock for this CloudContainer. For this to succeed:\r\n * 1. it must be connected to a `CloudCache`\r\n * 2. this CloudContainer must have been constructed with `writeable: true`\r\n * 3. the `accessToken` must authorize write access\r\n * 4. no other process may be holding an unexpired write lock\r\n * @throws exception if any of the above conditions fail\r\n * @note Write locks *expire* after the duration specified in the `durationSeconds` property of the constructor argument, in case a process\r\n * crashes or otherwise fails to release the lock. Calling `acquireWriteLock` with the lock already held resets the lock duration from the current time,\r\n * 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\r\n * before it expires.)\r\n * @note on success, the manifest is polled before the promise resolves.\r\n * @param user An identifier of the process/user locking the CloudContainer. In the event of a write lock\r\n * collision, this string will be included in the exception string of the *other* process attempting to obtain a write lock.\r\n */\r\n acquireWriteLock(user: string): void;\r\n\r\n /**\r\n * Release the write lock if it is currently held.\r\n * @note if there are local changes that have not been uploaded, they are automatically uploaded before the write lock is released.\r\n * @note if the write lock is not held, this method does nothing.\r\n */\r\n releaseWriteLock(): void;\r\n\r\n /**\r\n * Destroy any currently valid write lock from this or any other process. This is obviously very dangerous and defeats the purpose of write locking.\r\n * 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.\r\n * For this to succeed, all of the conditions of `acquireWriteLock` must be true other than #4.\r\n */\r\n clearWriteLock(): void;\r\n\r\n /**\r\n * Abandon any local changes in this container. If the write lock is currently held, it is released.\r\n * This function fails with BE_SQLITE_BUSY if one or more clients have open read or write transactions\r\n * on any database in the container.\r\n */\r\n abandonChanges(): void;\r\n\r\n /**\r\n * Connect this CloudContainer to a CloudCache for reading or writing its manifest, write lock, and databases.\r\n * @note A CloudCache is a local directory holding copies of information from the cloud. Its content is persistent across sessions,\r\n * but this method must be called each session to (re)establish the connection to the cache. If the CloudCache was previously populated,\r\n * this method may be called and will succeed *even when offline* or without a valid `accessToken`.\r\n * @note all operations that access the contents of databases or the manifest require this method be called (`isConnected === true`).\r\n */\r\n connect(cache: CloudCache): void;\r\n\r\n /**\r\n * Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container. Leaves the container attached to the\r\n * CloudCache so it is available for future sessions.\r\n */\r\n disconnect(): void;\r\n\r\n /**\r\n * Permanently Detach and Disconnect this CloudContainer from its CloudCache. There must be no open databases from this container.\r\n */\r\n detach(): void;\r\n\r\n /**\r\n * Poll cloud storage for changes from other processes. *No changes* made by other processes are visible to\r\n * this CloudContainer unless/until this method is called.\r\n * @note this is automatically called whenever the write lock is obtained to ensure all changes are against the latest version.\r\n */\r\n checkForChanges(): void;\r\n\r\n /**\r\n * Upload any changed blocks from all databases in this CloudContainer.\r\n * @note this is called automatically from `releaseWriteLock` before the write lock is released. It is only necessary to call this directly if you\r\n * wish to upload changes while the write lock is still held.\r\n * @see hasLocalChanges\r\n */\r\n uploadChanges(): Promise<void>;\r\n\r\n /**\r\n * Clean any unused deleted blocks from cloud storage. When a database is written, a subset of its blocks are replaced\r\n * by new versions, sometimes leaving the originals unused. In this case, they are not deleted immediately.\r\n * Instead, they are scheduled for deletion at some later time. Calling this method deletes all blocks in the cloud container\r\n * for which the scheduled deletion time has passed.\r\n * @param nSeconds Any block that was marked as unused before this number of seconds ago will be deleted. Specifying a non-zero\r\n * value gives a period of time for other clients to refresh their manifests and stop using the now-garbage blocks. Otherwise they may get\r\n * a 404 error. Default is 1 hour.\r\n */\r\n cleanDeletedBlocks(nSeconds?: number): Promise<void>;\r\n\r\n /**\r\n * Create a copy of an existing database within this CloudContainer with a new name.\r\n * @note CloudSqlite uses copy-on-write semantics for this operation. That is, this method merely makes a\r\n * new entry in the manifest with the new name that *shares* all of its blocks with the original database.\r\n * If either database subsequently changes, the only modified blocks are not shared.\r\n */\r\n copyDatabase(dbName: string, toAlias: string): Promise<void>;\r\n\r\n /** Remove a database from this CloudContainer.\r\n * @see cleanDeletedBlocks\r\n */\r\n deleteDatabase(dbName: string): Promise<void>;\r\n\r\n /** Get the list of database names in this CloudContainer.\r\n * @param globArg if present, filter the results with SQLite [GLOB](https://www.sqlite.org/lang_expr.html#glob) operator.\r\n */\r\n queryDatabases(globArg?: string): string[];\r\n\r\n /**\r\n * Get the status of a specific database in this CloudContainer.\r\n * @param dbName the name of the database of interest\r\n */\r\n queryDatabase(dbName: string): CloudSqlite.CachedDbProps | undefined;\r\n\r\n /**\r\n * Get the SHA1 hash of the content of a database.\r\n * @param dbName the name of the database of interest\r\n * @note the hash will be empty if the database does not exist\r\n */\r\n queryDatabaseHash(dbName: string): string;\r\n }\r\n\r\n /** @internal */\r\n export interface CloudPrefetch {\r\n readonly cloudContainer: CloudContainer;\r\n readonly dbName: string;\r\n\r\n /** Cancel a currently pending prefetch. The promise will be resolved immediately after this call. */\r\n cancel(): void;\r\n\r\n /**\r\n * Promise that is resolved when the prefetch completes or is cancelled. Await this promise to ensure that the\r\n * database has been fully downloaded before going offline, for example.\r\n * @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.\r\n * @note the promise is *not* rejected on `cancel`. Some progress may (or may not) have been made by the request.\r\n * @note To monitor the progress being made during prefetch, call `CloudContainer.queryDatabase` periodically.\r\n */\r\n promise: Promise<boolean>;\r\n }\r\n\r\n /** @internal */\r\n export async function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps) {\r\n if (direction === \"download\")\r\n mkdirSync(dirname(props.localFileName), { recursive: true }); // make sure the directory exists before starting download\r\n\r\n let timer: NodeJS.Timeout | undefined;\r\n try {\r\n const transfer = new NativeLibrary.nativeLib.CloudDbTransfer(direction, container, props);\r\n let total = 0;\r\n const onProgress = props.onProgress;\r\n if (onProgress) {\r\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\r\n const progress = transfer.getProgress();\r\n total = progress.total;\r\n if (onProgress(progress.loaded, progress.total))\r\n transfer.cancelTransfer();\r\n }, 250);\r\n }\r\n await transfer.promise;\r\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\r\n } catch (err: any) {\r\n if (err.message === \"cancelled\")\r\n err.errorNumber = BriefcaseStatus.DownloadCancelled;\r\n\r\n throw err;\r\n } finally {\r\n if (timer)\r\n clearInterval(timer);\r\n }\r\n }\r\n\r\n /** Upload a database into a CloudContainer\r\n * @param container the CloudContainer holding the database. Must be connected.\r\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\r\n * @note this function requires that the write lock be held on the container\r\n */\r\n export async function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\r\n await transferDb(\"upload\", container, props);\r\n container.checkForChanges(); // re-read the manifest so the database is available locally.\r\n }\r\n\r\n /** Download a database from a CloudContainer\r\n * @param container the CloudContainer holding the database. Must be connected.\r\n * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.\r\n * @returns a Promise that is resolved when the download completes.\r\n * @note the download is \"restartable.\" If the transfer is aborted and then re-requested, it will continue from where\r\n * it left off rather than re-downloading the entire file.\r\n */\r\n export async function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void> {\r\n await transferDb(\"download\", container, props);\r\n }\r\n\r\n /** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.\r\n * @param lockedBy The identifier supplied by the application/user that currently holds the lock.\r\n * @param expires a stringified Date (in local time) indicating when the lock will expire.\r\n * @return \"stop\" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.\r\n */\r\n export type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | \"stop\">;\r\n\r\n /**\r\n * Attempt to acquire the write lock for a container, with retries.\r\n * If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns \"stop\", throw. Otherwise try again.\r\n * @note if write lock is already held, this function does nothing.\r\n * @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\r\n * @param container the CloudContainer for which the lock is to be acquired\r\n * @param busyHandler if present, function called when the write lock is currently held by another user.\r\n */\r\n export async function acquireWriteLock(user: string, container: CloudContainer, busyHandler?: WriteLockBusyHandler) {\r\n if (container.hasWriteLock)\r\n return;\r\n\r\n while (true) {\r\n try {\r\n return container.acquireWriteLock(user);\r\n } catch (e: any) {\r\n if (e.errorNumber === 5 && busyHandler && \"stop\" !== await busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY\r\n continue; // busy handler wants to try again\r\n throw e;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Perform an asynchronous write operation on a CloudContainer with the write lock held.\r\n * 1. if write lock is already held, call operation and return.\r\n * 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.\r\n * 3. perform the operation\r\n * 3.a if the operation throws, abandon all changes and re-throw\r\n * 4. release the write lock.\r\n * 5. return value from operation\r\n * @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\r\n * @param container the CloudContainer for which the lock is to be acquired\r\n * @param operation an asynchronous operation performed with the write lock held.\r\n * @param busyHandler if present, function called when the write lock is currently held by another user.\r\n * @returns a Promise with the result of `operation`\r\n */\r\n export async function withWriteLock<T>(user: string, container: CloudContainer, operation: () => T, busyHandler?: WriteLockBusyHandler) {\r\n if (container.hasWriteLock)\r\n return operation();\r\n\r\n await acquireWriteLock(user, container, busyHandler);\r\n try {\r\n // eslint-disable-next-line @typescript-eslint/await-thenable\r\n const val = await operation(); // wait for work to finish or fail\r\n container.releaseWriteLock();\r\n return val;\r\n } catch (e) {\r\n container.abandonChanges(); // if operation threw, abandon all changes\r\n throw e;\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Readable } from "stream";
|
|
3
|
-
import { CloudStorageContainerDescriptor, CloudStorageContainerUrl, CloudStorageProvider, IModelRpcProps } from "@itwin/core-common";
|
|
4
|
-
/** @beta */
|
|
5
|
-
export interface AzureBlobStorageCredentials {
|
|
6
|
-
account: string;
|
|
7
|
-
accessKey: string;
|
|
8
|
-
baseUrl?: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @beta
|
|
12
|
-
* @deprecated in 3.x.
|
|
13
|
-
*/
|
|
14
|
-
export interface CloudStorageUploadOptions {
|
|
15
|
-
type?: string;
|
|
16
|
-
cacheControl?: string;
|
|
17
|
-
contentEncoding?: "gzip";
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @beta
|
|
21
|
-
* @deprecated in 3.x.
|
|
22
|
-
*/
|
|
23
|
-
export declare abstract class CloudStorageService {
|
|
24
|
-
initialize(): void;
|
|
25
|
-
terminate(): void;
|
|
26
|
-
abstract id: CloudStorageProvider;
|
|
27
|
-
abstract obtainContainerUrl(id: CloudStorageContainerDescriptor, expiry: Date, clientIp?: string): CloudStorageContainerUrl;
|
|
28
|
-
abstract upload(container: string, name: string, data: Uint8Array, options?: CloudStorageUploadOptions, metadata?: object): Promise<string>;
|
|
29
|
-
download(_name: string): Promise<Readable | undefined>;
|
|
30
|
-
protected makeDescriptor(id: CloudStorageContainerDescriptor): {
|
|
31
|
-
name: string;
|
|
32
|
-
provider: CloudStorageProvider;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @beta
|
|
37
|
-
* @deprecated in 3.x.
|
|
38
|
-
*/
|
|
39
|
-
export declare class AzureBlobStorage extends CloudStorageService {
|
|
40
|
-
private _service;
|
|
41
|
-
private _credential;
|
|
42
|
-
private _baseUrl;
|
|
43
|
-
constructor(credentials: AzureBlobStorageCredentials);
|
|
44
|
-
readonly id = CloudStorageProvider.Azure;
|
|
45
|
-
obtainContainerUrl(id: CloudStorageContainerDescriptor, expiry: Date, clientIp?: string): CloudStorageContainerUrl;
|
|
46
|
-
ensureContainer(name: string): Promise<void>;
|
|
47
|
-
upload(container: string, name: string, data: Uint8Array, options?: CloudStorageUploadOptions, metadata?: object): Promise<string>;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* @beta
|
|
51
|
-
* @deprecated in 3.x.
|
|
52
|
-
*/
|
|
53
|
-
export declare class CloudStorageTileUploader {
|
|
54
|
-
private _activeUploads;
|
|
55
|
-
get activeUploads(): Iterable<Promise<void>>;
|
|
56
|
-
private uploadToCache;
|
|
57
|
-
cacheTile(tokenProps: IModelRpcProps, treeId: string, contentId: string, content: Uint8Array, guid: string | undefined, metadata?: object): Promise<void>;
|
|
58
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
import { CloudStorageContainerDescriptor, CloudStorageContainerUrl, CloudStorageProvider, IModelRpcProps } from "@itwin/core-common";
|
|
4
|
+
/** @beta */
|
|
5
|
+
export interface AzureBlobStorageCredentials {
|
|
6
|
+
account: string;
|
|
7
|
+
accessKey: string;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @beta
|
|
12
|
+
* @deprecated in 3.x. Use [[TileStorage]] instead.
|
|
13
|
+
*/
|
|
14
|
+
export interface CloudStorageUploadOptions {
|
|
15
|
+
type?: string;
|
|
16
|
+
cacheControl?: string;
|
|
17
|
+
contentEncoding?: "gzip";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @beta
|
|
21
|
+
* @deprecated in 3.x. Use [[TileStorage]] instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class CloudStorageService {
|
|
24
|
+
initialize(): void;
|
|
25
|
+
terminate(): void;
|
|
26
|
+
abstract id: CloudStorageProvider;
|
|
27
|
+
abstract obtainContainerUrl(id: CloudStorageContainerDescriptor, expiry: Date, clientIp?: string): CloudStorageContainerUrl;
|
|
28
|
+
abstract upload(container: string, name: string, data: Uint8Array, options?: CloudStorageUploadOptions, metadata?: object): Promise<string>;
|
|
29
|
+
download(_name: string): Promise<Readable | undefined>;
|
|
30
|
+
protected makeDescriptor(id: CloudStorageContainerDescriptor): {
|
|
31
|
+
name: string;
|
|
32
|
+
provider: CloudStorageProvider;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @beta
|
|
37
|
+
* @deprecated in 3.x. Use `@itwin/object-storage-oss` instead, see https://github.com/iTwin/object-storage for more details.
|
|
38
|
+
*/
|
|
39
|
+
export declare class AzureBlobStorage extends CloudStorageService {
|
|
40
|
+
private _service;
|
|
41
|
+
private _credential;
|
|
42
|
+
private _baseUrl;
|
|
43
|
+
constructor(credentials: AzureBlobStorageCredentials);
|
|
44
|
+
readonly id = CloudStorageProvider.Azure;
|
|
45
|
+
obtainContainerUrl(id: CloudStorageContainerDescriptor, expiry: Date, clientIp?: string): CloudStorageContainerUrl;
|
|
46
|
+
ensureContainer(name: string): Promise<void>;
|
|
47
|
+
upload(container: string, name: string, data: Uint8Array, options?: CloudStorageUploadOptions, metadata?: object): Promise<string>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @beta
|
|
51
|
+
* @deprecated in 3.x. Use [[TileStorage]] instead.
|
|
52
|
+
*/
|
|
53
|
+
export declare class CloudStorageTileUploader {
|
|
54
|
+
private _activeUploads;
|
|
55
|
+
get activeUploads(): Iterable<Promise<void>>;
|
|
56
|
+
private uploadToCache;
|
|
57
|
+
cacheTile(tokenProps: IModelRpcProps, treeId: string, contentId: string, content: Uint8Array, guid: string | undefined, metadata?: object): Promise<void>;
|
|
58
|
+
}
|
|
59
59
|
//# sourceMappingURL=CloudStorageBackend.d.ts.map
|