@itwin/core-backend 4.8.0-dev.3 → 4.8.0-dev.32
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/CHANGELOG.md +57 -1
- package/lib/cjs/BackendHubAccess.d.ts +18 -16
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js +16 -15
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BackendLoggerCategory.d.ts +3 -1
- package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/BackendLoggerCategory.js +2 -0
- package/lib/cjs/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/BlobContainerService.d.ts +3 -3
- package/lib/cjs/BlobContainerService.d.ts.map +1 -1
- package/lib/cjs/BlobContainerService.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +19 -11
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/Category.d.ts +0 -6
- package/lib/cjs/Category.d.ts.map +1 -1
- package/lib/cjs/Category.js +0 -6
- package/lib/cjs/Category.js.map +1 -1
- package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
- package/lib/cjs/ChangeSummaryManager.js +11 -9
- package/lib/cjs/ChangeSummaryManager.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +1 -0
- package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
- package/lib/cjs/ChangedElementsDb.js +6 -4
- package/lib/cjs/ChangedElementsDb.js.map +1 -1
- package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
- package/lib/cjs/ChangesetECAdaptor.js +26 -21
- package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
- package/lib/cjs/ChannelControl.d.ts +4 -26
- package/lib/cjs/ChannelControl.d.ts.map +1 -1
- package/lib/cjs/ChannelControl.js +2 -101
- package/lib/cjs/ChannelControl.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +5 -3
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts.map +1 -1
- package/lib/cjs/ClassRegistry.js +3 -2
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +49 -24
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +66 -7
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/CodeService.d.ts +4 -4
- package/lib/cjs/CodeService.d.ts.map +1 -1
- package/lib/cjs/CodeService.js.map +1 -1
- package/lib/cjs/DevTools.d.ts.map +1 -1
- package/lib/cjs/DevTools.js +2 -1
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +0 -3
- package/lib/cjs/DisplayStyle.d.ts.map +1 -1
- package/lib/cjs/DisplayStyle.js +0 -3
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +6 -1
- package/lib/cjs/ECDb.d.ts.map +1 -1
- package/lib/cjs/ECDb.js +19 -14
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.js +2 -2
- package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
- package/lib/cjs/ECSqlStatement.d.ts +6 -3
- package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
- package/lib/cjs/ECSqlStatement.js +3 -3
- package/lib/cjs/ECSqlStatement.js.map +1 -1
- package/lib/cjs/Element.d.ts +3 -60
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +8 -64
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +0 -5
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +4 -8
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/ElementGraphics.d.ts.map +1 -1
- package/lib/cjs/ElementGraphics.js +2 -1
- package/lib/cjs/ElementGraphics.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts +10 -0
- package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
- package/lib/cjs/GeoCoordConfig.js +22 -24
- package/lib/cjs/GeoCoordConfig.js.map +1 -1
- package/lib/cjs/GeographicCRSServices.js +2 -2
- package/lib/cjs/GeographicCRSServices.js.map +1 -1
- package/lib/cjs/GeometrySummary.d.ts.map +1 -1
- package/lib/cjs/GeometrySummary.js +2 -1
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +33 -98
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +242 -156
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelElementCloneContext.js +5 -4
- package/lib/cjs/IModelElementCloneContext.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +13 -4
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +39 -32
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts.map +1 -1
- package/lib/cjs/IpcHost.js +15 -13
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LocalHub.d.ts +2 -2
- package/lib/cjs/LocalHub.d.ts.map +1 -1
- package/lib/cjs/LocalHub.js +17 -17
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/LockControl.d.ts +73 -0
- package/lib/cjs/LockControl.d.ts.map +1 -0
- package/lib/cjs/LockControl.js +11 -0
- package/lib/cjs/LockControl.js.map +1 -0
- package/lib/cjs/Material.d.ts +2 -5
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +6 -4
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +0 -22
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +5 -26
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/PropertyStore.d.ts +17 -7
- package/lib/cjs/PropertyStore.d.ts.map +1 -1
- package/lib/cjs/PropertyStore.js +11 -5
- package/lib/cjs/PropertyStore.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +0 -12
- package/lib/cjs/Relationship.d.ts.map +1 -1
- package/lib/cjs/Relationship.js +5 -16
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/SQLiteDb.d.ts +8 -4
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +25 -19
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/SchemaSync.d.ts +4 -1
- package/lib/cjs/SchemaSync.d.ts.map +1 -1
- package/lib/cjs/SchemaSync.js +24 -11
- package/lib/cjs/SchemaSync.js.map +1 -1
- package/lib/cjs/SchemaUtils.js +3 -3
- package/lib/cjs/SchemaUtils.js.map +1 -1
- package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
- package/lib/cjs/SqliteChangesetReader.js +2 -2
- package/lib/cjs/SqliteChangesetReader.js.map +1 -1
- package/lib/cjs/SqliteStatement.js +2 -2
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/TextAnnotationGeometry.d.ts +5 -1
- package/lib/cjs/TextAnnotationGeometry.d.ts.map +1 -1
- package/lib/cjs/TextAnnotationGeometry.js +11 -8
- package/lib/cjs/TextAnnotationGeometry.js.map +1 -1
- package/lib/cjs/TextAnnotationLayout.d.ts +21 -13
- package/lib/cjs/TextAnnotationLayout.d.ts.map +1 -1
- package/lib/cjs/TextAnnotationLayout.js +134 -92
- package/lib/cjs/TextAnnotationLayout.js.map +1 -1
- package/lib/cjs/TxnManager.d.ts +2 -1
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +4 -2
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +1 -18
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +1 -18
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/ViewStore.d.ts +16 -2
- package/lib/cjs/ViewStore.d.ts.map +1 -1
- package/lib/cjs/ViewStore.js +20 -6
- package/lib/cjs/ViewStore.js.map +1 -1
- package/lib/cjs/assets/Settings/Schemas/Base.Schema.json +33 -0
- package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +17 -21
- package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +80 -38
- package/lib/cjs/assets/Settings/backend.setting.json5 +8 -119
- package/lib/cjs/core-backend.d.ts +4 -2
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +5 -6
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts +0 -10
- package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalElements.js +0 -10
- package/lib/cjs/domains/FunctionalElements.js.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.js +2 -1
- package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
- package/lib/cjs/domains/GenericElements.d.ts +0 -18
- package/lib/cjs/domains/GenericElements.d.ts.map +1 -1
- package/lib/cjs/domains/GenericElements.js +0 -18
- package/lib/cjs/domains/GenericElements.js.map +1 -1
- package/lib/cjs/internal/ChangesetConflictArgs.d.ts +24 -0
- package/lib/cjs/internal/ChangesetConflictArgs.d.ts.map +1 -0
- package/lib/cjs/internal/ChangesetConflictArgs.js +7 -0
- package/lib/cjs/internal/ChangesetConflictArgs.js.map +1 -0
- package/lib/cjs/internal/ChannelAdmin.d.ts +34 -0
- package/lib/cjs/internal/ChannelAdmin.d.ts.map +1 -0
- package/lib/cjs/internal/ChannelAdmin.js +117 -0
- package/lib/cjs/internal/ChannelAdmin.js.map +1 -0
- package/lib/cjs/internal/NativePlatform.d.ts +15 -0
- package/lib/cjs/internal/NativePlatform.d.ts.map +1 -0
- package/lib/cjs/internal/NativePlatform.js +49 -0
- package/lib/cjs/internal/NativePlatform.js.map +1 -0
- package/lib/cjs/internal/NoLocks.d.ts +6 -0
- package/lib/cjs/internal/NoLocks.d.ts.map +1 -0
- package/lib/cjs/internal/NoLocks.js +31 -0
- package/lib/cjs/internal/NoLocks.js.map +1 -0
- package/lib/cjs/{ServerBasedLocks.d.ts → internal/ServerBasedLocks.d.ts} +10 -16
- package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -0
- package/lib/cjs/{ServerBasedLocks.js → internal/ServerBasedLocks.js} +29 -18
- package/lib/cjs/internal/ServerBasedLocks.js.map +1 -0
- package/lib/cjs/internal/Symbols.d.ts +11 -0
- package/lib/cjs/internal/Symbols.d.ts.map +1 -0
- package/lib/cjs/internal/Symbols.js +21 -0
- package/lib/cjs/internal/Symbols.js.map +1 -0
- package/lib/cjs/internal/cross-package.d.ts +4 -0
- package/lib/cjs/internal/cross-package.d.ts.map +1 -0
- package/lib/cjs/internal/cross-package.js +16 -0
- package/lib/cjs/internal/cross-package.js.map +1 -0
- package/lib/cjs/internal/workspace/SettingsImpl.d.ts +43 -0
- package/lib/cjs/internal/workspace/SettingsImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/SettingsImpl.js +161 -0
- package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts +6 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +276 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts +41 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.js +696 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts +10 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js +42 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js.map +1 -0
- package/lib/cjs/rpc/tracing.d.ts.map +1 -1
- package/lib/cjs/rpc/tracing.js +5 -2
- package/lib/cjs/rpc/tracing.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +1 -0
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +10 -6
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +5 -3
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/workspace/Settings.d.ts +167 -138
- package/lib/cjs/workspace/Settings.d.ts.map +1 -1
- package/lib/cjs/workspace/Settings.js +68 -138
- package/lib/cjs/workspace/Settings.js.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.d.ts +112 -48
- package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.js +1 -172
- package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +411 -277
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +76 -457
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/lib/cjs/workspace/WorkspaceEditor.d.ts +245 -0
- package/lib/cjs/workspace/WorkspaceEditor.d.ts.map +1 -0
- package/lib/cjs/workspace/WorkspaceEditor.js +34 -0
- package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -0
- package/package.json +15 -14
- package/lib/cjs/ServerBasedLocks.d.ts.map +0 -1
- package/lib/cjs/ServerBasedLocks.js.map +0 -1
- package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +0 -45
|
@@ -0,0 +1,117 @@
|
|
|
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 Elements
|
|
8
|
+
*/
|
|
9
|
+
var _a;
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createChannelControl = void 0;
|
|
12
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
13
|
+
const core_common_1 = require("@itwin/core-common");
|
|
14
|
+
const Element_1 = require("../Element");
|
|
15
|
+
const IModelHost_1 = require("../IModelHost");
|
|
16
|
+
const ChannelControl_1 = require("../ChannelControl");
|
|
17
|
+
const Symbols_1 = require("./Symbols");
|
|
18
|
+
class ChannelAdmin {
|
|
19
|
+
constructor(_iModel) {
|
|
20
|
+
this._iModel = _iModel;
|
|
21
|
+
this[_a] = undefined;
|
|
22
|
+
this._allowedChannels = new Set();
|
|
23
|
+
this._allowedModels = new Set();
|
|
24
|
+
this._deniedModels = new Map();
|
|
25
|
+
// for backwards compatibility, allow the shared channel unless explicitly turned off in IModelHostOptions.
|
|
26
|
+
if (IModelHost_1.IModelHost.configuration?.allowSharedChannel !== false)
|
|
27
|
+
this._allowedChannels.add(ChannelControl_1.ChannelControl.sharedChannelName);
|
|
28
|
+
}
|
|
29
|
+
addAllowedChannel(channelKey) {
|
|
30
|
+
this._allowedChannels.add(channelKey);
|
|
31
|
+
this._deniedModels.clear();
|
|
32
|
+
}
|
|
33
|
+
removeAllowedChannel(channelKey) {
|
|
34
|
+
this._allowedChannels.delete(channelKey);
|
|
35
|
+
this._allowedModels.clear();
|
|
36
|
+
}
|
|
37
|
+
getChannelKey(elementId) {
|
|
38
|
+
if (elementId === core_common_1.IModel.rootSubjectId)
|
|
39
|
+
return ChannelControl_1.ChannelControl.sharedChannelName;
|
|
40
|
+
try {
|
|
41
|
+
const channel = this._iModel.withPreparedStatement(`SELECT Owner FROM ${ChannelAdmin.channelClassName} WHERE Element.Id=?`, (stmt) => {
|
|
42
|
+
stmt.bindId(1, elementId);
|
|
43
|
+
return core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getString() : undefined;
|
|
44
|
+
});
|
|
45
|
+
if (channel !== undefined)
|
|
46
|
+
return channel;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Exception happens if the iModel is too old: ChannelRootAspect class not present in the BisCore schema (older than v1.0.10).
|
|
50
|
+
// In that case all data in such iModel is assumed to be in the shared channel.
|
|
51
|
+
return ChannelControl_1.ChannelControl.sharedChannelName;
|
|
52
|
+
}
|
|
53
|
+
const parentId = this._iModel.withPreparedSqliteStatement("SELECT ParentId,ModelId FROM bis_Element WHERE id=?", (stmt) => {
|
|
54
|
+
stmt.bindId(1, elementId);
|
|
55
|
+
if (core_bentley_1.DbResult.BE_SQLITE_ROW !== stmt.step())
|
|
56
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, "Element does not exist");
|
|
57
|
+
return stmt.getValueId(0) ?? stmt.getValueId(1); // if parent is undefined, use modelId
|
|
58
|
+
});
|
|
59
|
+
return this.getChannelKey(parentId);
|
|
60
|
+
}
|
|
61
|
+
[(_a = Symbols_1._implementationProhibited, Symbols_1._verifyChannel)](modelId) {
|
|
62
|
+
// Note: indirect changes are permitted to change any channel
|
|
63
|
+
if (this._allowedModels.has(modelId) || this._iModel[Symbols_1._nativeDb].isIndirectChanges())
|
|
64
|
+
return;
|
|
65
|
+
const deniedChannel = this._deniedModels.get(modelId);
|
|
66
|
+
if (undefined !== deniedChannel)
|
|
67
|
+
throw new Error(`channel "${deniedChannel}" is not allowed`);
|
|
68
|
+
const channel = this.getChannelKey(modelId);
|
|
69
|
+
if (this._allowedChannels.has(channel)) {
|
|
70
|
+
this._allowedModels.add(modelId);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this._deniedModels.set(modelId, channel);
|
|
74
|
+
return this[Symbols_1._verifyChannel](modelId);
|
|
75
|
+
}
|
|
76
|
+
makeChannelRoot(args) {
|
|
77
|
+
if (ChannelControl_1.ChannelControl.sharedChannelName !== this.getChannelKey(args.elementId))
|
|
78
|
+
throw new Error("channels may not nest");
|
|
79
|
+
if (this.queryChannelRoot(args.channelKey) !== undefined)
|
|
80
|
+
throw new Error("a channel root for the specified key already exists");
|
|
81
|
+
const props = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };
|
|
82
|
+
this._iModel.elements.insertAspect(props);
|
|
83
|
+
}
|
|
84
|
+
insertChannelSubject(args) {
|
|
85
|
+
// Check if channelKey already exists before inserting Subject.
|
|
86
|
+
// makeChannelRoot will check that again, but at that point the new Subject is already inserted.
|
|
87
|
+
// Prefer to check twice instead of deleting the Subject in the latter option.
|
|
88
|
+
if (this.queryChannelRoot(args.channelKey) !== undefined)
|
|
89
|
+
throw new Error("a channel root for the specified key already exists");
|
|
90
|
+
const elementId = Element_1.Subject.insert(this._iModel, args.parentSubjectId ?? core_common_1.IModel.rootSubjectId, args.subjectName, args.description);
|
|
91
|
+
this.makeChannelRoot({ elementId, channelKey: args.channelKey });
|
|
92
|
+
return elementId;
|
|
93
|
+
}
|
|
94
|
+
queryChannelRoot(channelKey) {
|
|
95
|
+
if (channelKey === ChannelControl_1.ChannelControl.sharedChannelName)
|
|
96
|
+
// RootSubject acts as the ChannelRoot element of the shared channel
|
|
97
|
+
return core_common_1.IModel.rootSubjectId;
|
|
98
|
+
try {
|
|
99
|
+
const channelRoot = this._iModel.withPreparedStatement(`SELECT Element.Id FROM ${ChannelAdmin.channelClassName} WHERE Owner=?`, (stmt) => {
|
|
100
|
+
stmt.bindString(1, channelKey);
|
|
101
|
+
return core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getId() : undefined;
|
|
102
|
+
});
|
|
103
|
+
return channelRoot;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// Exception happens if the iModel is too old: ChannelRootAspect class not present in the BisCore schema (older than v1.0.10).
|
|
107
|
+
// In that case all data in such iModel is assumed to be in the shared channel.
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
ChannelAdmin.channelClassName = "bis:ChannelRootAspect";
|
|
113
|
+
function createChannelControl(iModel) {
|
|
114
|
+
return new ChannelAdmin(iModel);
|
|
115
|
+
}
|
|
116
|
+
exports.createChannelControl = createChannelControl;
|
|
117
|
+
//# sourceMappingURL=ChannelAdmin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChannelAdmin.js","sourceRoot":"","sources":["../../../src/internal/ChannelAdmin.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,sDAAyE;AACzE,oDAAiF;AACjF,wCAAqC;AAErC,8CAA2C;AAC3C,sDAA+D;AAC/D,uCAAiF;AAEjF,MAAM,YAAY;IAQhB,YAA2B,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;QAL5B,QAA2B,GAAG,SAAS,CAAC;QAChD,qBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;QACzC,mBAAc,GAAG,IAAI,GAAG,EAAc,CAAC;QACvC,kBAAa,GAAG,IAAI,GAAG,EAA0B,CAAC;QAGxD,2GAA2G;QAC3G,IAAI,uBAAU,CAAC,aAAa,EAAE,kBAAkB,KAAK,KAAK;YACxD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,+BAAc,CAAC,iBAAiB,CAAC,CAAC;IAChE,CAAC;IAEM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,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YACvF,CAAC,CAAC,CAAC;YAEH,OAAO,WAAW,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,8HAA8H;YAC9H,+EAA+E;YAC/E,OAAO,SAAS,CAAC;QACnB,CAAC;IAEH,CAAC;;AA/GsB,6BAAgB,GAAG,uBAAuB,AAA1B,CAA2B;AAkHpE,SAAgB,oBAAoB,CAAC,MAAgB;IACnD,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAFD,oDAEC","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 Elements\r\n */\r\n\r\nimport { DbResult, Id64String, IModelStatus } from \"@itwin/core-bentley\";\r\nimport { ChannelRootAspectProps, IModel, IModelError } from \"@itwin/core-common\";\r\nimport { Subject } from \"../Element\";\r\nimport { IModelDb } from \"../IModelDb\";\r\nimport { IModelHost } from \"../IModelHost\";\r\nimport { ChannelControl, ChannelKey } from \"../ChannelControl\";\r\nimport { _implementationProhibited, _nativeDb, _verifyChannel } from \"./Symbols\";\r\n\r\nclass ChannelAdmin implements ChannelControl {\r\n public static readonly channelClassName = \"bis:ChannelRootAspect\";\r\n\r\n public readonly [_implementationProhibited] = undefined;\r\n private _allowedChannels = new Set<ChannelKey>();\r\n private _allowedModels = new Set<Id64String>();\r\n private _deniedModels = new Map<Id64String, ChannelKey>();\r\n\r\n public constructor(private _iModel: IModelDb) {\r\n // for backwards compatibility, allow the shared channel unless explicitly turned off in IModelHostOptions.\r\n if (IModelHost.configuration?.allowSharedChannel !== false)\r\n this._allowedChannels.add(ChannelControl.sharedChannelName);\r\n }\r\n\r\n public addAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.add(channelKey);\r\n this._deniedModels.clear();\r\n }\r\n\r\n public removeAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.delete(channelKey);\r\n this._allowedModels.clear();\r\n }\r\n\r\n public getChannelKey(elementId: Id64String): ChannelKey {\r\n if (elementId === IModel.rootSubjectId)\r\n return ChannelControl.sharedChannelName;\r\n\r\n try {\r\n const channel = this._iModel.withPreparedStatement(`SELECT Owner FROM ${ChannelAdmin.channelClassName} WHERE Element.Id=?`, (stmt) => {\r\n stmt.bindId(1, elementId);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getString() : undefined;\r\n });\r\n\r\n if (channel !== undefined)\r\n return channel;\r\n } catch {\r\n // Exception happens if the iModel is too old: ChannelRootAspect class not present in the BisCore schema (older than v1.0.10).\r\n // In that case all data in such iModel is assumed to be in the shared channel.\r\n return ChannelControl.sharedChannelName;\r\n }\r\n\r\n const parentId = this._iModel.withPreparedSqliteStatement(\"SELECT ParentId,ModelId FROM bis_Element WHERE id=?\", (stmt) => {\r\n stmt.bindId(1, elementId);\r\n if (DbResult.BE_SQLITE_ROW !== stmt.step())\r\n throw new IModelError(IModelStatus.NotFound, \"Element does not exist\");\r\n return stmt.getValueId(0) ?? stmt.getValueId(1); // if parent is undefined, use modelId\r\n });\r\n\r\n return this.getChannelKey(parentId);\r\n }\r\n\r\n public [_verifyChannel](modelId: Id64String): void {\r\n // Note: indirect changes are permitted to change any channel\r\n if (this._allowedModels.has(modelId) || this._iModel[_nativeDb].isIndirectChanges())\r\n return;\r\n\r\n const deniedChannel = this._deniedModels.get(modelId);\r\n if (undefined !== deniedChannel)\r\n throw new Error(`channel \"${deniedChannel}\" is not allowed`);\r\n\r\n const channel = this.getChannelKey(modelId);\r\n if (this._allowedChannels.has(channel)) {\r\n this._allowedModels.add(modelId);\r\n return;\r\n }\r\n\r\n this._deniedModels.set(modelId, channel);\r\n return this[_verifyChannel](modelId);\r\n }\r\n\r\n public makeChannelRoot(args: { elementId: Id64String, channelKey: ChannelKey }) {\r\n if (ChannelControl.sharedChannelName !== this.getChannelKey(args.elementId))\r\n throw new Error(\"channels may not nest\");\r\n\r\n if (this.queryChannelRoot(args.channelKey) !== undefined)\r\n throw new Error(\"a channel root for the specified key already exists\");\r\n\r\n const props: ChannelRootAspectProps = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };\r\n this._iModel.elements.insertAspect(props);\r\n }\r\n\r\n public insertChannelSubject(args: { subjectName: string, channelKey: ChannelKey, parentSubjectId?: Id64String, description?: string }): Id64String {\r\n // Check if channelKey already exists before inserting Subject.\r\n // makeChannelRoot will check that again, but at that point the new Subject is already inserted.\r\n // Prefer to check twice instead of deleting the Subject in the latter option.\r\n if (this.queryChannelRoot(args.channelKey) !== undefined)\r\n throw new Error(\"a channel root for the specified key already exists\");\r\n\r\n const elementId = Subject.insert(this._iModel, args.parentSubjectId ?? IModel.rootSubjectId, args.subjectName, args.description);\r\n this.makeChannelRoot({ elementId, channelKey: args.channelKey });\r\n return elementId;\r\n }\r\n\r\n public queryChannelRoot(channelKey: ChannelKey): Id64String | undefined {\r\n if (channelKey === ChannelControl.sharedChannelName)\r\n // RootSubject acts as the ChannelRoot element of the shared channel\r\n return IModel.rootSubjectId;\r\n\r\n try {\r\n const channelRoot = this._iModel.withPreparedStatement(`SELECT Element.Id FROM ${ChannelAdmin.channelClassName} WHERE Owner=?`, (stmt) => {\r\n stmt.bindString(1, channelKey);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getId() : undefined;\r\n });\r\n\r\n return channelRoot;\r\n } catch {\r\n // Exception happens if the iModel is too old: ChannelRootAspect class not present in the BisCore schema (older than v1.0.10).\r\n // In that case all data in such iModel is assumed to be in the shared channel.\r\n return undefined;\r\n }\r\n\r\n }\r\n}\r\n\r\nexport function createChannelControl(iModel: IModelDb): ChannelAdmin {\r\n return new ChannelAdmin(iModel);\r\n}\r\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module IModelHost
|
|
3
|
+
*/
|
|
4
|
+
import { IModelJsNative } from "@bentley/imodeljs-native";
|
|
5
|
+
/** Provides access to the internal APIs defined in @bentley/imodeljs-native.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class IModelNative {
|
|
9
|
+
static get platform(): typeof IModelJsNative;
|
|
10
|
+
}
|
|
11
|
+
/** @internal Strictly to be called by IModelHost.startup. */
|
|
12
|
+
export declare function loadNativePlatform(): void;
|
|
13
|
+
/** @internal Strictly for tests. */
|
|
14
|
+
export declare function overrideSyncNativeLogLevels(func?: () => void): void;
|
|
15
|
+
//# sourceMappingURL=NativePlatform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativePlatform.d.ts","sourceRoot":"","sources":["../../../src/internal/NativePlatform.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AAezE;;GAEG;AACH,qBAAa,YAAY;IACvB,WAAkB,QAAQ,IAAI,OAAO,cAAc,CAMlD;CACF;AAED,6DAA6D;AAC7D,wBAAgB,kBAAkB,IAAI,IAAI,CAMzC;AAED,oCAAoC;AACpC,wBAAgB,2BAA2B,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAEnE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module IModelHost
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.overrideSyncNativeLogLevels = exports.loadNativePlatform = exports.IModelNative = void 0;
|
|
11
|
+
const imodeljs_native_1 = require("@bentley/imodeljs-native");
|
|
12
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
13
|
+
let nativePlatform;
|
|
14
|
+
let syncNativeLogLevelsOverride;
|
|
15
|
+
function syncNativeLogLevels() {
|
|
16
|
+
if (syncNativeLogLevelsOverride) {
|
|
17
|
+
syncNativeLogLevelsOverride();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
nativePlatform?.clearLogLevelCache();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Provides access to the internal APIs defined in @bentley/imodeljs-native.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
class IModelNative {
|
|
27
|
+
static get platform() {
|
|
28
|
+
if (undefined === nativePlatform) {
|
|
29
|
+
throw new Error("IModelHost.startup must be called first");
|
|
30
|
+
}
|
|
31
|
+
return nativePlatform;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.IModelNative = IModelNative;
|
|
35
|
+
/** @internal Strictly to be called by IModelHost.startup. */
|
|
36
|
+
function loadNativePlatform() {
|
|
37
|
+
if (undefined === nativePlatform) {
|
|
38
|
+
nativePlatform = core_bentley_1.ProcessDetector.isMobileAppBackend ? process._linkedBinding("iModelJsNative") : imodeljs_native_1.NativeLibrary.load();
|
|
39
|
+
nativePlatform.logger = core_bentley_1.Logger;
|
|
40
|
+
core_bentley_1.Logger.onLogLevelChanged.addListener(() => syncNativeLogLevels());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.loadNativePlatform = loadNativePlatform;
|
|
44
|
+
/** @internal Strictly for tests. */
|
|
45
|
+
function overrideSyncNativeLogLevels(func) {
|
|
46
|
+
syncNativeLogLevelsOverride = func;
|
|
47
|
+
}
|
|
48
|
+
exports.overrideSyncNativeLogLevels = overrideSyncNativeLogLevels;
|
|
49
|
+
//# sourceMappingURL=NativePlatform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativePlatform.js","sourceRoot":"","sources":["../../../src/internal/NativePlatform.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,8DAAyE;AACzE,sDAA8D;AAE9D,IAAI,cAAiD,CAAC;AAEtD,IAAI,2BAAqD,CAAC;AAE1D,SAAS,mBAAmB;IAC1B,IAAI,2BAA2B,EAAE,CAAC;QAChC,2BAA2B,EAAE,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,cAAc,EAAE,kBAAkB,EAAE,CAAC;IACvC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAa,YAAY;IAChB,MAAM,KAAK,QAAQ;QACxB,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AARD,oCAQC;AAED,6DAA6D;AAC7D,SAAgB,kBAAkB;IAChC,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;QACjC,cAAc,GAAG,8BAAe,CAAC,kBAAkB,CAAC,CAAC,CAAE,OAAe,CAAC,cAAc,CAAC,gBAAgB,CAA0B,CAAC,CAAC,CAAC,+BAAa,CAAC,IAAI,EAAE,CAAC;QACxJ,cAAc,CAAC,MAAM,GAAG,qBAAM,CAAC;QAC/B,qBAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,mBAAmB,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAND,gDAMC;AAED,oCAAoC;AACpC,SAAgB,2BAA2B,CAAC,IAAiB;IAC3D,2BAA2B,GAAG,IAAI,CAAC;AACrC,CAAC;AAFD,kEAEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module IModelHost\r\n */\r\n\r\nimport { IModelJsNative, NativeLibrary } from \"@bentley/imodeljs-native\";\r\nimport { Logger, ProcessDetector } from \"@itwin/core-bentley\";\r\n\r\nlet nativePlatform: typeof IModelJsNative | undefined;\r\n\r\nlet syncNativeLogLevelsOverride: (() => void) | undefined;\r\n\r\nfunction syncNativeLogLevels() {\r\n if (syncNativeLogLevelsOverride) {\r\n syncNativeLogLevelsOverride();\r\n } else {\r\n nativePlatform?.clearLogLevelCache();\r\n }\r\n}\r\n\r\n/** Provides access to the internal APIs defined in @bentley/imodeljs-native.\r\n * @internal\r\n */\r\nexport class IModelNative {\r\n public static get platform(): typeof IModelJsNative {\r\n if (undefined === nativePlatform) {\r\n throw new Error(\"IModelHost.startup must be called first\");\r\n }\r\n\r\n return nativePlatform;\r\n }\r\n}\r\n\r\n/** @internal Strictly to be called by IModelHost.startup. */\r\nexport function loadNativePlatform(): void {\r\n if (undefined === nativePlatform) {\r\n nativePlatform = ProcessDetector.isMobileAppBackend ? (process as any)._linkedBinding(\"iModelJsNative\") as typeof IModelJsNative : NativeLibrary.load();\r\n nativePlatform.logger = Logger;\r\n Logger.onLogLevelChanged.addListener(() => syncNativeLogLevels());\r\n }\r\n}\r\n\r\n/** @internal Strictly for tests. */\r\nexport function overrideSyncNativeLogLevels(func?: () => void): void {\r\n syncNativeLogLevelsOverride = func;\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoLocks.d.ts","sourceRoot":"","sources":["../../../src/internal/NoLocks.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAmB7C,wBAAgB,qBAAqB,IAAI,WAAW,CAEnD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
var _a;
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createNoOpLockControl = void 0;
|
|
9
|
+
const Symbols_1 = require("./Symbols");
|
|
10
|
+
/** A null-implementation of LockControl that does not attempt to limit access between briefcases. This relies on change-merging to resolve conflicts. */
|
|
11
|
+
class NoLocks {
|
|
12
|
+
constructor() {
|
|
13
|
+
this[_a] = undefined;
|
|
14
|
+
}
|
|
15
|
+
get isServerBased() { return false; }
|
|
16
|
+
[(_a = Symbols_1._implementationProhibited, Symbols_1._close)]() { }
|
|
17
|
+
clearAllLocks() { }
|
|
18
|
+
holdsExclusiveLock() { return false; }
|
|
19
|
+
holdsSharedLock() { return false; }
|
|
20
|
+
checkExclusiveLock() { }
|
|
21
|
+
checkSharedLock() { }
|
|
22
|
+
[Symbols_1._elementWasCreated]() { }
|
|
23
|
+
async acquireLocks() { }
|
|
24
|
+
async [Symbols_1._releaseAllLocks]() { }
|
|
25
|
+
async releaseAllLocks() { }
|
|
26
|
+
}
|
|
27
|
+
function createNoOpLockControl() {
|
|
28
|
+
return new NoLocks();
|
|
29
|
+
}
|
|
30
|
+
exports.createNoOpLockControl = createNoOpLockControl;
|
|
31
|
+
//# sourceMappingURL=NoLocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoLocks.js","sourceRoot":"","sources":["../../../src/internal/NoLocks.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;AAO/F,uCAAoG;AAEpG,yJAAyJ;AACzJ,MAAM,OAAO;IAAb;QACkB,QAA2B,GAAG,SAAS,CAAC;IAY1D,CAAC;IAXC,IAAW,aAAa,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC;IACrC,OAFU,mCAAyB,EAElC,gBAAM,EAAC,KAAW,CAAC;IACpB,aAAa,KAAW,CAAC;IACzB,kBAAkB,KAAc,OAAO,KAAK,CAAC,CAAC,CAAC;IAC/C,eAAe,KAAc,OAAO,KAAK,CAAC,CAAC,CAAC;IAC5C,kBAAkB,KAAW,CAAC;IAC9B,eAAe,KAAW,CAAC;IAC3B,CAAC,4BAAkB,CAAC,KAAW,CAAC;IAChC,KAAK,CAAC,YAAY,KAAK,CAAC;IACxB,KAAK,CAAC,CAAC,0BAAgB,CAAC,KAAoB,CAAC;IAC7C,KAAK,CAAC,eAAe,KAAoB,CAAC;CAClD;AAED,SAAgB,qBAAqB;IACnC,OAAO,IAAI,OAAO,EAAE,CAAC;AACvB,CAAC;AAFD,sDAEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\nimport { LockControl } from \"../LockControl\";\r\nimport { _close, _elementWasCreated, _implementationProhibited, _releaseAllLocks } from \"./Symbols\";\r\n\r\n/** A null-implementation of LockControl that does not attempt to limit access between briefcases. This relies on change-merging to resolve conflicts. */\r\nclass NoLocks implements LockControl {\r\n public readonly [_implementationProhibited] = undefined;\r\n public get isServerBased() { return false; }\r\n public [_close](): void { }\r\n public clearAllLocks(): void { }\r\n public holdsExclusiveLock(): boolean { return false; }\r\n public holdsSharedLock(): boolean { return false; }\r\n public checkExclusiveLock(): void { }\r\n public checkSharedLock(): void { }\r\n public [_elementWasCreated](): void { }\r\n public async acquireLocks() { }\r\n public async [_releaseAllLocks](): Promise<void> { }\r\n public async releaseAllLocks(): Promise<void> { }\r\n}\r\n\r\nexport function createNoOpLockControl(): LockControl {\r\n return new NoLocks();\r\n}\r\n"]}
|
|
@@ -2,26 +2,18 @@
|
|
|
2
2
|
* @module iModels
|
|
3
3
|
*/
|
|
4
4
|
import { Id64Arg, Id64String } from "@itwin/core-bentley";
|
|
5
|
-
import { LockState } from "
|
|
6
|
-
import { BriefcaseDb
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* 1) they must hold at least a shared lock before an exclusive lock can be acquired for their members
|
|
11
|
-
* 2) if they hold an exclusive lock, then all of their members are exclusively locked implicitly.
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export interface ElementOwners {
|
|
15
|
-
readonly modelId: Id64String;
|
|
16
|
-
readonly parentId: Id64String | undefined;
|
|
17
|
-
}
|
|
18
|
-
/** @internal */
|
|
5
|
+
import { LockState } from "@itwin/core-common";
|
|
6
|
+
import { BriefcaseDb } from "../IModelDb";
|
|
7
|
+
import { LockControl } from "../LockControl";
|
|
8
|
+
import { SQLiteDb } from "../SQLiteDb";
|
|
9
|
+
import { _close, _elementWasCreated, _implementationProhibited, _releaseAllLocks } from "./Symbols";
|
|
19
10
|
export declare class ServerBasedLocks implements LockControl {
|
|
11
|
+
readonly [_implementationProhibited]: undefined;
|
|
20
12
|
get isServerBased(): boolean;
|
|
21
13
|
protected readonly lockDb: SQLiteDb;
|
|
22
14
|
protected readonly briefcase: BriefcaseDb;
|
|
23
15
|
constructor(iModel: BriefcaseDb);
|
|
24
|
-
|
|
16
|
+
[_close](): void;
|
|
25
17
|
private getOwners;
|
|
26
18
|
private getLockState;
|
|
27
19
|
/** Clear the cache of locally held locks.
|
|
@@ -30,6 +22,7 @@ export declare class ServerBasedLocks implements LockControl {
|
|
|
30
22
|
private clearAllLocks;
|
|
31
23
|
/** only for tests */
|
|
32
24
|
getLockCount(state: LockState): number;
|
|
25
|
+
[_releaseAllLocks](): Promise<void>;
|
|
33
26
|
releaseAllLocks(): Promise<void>;
|
|
34
27
|
private insertLock;
|
|
35
28
|
private ownerHoldsExclusiveLock;
|
|
@@ -47,7 +40,7 @@ export declare class ServerBasedLocks implements LockControl {
|
|
|
47
40
|
exclusive?: Id64Arg;
|
|
48
41
|
}): Promise<void>;
|
|
49
42
|
/** When an element is newly created in a session, we hold the lock on it implicitly. Save that fact. */
|
|
50
|
-
|
|
43
|
+
[_elementWasCreated](id: Id64String): void;
|
|
51
44
|
/** locks are not necessary during change propagation. */
|
|
52
45
|
private get _locksAreRequired();
|
|
53
46
|
/** throw if locks are currently required and the exclusive lock is not held on the supplied element */
|
|
@@ -55,4 +48,5 @@ export declare class ServerBasedLocks implements LockControl {
|
|
|
55
48
|
/** throw if locks are currently required and a shared lock is not held on the supplied element */
|
|
56
49
|
checkSharedLock(id: Id64String, type: string, operation: string): void;
|
|
57
50
|
}
|
|
51
|
+
export declare function createServerBasedLocks(iModel: BriefcaseDb): LockControl;
|
|
58
52
|
//# sourceMappingURL=ServerBasedLocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerBasedLocks.d.ts","sourceRoot":"","sources":["../../../src/internal/ServerBasedLocks.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAkB,OAAO,EAAE,UAAU,EAA0B,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAuB,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,yBAAyB,EAAa,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAmB/G,qBAAa,gBAAiB,YAAW,WAAW;IAClD,SAAgB,CAAC,yBAAyB,CAAC,YAAa;IAExD,IAAW,aAAa,YAAmB;IAC3C,SAAS,CAAC,QAAQ,CAAC,MAAM,WAAkB;IAC3C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;gBAEvB,MAAM,EAAE,WAAW;IAY/B,CAAC,MAAM,CAAC;IAKf,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAKrB,qBAAqB;IACd,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAQhC,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAKnC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ7C,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,uBAAuB;IAgB/B,mGAAmG;IAC5F,kBAAkB,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO;IAK3C,eAAe,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO;IAM/C,sIAAsI;IACtI,OAAO,CAAC,aAAa;IAUrB,sGAAsG;IACtG,OAAO,CAAC,mBAAmB;IAM3B,mEAAmE;YACrD,eAAe;IAmBhB,YAAY,CAAC,GAAG,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBxF,wGAAwG;IACjG,CAAC,kBAAkB,CAAC,CAAC,EAAE,EAAE,UAAU;IAK1C,yDAAyD;IACzD,OAAO,KAAK,iBAAiB,GAAqD;IAElF,uGAAuG;IAChG,kBAAkB,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAKzE,kGAAkG;IAC3F,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAKvE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAEvE"}
|
|
@@ -3,23 +3,24 @@
|
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
var _a;
|
|
6
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ServerBasedLocks = void 0;
|
|
8
|
+
exports.createServerBasedLocks = exports.ServerBasedLocks = void 0;
|
|
8
9
|
/** @packageDocumentation
|
|
9
10
|
* @module iModels
|
|
10
11
|
*/
|
|
11
12
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
13
|
const core_common_1 = require("@itwin/core-common");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
/** @internal */
|
|
14
|
+
const IModelHost_1 = require("../IModelHost");
|
|
15
|
+
const SQLiteDb_1 = require("../SQLiteDb");
|
|
16
|
+
const Symbols_1 = require("./Symbols");
|
|
17
17
|
class ServerBasedLocks {
|
|
18
18
|
get isServerBased() { return true; }
|
|
19
19
|
constructor(iModel) {
|
|
20
|
+
this[_a] = undefined;
|
|
20
21
|
this.lockDb = new SQLiteDb_1.SQLiteDb();
|
|
21
22
|
this.briefcase = iModel;
|
|
22
|
-
const dbName = `${iModel.
|
|
23
|
+
const dbName = `${iModel[Symbols_1._nativeDb].getTempFileBaseName()}-locks`;
|
|
23
24
|
try {
|
|
24
25
|
this.lockDb.openDb(dbName, core_bentley_1.OpenMode.ReadWrite);
|
|
25
26
|
}
|
|
@@ -29,7 +30,7 @@ class ServerBasedLocks {
|
|
|
29
30
|
this.lockDb.saveChanges();
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
[(_a = Symbols_1._implementationProhibited, Symbols_1._close)]() {
|
|
33
34
|
if (this.lockDb.isOpen)
|
|
34
35
|
this.lockDb.closeDb();
|
|
35
36
|
}
|
|
@@ -63,10 +64,16 @@ class ServerBasedLocks {
|
|
|
63
64
|
return stmt.getValueInteger(0);
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
|
-
async
|
|
67
|
+
async [Symbols_1._releaseAllLocks]() {
|
|
67
68
|
await IModelHost_1.IModelHost.hubAccess.releaseAllLocks(this.briefcase); // throws if unsuccessful
|
|
68
69
|
this.clearAllLocks();
|
|
69
70
|
}
|
|
71
|
+
async releaseAllLocks() {
|
|
72
|
+
if (this.briefcase.txns.hasLocalChanges) {
|
|
73
|
+
throw new Error("Locks cannot be released while the briefcase contains local changes");
|
|
74
|
+
}
|
|
75
|
+
return this[Symbols_1._releaseAllLocks]();
|
|
76
|
+
}
|
|
70
77
|
insertLock(id, state, origin) {
|
|
71
78
|
this.lockDb.withPreparedSqliteStatement("INSERT INTO locks(id,state,origin) VALUES (?,?,?) ON CONFLICT(id) DO UPDATE SET state=excluded.state,origin=excluded.origin", (stmt) => {
|
|
72
79
|
stmt.bindId(1, id);
|
|
@@ -82,23 +89,23 @@ class ServerBasedLocks {
|
|
|
82
89
|
if (id === undefined || id === core_common_1.IModel.rootSubjectId)
|
|
83
90
|
return false; // has no owners
|
|
84
91
|
const { modelId, parentId } = this.getOwners(id);
|
|
85
|
-
if (this.getLockState(modelId) ===
|
|
92
|
+
if (this.getLockState(modelId) === core_common_1.LockState.Exclusive || this.getLockState(parentId) === core_common_1.LockState.Exclusive)
|
|
86
93
|
return true;
|
|
87
94
|
// see if this model is exclusively locked by one of its owners. If so, save that fact on modelId so future tests won't have to descend.
|
|
88
95
|
if (this.ownerHoldsExclusiveLock(modelId))
|
|
89
|
-
return this.insertLock(modelId,
|
|
96
|
+
return this.insertLock(modelId, core_common_1.LockState.Exclusive, 2 /* LockOrigin.Discovered */);
|
|
90
97
|
// see if the parent is exclusively locked by one of its owners. If so, save that fact on parentId so future tests won't have to descend.
|
|
91
|
-
return this.ownerHoldsExclusiveLock(parentId) ? this.insertLock(parentId,
|
|
98
|
+
return this.ownerHoldsExclusiveLock(parentId) ? this.insertLock(parentId, core_common_1.LockState.Exclusive, 2 /* LockOrigin.Discovered */) : false; // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
92
99
|
}
|
|
93
100
|
/** Determine whether an the exclusive lock is already held by an element (or one of its owners) */
|
|
94
101
|
holdsExclusiveLock(id) {
|
|
95
102
|
// see if we hold the exclusive lock. or if one of the element's owners is exclusively locked (recursively)
|
|
96
|
-
return this.getLockState(id) ===
|
|
103
|
+
return this.getLockState(id) === core_common_1.LockState.Exclusive || this.ownerHoldsExclusiveLock(id);
|
|
97
104
|
}
|
|
98
105
|
holdsSharedLock(id) {
|
|
99
106
|
const state = this.getLockState(id);
|
|
100
107
|
// see if we hold shared or exclusive lock, or if an owner has exclusive lock. If so we implicitly have shared lock, but owner holding shared lock doesn't help.
|
|
101
|
-
return (state ===
|
|
108
|
+
return (state === core_common_1.LockState.Shared || state === core_common_1.LockState.Exclusive) || this.ownerHoldsExclusiveLock(id);
|
|
102
109
|
}
|
|
103
110
|
/** if the shared lock on the element supplied is not already held, add it to the set of shared locks required. Then, check owners. */
|
|
104
111
|
addSharedLock(id, locks) {
|
|
@@ -124,7 +131,7 @@ class ServerBasedLocks {
|
|
|
124
131
|
this.addOwnerSharedLocks(lock[0], sharedLocks);
|
|
125
132
|
for (const shared of sharedLocks) {
|
|
126
133
|
if (!locks.has(shared)) // we may already be asking for exclusive lock
|
|
127
|
-
locks.set(shared,
|
|
134
|
+
locks.set(shared, core_common_1.LockState.Shared);
|
|
128
135
|
}
|
|
129
136
|
await IModelHost_1.IModelHost.hubAccess.acquireLocks(this.briefcase, locks); // throws if unsuccessful
|
|
130
137
|
for (const lock of locks)
|
|
@@ -136,20 +143,20 @@ class ServerBasedLocks {
|
|
|
136
143
|
if (arg.shared) {
|
|
137
144
|
for (const id of core_bentley_1.Id64.iterable(arg.shared)) {
|
|
138
145
|
if (!this.holdsSharedLock(id))
|
|
139
|
-
locks.set(id,
|
|
146
|
+
locks.set(id, core_common_1.LockState.Shared);
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
if (arg.exclusive) {
|
|
143
150
|
for (const id of core_bentley_1.Id64.iterable(arg.exclusive)) {
|
|
144
151
|
if (!this.holdsExclusiveLock(id))
|
|
145
|
-
locks.set(id,
|
|
152
|
+
locks.set(id, core_common_1.LockState.Exclusive);
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
return this.acquireAllLocks(locks);
|
|
149
156
|
}
|
|
150
157
|
/** When an element is newly created in a session, we hold the lock on it implicitly. Save that fact. */
|
|
151
|
-
|
|
152
|
-
this.insertLock(id,
|
|
158
|
+
[Symbols_1._elementWasCreated](id) {
|
|
159
|
+
this.insertLock(id, core_common_1.LockState.Exclusive, 1 /* LockOrigin.NewElement */);
|
|
153
160
|
this.lockDb.saveChanges();
|
|
154
161
|
}
|
|
155
162
|
/** locks are not necessary during change propagation. */
|
|
@@ -166,4 +173,8 @@ class ServerBasedLocks {
|
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
175
|
exports.ServerBasedLocks = ServerBasedLocks;
|
|
176
|
+
function createServerBasedLocks(iModel) {
|
|
177
|
+
return new ServerBasedLocks(iModel);
|
|
178
|
+
}
|
|
179
|
+
exports.createServerBasedLocks = createServerBasedLocks;
|
|
169
180
|
//# sourceMappingURL=ServerBasedLocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerBasedLocks.js","sourceRoot":"","sources":["../../../src/internal/ServerBasedLocks.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;AAE/F;;GAEG;AAEH,sDAAkG;AAClG,oDAAoE;AAIpE,8CAA2C;AAC3C,0CAAuC;AACvC,uCAA+G;AAmB/G,MAAa,gBAAgB;IAG3B,IAAW,aAAa,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAI3C,YAAmB,MAAmB;QANtB,QAA2B,GAAG,SAAS,CAAC;QAGrC,WAAM,GAAG,IAAI,mBAAQ,EAAE,CAAC;QAIzC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QACxB,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,mBAAS,CAAC,CAAC,mBAAmB,EAAE,QAAQ,CAAC;QAClE,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAQ,CAAC,SAAS,CAAC,CAAC;QACjD,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AC;QACD,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,wGAAwG;IACjG,CAAC,4BAAkB,CAAC,CAAC,EAAc;QACxC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,uBAAS,CAAC,SAAS,gCAAwB,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED,yDAAyD;IACzD,IAAY,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAElF,uGAAuG;IAChG,kBAAkB,CAAC,EAAc,EAAE,IAAY,EAAE,SAAiB;QACvE,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,WAAW,EAAE,8BAA8B,IAAI,QAAQ,SAAS,QAAQ,EAAE,GAAG,CAAC,CAAC;IACtH,CAAC;IAED,kGAAkG;IAC3F,eAAe,CAAC,EAAc,EAAE,IAAY,EAAE,SAAiB;QACpE,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,WAAW,EAAE,2BAA2B,IAAI,QAAQ,SAAS,QAAQ,EAAE,GAAG,CAAC,CAAC;IACnH,CAAC;CAEF;AA5LD,4CA4LC;AAED,SAAgB,sBAAsB,CAAC,MAAmB;IACxD,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAFD,wDAEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\nimport { DbResult, Id64, Id64Arg, Id64String, IModelStatus, OpenMode } from \"@itwin/core-bentley\";\r\nimport { IModel, IModelError, LockState } from \"@itwin/core-common\";\r\nimport { LockMap } from \"../BackendHubAccess\";\r\nimport { BriefcaseDb } from \"../IModelDb\";\r\nimport { LockControl } from \"../LockControl\";\r\nimport { IModelHost } from \"../IModelHost\";\r\nimport { SQLiteDb } from \"../SQLiteDb\";\r\nimport { _close, _elementWasCreated, _implementationProhibited, _nativeDb, _releaseAllLocks } from \"./Symbols\";\r\n\r\n/**\r\n * Both the Model and Parent of an element are considered \"owners\" of their member elements. That means:\r\n * 1) they must hold at least a shared lock before an exclusive lock can be acquired for their members\r\n * 2) if they hold an exclusive lock, then all of their members are exclusively locked implicitly.\r\n */\r\ninterface ElementOwners {\r\n readonly modelId: Id64String;\r\n readonly parentId: Id64String | undefined;\r\n}\r\n\r\n// eslint-disable-next-line no-restricted-syntax\r\nconst enum LockOrigin {\r\n Acquired = 0,\r\n NewElement = 1,\r\n Discovered = 2,\r\n}\r\n\r\nexport class ServerBasedLocks implements LockControl {\r\n public readonly [_implementationProhibited] = undefined;\r\n\r\n public get isServerBased() { return true; }\r\n protected readonly lockDb = new SQLiteDb();\r\n protected readonly briefcase: BriefcaseDb;\r\n\r\n public constructor(iModel: BriefcaseDb) {\r\n this.briefcase = iModel;\r\n const dbName = `${iModel[_nativeDb].getTempFileBaseName()}-locks`;\r\n try {\r\n this.lockDb.openDb(dbName, OpenMode.ReadWrite);\r\n } catch (_e) {\r\n this.lockDb.createDb(dbName);\r\n this.lockDb.executeSQL(\"CREATE TABLE locks(id INTEGER PRIMARY KEY NOT NULL,state INTEGER NOT NULL,origin INTEGER)\");\r\n this.lockDb.saveChanges();\r\n }\r\n }\r\n\r\n public [_close]() {\r\n if (this.lockDb.isOpen)\r\n this.lockDb.closeDb();\r\n }\r\n\r\n private getOwners(id: Id64String): ElementOwners {\r\n return this.briefcase.withPreparedSqliteStatement(\"SELECT ModelId,ParentId FROM bis_Element WHERE id=?\", (stmt) => {\r\n stmt.bindId(1, id);\r\n const rc = stmt.step();\r\n if (DbResult.BE_SQLITE_ROW !== rc)\r\n throw new IModelError(rc, `element ${id} not found`);\r\n\r\n return { modelId: stmt.getValueId(0), parentId: stmt.getValueId(1) };\r\n });\r\n }\r\n\r\n private getLockState(id?: Id64String): LockState | undefined {\r\n return (id === undefined || !Id64.isValid(id)) ? undefined : this.lockDb.withPreparedSqliteStatement(\"SELECT state FROM locks WHERE id=?\", (stmt) => {\r\n stmt.bindId(1, id);\r\n return (DbResult.BE_SQLITE_ROW === stmt.step()) ? stmt.getValueInteger(0) : undefined;\r\n });\r\n }\r\n\r\n /** Clear the cache of locally held locks.\r\n * Note: does *not* release locks from server.\r\n */\r\n private clearAllLocks() {\r\n this.lockDb.executeSQL(\"DELETE FROM locks\");\r\n this.lockDb.saveChanges();\r\n }\r\n\r\n /** only for tests */\r\n public getLockCount(state: LockState): number {\r\n return this.lockDb.withSqliteStatement(\"SELECT count(*) FROM locks WHERE state=?\", (stmt) => {\r\n stmt.bindInteger(1, state);\r\n stmt.step();\r\n return stmt.getValueInteger(0);\r\n });\r\n }\r\n\r\n public async [_releaseAllLocks](): Promise<void> {\r\n await IModelHost.hubAccess.releaseAllLocks(this.briefcase); // throws if unsuccessful\r\n this.clearAllLocks();\r\n }\r\n\r\n public async releaseAllLocks(): Promise<void> {\r\n if (this.briefcase.txns.hasLocalChanges) {\r\n throw new Error(\"Locks cannot be released while the briefcase contains local changes\");\r\n }\r\n\r\n return this[_releaseAllLocks]();\r\n }\r\n\r\n private insertLock(id: Id64String, state: LockState, origin: LockOrigin): true {\r\n this.lockDb.withPreparedSqliteStatement(\"INSERT INTO locks(id,state,origin) VALUES (?,?,?) ON CONFLICT(id) DO UPDATE SET state=excluded.state,origin=excluded.origin\", (stmt) => {\r\n stmt.bindId(1, id);\r\n stmt.bindInteger(2, state);\r\n stmt.bindInteger(3, origin);\r\n const rc = stmt.step();\r\n if (DbResult.BE_SQLITE_DONE !== rc)\r\n throw new IModelError(rc, \"can't insert lock into database\");\r\n });\r\n return true;\r\n }\r\n\r\n private ownerHoldsExclusiveLock(id: Id64String | undefined): boolean {\r\n if (id === undefined || id === IModel.rootSubjectId)\r\n return false; // has no owners\r\n\r\n const { modelId, parentId } = this.getOwners(id);\r\n if (this.getLockState(modelId) === LockState.Exclusive || this.getLockState(parentId) === LockState.Exclusive)\r\n return true;\r\n\r\n // see if this model is exclusively locked by one of its owners. If so, save that fact on modelId so future tests won't have to descend.\r\n if (this.ownerHoldsExclusiveLock(modelId))\r\n return this.insertLock(modelId, LockState.Exclusive, LockOrigin.Discovered);\r\n\r\n // see if the parent is exclusively locked by one of its owners. If so, save that fact on parentId so future tests won't have to descend.\r\n return this.ownerHoldsExclusiveLock(parentId) ? this.insertLock(parentId!, LockState.Exclusive, LockOrigin.Discovered) : false; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n }\r\n\r\n /** Determine whether an the exclusive lock is already held by an element (or one of its owners) */\r\n public holdsExclusiveLock(id: Id64String): boolean {\r\n // see if we hold the exclusive lock. or if one of the element's owners is exclusively locked (recursively)\r\n return this.getLockState(id) === LockState.Exclusive || this.ownerHoldsExclusiveLock(id);\r\n }\r\n\r\n public holdsSharedLock(id: Id64String): boolean {\r\n const state = this.getLockState(id);\r\n // see if we hold shared or exclusive lock, or if an owner has exclusive lock. If so we implicitly have shared lock, but owner holding shared lock doesn't help.\r\n return (state === LockState.Shared || state === LockState.Exclusive) || this.ownerHoldsExclusiveLock(id);\r\n }\r\n\r\n /** if the shared lock on the element supplied is not already held, add it to the set of shared locks required. Then, check owners. */\r\n private addSharedLock(id: Id64String | undefined, locks: Set<Id64String>) {\r\n // if the id is not valid, or of the lock is already in the set, or if we already hold a shared lock, we're done\r\n // Note: if we hold a shared lock, it is guaranteed that we also hold all required shared locks on owners.\r\n if (id === undefined || !Id64.isValid(id) || locks.has(id) || this.holdsSharedLock(id))\r\n return;\r\n\r\n locks.add(id); // add to set of needed shared locks\r\n this.addOwnerSharedLocks(id, locks); // check parent models and groups\r\n }\r\n\r\n /** add owners (recursively) of an element to a list of required shared locks, if not already held. */\r\n private addOwnerSharedLocks(id: Id64String, locks: Set<Id64String>) {\r\n const el = this.getOwners(id);\r\n this.addSharedLock(el.parentId, locks); // if this element is in a group\r\n this.addSharedLock(el.modelId, locks); // check its model\r\n }\r\n\r\n /** attempt to acquire all necessary locks for a set of elements */\r\n private async acquireAllLocks(locks: LockMap) {\r\n if (locks.size === 0) // no locks are required.\r\n return;\r\n\r\n const sharedLocks = new Set<Id64String>();\r\n for (const lock of locks)\r\n this.addOwnerSharedLocks(lock[0], sharedLocks);\r\n\r\n for (const shared of sharedLocks) {\r\n if (!locks.has(shared)) // we may already be asking for exclusive lock\r\n locks.set(shared, LockState.Shared);\r\n }\r\n\r\n await IModelHost.hubAccess.acquireLocks(this.briefcase, locks); // throws if unsuccessful\r\n for (const lock of locks)\r\n this.insertLock(lock[0], lock[1], LockOrigin.Acquired);\r\n this.lockDb.saveChanges();\r\n }\r\n\r\n public async acquireLocks(arg: { shared?: Id64Arg, exclusive?: Id64Arg }): Promise<void> {\r\n const locks = new Map<Id64String, LockState>();\r\n if (arg.shared) {\r\n for (const id of Id64.iterable(arg.shared)) {\r\n if (!this.holdsSharedLock(id))\r\n locks.set(id, LockState.Shared);\r\n }\r\n }\r\n if (arg.exclusive) {\r\n for (const id of Id64.iterable(arg.exclusive)) {\r\n if (!this.holdsExclusiveLock(id))\r\n locks.set(id, LockState.Exclusive);\r\n }\r\n }\r\n return this.acquireAllLocks(locks);\r\n }\r\n\r\n /** When an element is newly created in a session, we hold the lock on it implicitly. Save that fact. */\r\n public [_elementWasCreated](id: Id64String) {\r\n this.insertLock(id, LockState.Exclusive, LockOrigin.NewElement);\r\n this.lockDb.saveChanges();\r\n }\r\n\r\n /** locks are not necessary during change propagation. */\r\n private get _locksAreRequired() { return !this.briefcase.txns.isIndirectChanges; }\r\n\r\n /** throw if locks are currently required and the exclusive lock is not held on the supplied element */\r\n public checkExclusiveLock(id: Id64String, type: string, operation: string) {\r\n if (this._locksAreRequired && !this.holdsExclusiveLock(id))\r\n throw new IModelError(IModelStatus.LockNotHeld, `exclusive lock not held on ${type} for ${operation} (id=${id})`);\r\n }\r\n\r\n /** throw if locks are currently required and a shared lock is not held on the supplied element */\r\n public checkSharedLock(id: Id64String, type: string, operation: string) {\r\n if (this._locksAreRequired && !this.holdsSharedLock(id))\r\n throw new IModelError(IModelStatus.LockNotHeld, `shared lock not held on ${type} for ${operation} (id=${id})`);\r\n }\r\n\r\n}\r\n\r\nexport function createServerBasedLocks(iModel: BriefcaseDb): LockControl {\r\n return new ServerBasedLocks(iModel);\r\n}\r\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Workspace
|
|
3
|
+
*/
|
|
4
|
+
export declare const _implementationProhibited: unique symbol;
|
|
5
|
+
export declare const _close: unique symbol;
|
|
6
|
+
export declare const _elementWasCreated: unique symbol;
|
|
7
|
+
/** @internal */
|
|
8
|
+
export declare const _nativeDb: unique symbol;
|
|
9
|
+
export declare const _releaseAllLocks: unique symbol;
|
|
10
|
+
export declare const _verifyChannel: unique symbol;
|
|
11
|
+
//# sourceMappingURL=Symbols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Symbols.d.ts","sourceRoot":"","sources":["../../../src/internal/Symbols.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,eAAO,MAAM,yBAAyB,eAAmG,CAAC;AAM1I,eAAO,MAAM,MAAM,eAA2B,CAAC;AAC/C,eAAO,MAAM,kBAAkB,eAAuC,CAAC;AACvE,gBAAgB;AAChB,eAAO,MAAM,SAAS,eAA8B,CAAC;AACrD,eAAO,MAAM,gBAAgB,eAAqC,CAAC;AACnE,eAAO,MAAM,cAAc,eAAmC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 Workspace
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports._verifyChannel = exports._releaseAllLocks = exports._nativeDb = exports._elementWasCreated = exports._close = exports._implementationProhibited = void 0;
|
|
11
|
+
exports._implementationProhibited = Symbol.for("Implementations of this interface can only be obtained from the containing package");
|
|
12
|
+
function sym(name) {
|
|
13
|
+
return `${name}_core-backend_INTERNAL_ONLY_DO_NOT_USE`;
|
|
14
|
+
}
|
|
15
|
+
exports._close = Symbol.for(sym("close"));
|
|
16
|
+
exports._elementWasCreated = Symbol.for(sym("elementWasCreated"));
|
|
17
|
+
/** @internal */
|
|
18
|
+
exports._nativeDb = Symbol.for(sym("nativeDb"));
|
|
19
|
+
exports._releaseAllLocks = Symbol.for(sym("releaseAllLocks"));
|
|
20
|
+
exports._verifyChannel = Symbol.for(sym("verifyChannel"));
|
|
21
|
+
//# sourceMappingURL=Symbols.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Symbols.js","sourceRoot":"","sources":["../../../src/internal/Symbols.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEU,QAAA,yBAAyB,GAAG,MAAM,CAAC,GAAG,CAAC,oFAAoF,CAAC,CAAC;AAE1I,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,GAAG,IAAI,wCAAwC,CAAC;AACzD,CAAC;AAEY,QAAA,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AAClC,QAAA,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC;AACvE,gBAAgB;AACH,QAAA,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACxC,QAAA,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACtD,QAAA,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC","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 Workspace\r\n */\r\n\r\nexport const _implementationProhibited = Symbol.for(\"Implementations of this interface can only be obtained from the containing package\");\r\n\r\nfunction sym(name: string): string {\r\n return `${name}_core-backend_INTERNAL_ONLY_DO_NOT_USE`;\r\n}\r\n\r\nexport const _close = Symbol.for(sym(\"close\"));\r\nexport const _elementWasCreated = Symbol.for(sym(\"elementWasCreated\"));\r\n/** @internal */\r\nexport const _nativeDb = Symbol.for(sym(\"nativeDb\"));\r\nexport const _releaseAllLocks = Symbol.for(sym(\"releaseAllLocks\"));\r\nexport const _verifyChannel = Symbol.for(sym(\"verifyChannel\"));\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-package.d.ts","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EACL,SAAS,GACV,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports._nativeDb = exports.IModelNative = exports.NativeLoggerCategory = exports.NativeCloudSqlite = exports.IModelJsNative = void 0;
|
|
8
|
+
var imodeljs_native_1 = require("@bentley/imodeljs-native");
|
|
9
|
+
Object.defineProperty(exports, "IModelJsNative", { enumerable: true, get: function () { return imodeljs_native_1.IModelJsNative; } });
|
|
10
|
+
Object.defineProperty(exports, "NativeCloudSqlite", { enumerable: true, get: function () { return imodeljs_native_1.NativeCloudSqlite; } });
|
|
11
|
+
Object.defineProperty(exports, "NativeLoggerCategory", { enumerable: true, get: function () { return imodeljs_native_1.NativeLoggerCategory; } });
|
|
12
|
+
var NativePlatform_1 = require("./NativePlatform");
|
|
13
|
+
Object.defineProperty(exports, "IModelNative", { enumerable: true, get: function () { return NativePlatform_1.IModelNative; } });
|
|
14
|
+
var Symbols_1 = require("./Symbols");
|
|
15
|
+
Object.defineProperty(exports, "_nativeDb", { enumerable: true, get: function () { return Symbols_1._nativeDb; } });
|
|
16
|
+
//# sourceMappingURL=cross-package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-package.js","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,4DAAmG;AAA1F,iHAAA,cAAc,OAAA;AAAE,oHAAA,iBAAiB,OAAA;AAAE,uHAAA,oBAAoB,OAAA;AAChE,mDAAgD;AAAvC,8GAAA,YAAY,OAAA;AACrB,qCAEmB;AADjB,oGAAA,SAAS,OAAA","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nexport { IModelJsNative, NativeCloudSqlite, NativeLoggerCategory } from \"@bentley/imodeljs-native\";\r\nexport { IModelNative } from \"./NativePlatform\";\r\nexport {\r\n _nativeDb,\r\n} from \"./Symbols\";\r\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Workspace
|
|
3
|
+
*/
|
|
4
|
+
import { BeEvent } from "@itwin/core-bentley";
|
|
5
|
+
import { LocalDirName, LocalFileName } from "@itwin/core-common";
|
|
6
|
+
import { Setting, SettingName, Settings, SettingsContainer, SettingsDictionary, SettingsDictionaryProps, SettingsDictionarySource, SettingsPriority } from "../../workspace/Settings";
|
|
7
|
+
import { _implementationProhibited } from "../Symbols";
|
|
8
|
+
/**
|
|
9
|
+
* Internal implementation of Settings interface.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare class SettingsImpl implements Settings {
|
|
13
|
+
readonly [_implementationProhibited]: undefined;
|
|
14
|
+
dictionaries: SettingsDictionary[];
|
|
15
|
+
protected verifyPriority(_priority: SettingsPriority): void;
|
|
16
|
+
close(): void;
|
|
17
|
+
readonly onSettingsChanged: BeEvent<() => void>;
|
|
18
|
+
addFile(fileName: LocalFileName, priority: SettingsPriority): void;
|
|
19
|
+
addDirectory(dirName: LocalDirName, priority: SettingsPriority): void;
|
|
20
|
+
addJson(props: SettingsDictionaryProps, settingsJson: string): void;
|
|
21
|
+
addDictionary(props: SettingsDictionaryProps, settings: SettingsContainer): void;
|
|
22
|
+
getDictionary(source: SettingsDictionarySource): SettingsDictionary | undefined;
|
|
23
|
+
dropDictionary(source: SettingsDictionarySource, raiseEvent?: boolean): boolean;
|
|
24
|
+
getSettingEntries<T extends Setting>(settingName: SettingName): Iterable<{
|
|
25
|
+
value: T;
|
|
26
|
+
dictionary: SettingsDictionary;
|
|
27
|
+
}>;
|
|
28
|
+
getSettingValues<T extends Setting>(settingName: SettingName): Iterable<T>;
|
|
29
|
+
getSetting<T extends Setting>(settingName: SettingName, defaultValue?: T): T | undefined;
|
|
30
|
+
private getResult;
|
|
31
|
+
getString(name: SettingName, defaultValue: string): string;
|
|
32
|
+
getString(name: SettingName): string | undefined;
|
|
33
|
+
getBoolean(name: SettingName, defaultValue: boolean): boolean;
|
|
34
|
+
getBoolean(name: SettingName): boolean | undefined;
|
|
35
|
+
getNumber(name: SettingName, defaultValue: number): number;
|
|
36
|
+
getNumber(name: SettingName): number | undefined;
|
|
37
|
+
getObject<T extends object>(name: SettingName, defaultValue: T): T;
|
|
38
|
+
getObject<T extends object>(name: SettingName): T | undefined;
|
|
39
|
+
getArray<T extends Setting>(name: SettingName, defaultValue: T[]): T[];
|
|
40
|
+
getArray<T extends Setting>(name: SettingName): T[] | undefined;
|
|
41
|
+
private getCombinedArray;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=SettingsImpl.d.ts.map
|