@itwin/core-backend 4.0.0-dev.52 → 4.0.0-dev.55
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.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js +41 -41
- package/lib/cjs/BackendLoggerCategory.d.ts +90 -91
- package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/BackendLoggerCategory.js +98 -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/BriefcaseManager.d.ts +170 -170
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +408 -408
- 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 +444 -444
- 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/ChangedElementsManager.d.ts +39 -39
- package/lib/cjs/ChangedElementsManager.js +88 -88
- package/lib/cjs/ChannelControl.d.ts +69 -69
- package/lib/cjs/ChannelControl.d.ts.map +1 -1
- package/lib/cjs/ChannelControl.js +88 -88
- package/lib/cjs/ChannelControl.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts +121 -121
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +351 -351
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts +79 -79
- package/lib/cjs/ClassRegistry.js +249 -244
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +355 -355
- package/lib/cjs/CloudSqlite.js +154 -154
- package/lib/cjs/CloudStorageBackend.d.ts +58 -58
- package/lib/cjs/CloudStorageBackend.js +170 -170
- package/lib/cjs/CodeService.d.ts +396 -396
- package/lib/cjs/CodeService.js +63 -63
- package/lib/cjs/CodeSpecs.d.ts +55 -55
- package/lib/cjs/CodeSpecs.js +124 -124
- package/lib/cjs/ConcurrentQuery.d.ts +13 -13
- package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
- package/lib/cjs/ConcurrentQuery.js +36 -36
- package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
- package/lib/cjs/CustomViewState3dCreator.js +82 -82
- package/lib/cjs/DevTools.d.ts +74 -73
- package/lib/cjs/DevTools.d.ts.map +1 -1
- package/lib/cjs/DevTools.js +156 -156
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +106 -106
- package/lib/cjs/DisplayStyle.js +253 -253
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +194 -194
- package/lib/cjs/ECDb.js +353 -353
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
- package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.js +41 -41
- package/lib/cjs/ECSqlStatement.d.ts +473 -473
- package/lib/cjs/ECSqlStatement.js +791 -791
- package/lib/cjs/Element.d.ts +1113 -1113
- package/lib/cjs/Element.js +1424 -1424
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +176 -176
- package/lib/cjs/ElementAspect.js +203 -203
- 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.d.ts.map +1 -1
- package/lib/cjs/ElementTreeWalker.js +409 -409
- package/lib/cjs/Entity.d.ts +106 -106
- package/lib/cjs/Entity.d.ts.map +1 -1
- 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.d.ts.map +1 -1
- package/lib/cjs/EntityReferences.js +95 -95
- package/lib/cjs/ExportGraphics.d.ts +317 -317
- package/lib/cjs/ExportGraphics.d.ts.map +1 -1
- package/lib/cjs/ExportGraphics.js +208 -208
- 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 +333 -333
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/HubMock.d.ts +94 -94
- package/lib/cjs/HubMock.js +220 -220
- package/lib/cjs/HubMock.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +8 -8
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +15 -15
- package/lib/cjs/IModelDb.d.ts +1216 -1216
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +2387 -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/IModelHost.d.ts +369 -369
- package/lib/cjs/IModelHost.js +488 -488
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IModelJsFs.d.ts +62 -62
- package/lib/cjs/IModelJsFs.js +139 -139
- package/lib/cjs/IpcHost.d.ts +104 -104
- package/lib/cjs/IpcHost.js +276 -276
- 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/LocalHub.d.ts +162 -162
- package/lib/cjs/LocalHub.d.ts.map +1 -1
- package/lib/cjs/LocalHub.js +579 -579
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
- package/lib/cjs/LocalhostIpcHost.js +79 -79
- package/lib/cjs/LocalhostIpcHost.js.map +1 -1
- package/lib/cjs/Material.d.ts +131 -131
- package/lib/cjs/Material.js +180 -180
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +392 -392
- package/lib/cjs/Model.js +489 -489
- 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 +160 -160
- 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.d.ts.map +1 -1
- 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/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/SQLiteDb.d.ts +219 -219
- package/lib/cjs/SQLiteDb.js +212 -212
- 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.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js +586 -586
- 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 +87 -87
- package/lib/cjs/TxnManager.d.ts +202 -202
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +356 -356
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +435 -435
- 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/core-backend.d.ts +185 -185
- package/lib/cjs/core-backend.js +209 -205
- 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 +39 -39
- package/lib/cjs/domains/GenericElements.d.ts +177 -177
- package/lib/cjs/domains/GenericElements.js +263 -263
- package/lib/cjs/domains/GenericSchema.d.ts +10 -10
- package/lib/cjs/domains/GenericSchema.js +28 -28
- package/lib/cjs/rpc/multipart.d.ts +11 -11
- package/lib/cjs/rpc/multipart.js +71 -71
- package/lib/cjs/rpc/tracing.d.ts +28 -28
- package/lib/cjs/rpc/tracing.js +73 -73
- 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/request.d.ts +6 -6
- package/lib/cjs/rpc/web/request.js +73 -73
- package/lib/cjs/rpc/web/response.d.ts +6 -6
- package/lib/cjs/rpc/web/response.js +105 -105
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -293
- 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 +202 -202
- 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 +166 -166
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -42
- package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
- package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
- package/lib/cjs/workspace/Settings.d.ts +186 -186
- package/lib/cjs/workspace/Settings.d.ts.map +1 -1
- package/lib/cjs/workspace/Settings.js +154 -154
- package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
- package/lib/cjs/workspace/SettingsSchemas.js +190 -190
- package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +414 -414
- package/lib/cjs/workspace/Workspace.js +537 -537
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +12 -12
package/lib/cjs/CloudSqlite.js
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
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?.(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
|
-
* @throws if [[container]] is not connected to a CloudCache.
|
|
108
|
-
*/
|
|
109
|
-
async function acquireWriteLock(user, container, busyHandler) {
|
|
110
|
-
if (container.hasWriteLock)
|
|
111
|
-
return;
|
|
112
|
-
while (true) {
|
|
113
|
-
try {
|
|
114
|
-
return container.acquireWriteLock(user);
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
if (e.errorNumber === 5 && busyHandler && "stop" !== await busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY
|
|
118
|
-
continue; // busy handler wants to try again
|
|
119
|
-
throw e;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
CloudSqlite.acquireWriteLock = acquireWriteLock;
|
|
124
|
-
/**
|
|
125
|
-
* Perform an asynchronous write operation on a CloudContainer with the write lock held.
|
|
126
|
-
* 1. if write lock is already held, call operation and return.
|
|
127
|
-
* 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
|
|
128
|
-
* 3. perform the operation
|
|
129
|
-
* 3.a if the operation throws, abandon all changes and re-throw
|
|
130
|
-
* 4. release the write lock.
|
|
131
|
-
* 5. return value from operation
|
|
132
|
-
* @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
|
|
133
|
-
* @param container the CloudContainer for which the lock is to be acquired
|
|
134
|
-
* @param operation an asynchronous operation performed with the write lock held.
|
|
135
|
-
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
136
|
-
* @returns a Promise with the result of `operation`
|
|
137
|
-
*/
|
|
138
|
-
async function withWriteLock(user, container, operation, busyHandler) {
|
|
139
|
-
if (container.hasWriteLock)
|
|
140
|
-
return operation();
|
|
141
|
-
await acquireWriteLock(user, container, busyHandler);
|
|
142
|
-
try {
|
|
143
|
-
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
144
|
-
const val = await operation(); // wait for work to finish or fail
|
|
145
|
-
container.releaseWriteLock();
|
|
146
|
-
return val;
|
|
147
|
-
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
container.abandonChanges(); // if operation threw, abandon all changes
|
|
150
|
-
throw e;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
CloudSqlite.withWriteLock = withWriteLock;
|
|
154
|
-
})(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?.(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
|
+
* @throws if [[container]] is not connected to a CloudCache.
|
|
108
|
+
*/
|
|
109
|
+
async function acquireWriteLock(user, container, busyHandler) {
|
|
110
|
+
if (container.hasWriteLock)
|
|
111
|
+
return;
|
|
112
|
+
while (true) {
|
|
113
|
+
try {
|
|
114
|
+
return container.acquireWriteLock(user);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
if (e.errorNumber === 5 && busyHandler && "stop" !== await busyHandler(e.lockedBy, e.expires)) // 5 === BE_SQLITE_BUSY
|
|
118
|
+
continue; // busy handler wants to try again
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
CloudSqlite.acquireWriteLock = acquireWriteLock;
|
|
124
|
+
/**
|
|
125
|
+
* Perform an asynchronous write operation on a CloudContainer with the write lock held.
|
|
126
|
+
* 1. if write lock is already held, call operation and return.
|
|
127
|
+
* 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
|
|
128
|
+
* 3. perform the operation
|
|
129
|
+
* 3.a if the operation throws, abandon all changes and re-throw
|
|
130
|
+
* 4. release the write lock.
|
|
131
|
+
* 5. return value from operation
|
|
132
|
+
* @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
|
|
133
|
+
* @param container the CloudContainer for which the lock is to be acquired
|
|
134
|
+
* @param operation an asynchronous operation performed with the write lock held.
|
|
135
|
+
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
136
|
+
* @returns a Promise with the result of `operation`
|
|
137
|
+
*/
|
|
138
|
+
async function withWriteLock(user, container, operation, busyHandler) {
|
|
139
|
+
if (container.hasWriteLock)
|
|
140
|
+
return operation();
|
|
141
|
+
await acquireWriteLock(user, container, busyHandler);
|
|
142
|
+
try {
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
144
|
+
const val = await operation(); // wait for work to finish or fail
|
|
145
|
+
container.releaseWriteLock();
|
|
146
|
+
return val;
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
container.abandonChanges(); // if operation threw, abandon all changes
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
CloudSqlite.withWriteLock = withWriteLock;
|
|
154
|
+
})(CloudSqlite = exports.CloudSqlite || (exports.CloudSqlite = {}));
|
|
155
155
|
//# sourceMappingURL=CloudSqlite.js.map
|
|
@@ -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. 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
|
-
}
|
|
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
|