@itwin/core-backend 5.0.0-dev.105 → 5.0.0-dev.109
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/CatalogDb.d.ts +103 -0
- package/lib/cjs/CatalogDb.d.ts.map +1 -0
- package/lib/cjs/CatalogDb.js +271 -0
- package/lib/cjs/CatalogDb.js.map +1 -0
- package/lib/cjs/CloudSqlite.d.ts +104 -20
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +157 -46
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.d.ts +1 -1
- package/lib/cjs/ECSchemaXmlContext.js +1 -1
- package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
- package/lib/cjs/Entity.d.ts +8 -4
- package/lib/cjs/Entity.d.ts.map +1 -1
- package/lib/cjs/Entity.js +3 -3
- package/lib/cjs/Entity.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +6 -1
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +14 -7
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +1 -1
- package/lib/cjs/IModelHost.js +1 -1
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/NativeHost.d.ts.map +1 -1
- package/lib/cjs/NativeHost.js +4 -1
- package/lib/cjs/NativeHost.js.map +1 -1
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +5 -4
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/ViewStore.d.ts.map +1 -1
- package/lib/cjs/ViewStore.js +27 -27
- package/lib/cjs/ViewStore.js.map +1 -1
- package/lib/cjs/core-backend.d.ts +1 -0
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +1 -0
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/internal/ChannelAdmin.js +4 -4
- package/lib/cjs/internal/ChannelAdmin.js.map +1 -1
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts +2 -16
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts.map +1 -1
- package/lib/cjs/internal/workspace/WorkspaceImpl.js +35 -104
- package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +6 -13
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/lib/cjs/workspace/WorkspaceEditor.d.ts +2 -7
- package/lib/cjs/workspace/WorkspaceEditor.d.ts.map +1 -1
- package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -1
- package/lib/esm/CatalogDb.d.ts +103 -0
- package/lib/esm/CatalogDb.d.ts.map +1 -0
- package/lib/esm/CatalogDb.js +267 -0
- package/lib/esm/CatalogDb.js.map +1 -0
- package/lib/esm/CloudSqlite.d.ts +104 -20
- package/lib/esm/CloudSqlite.d.ts.map +1 -1
- package/lib/esm/CloudSqlite.js +157 -46
- package/lib/esm/CloudSqlite.js.map +1 -1
- package/lib/esm/ECSchemaXmlContext.d.ts +1 -1
- package/lib/esm/ECSchemaXmlContext.js +1 -1
- package/lib/esm/ECSchemaXmlContext.js.map +1 -1
- package/lib/esm/Entity.d.ts +8 -4
- package/lib/esm/Entity.d.ts.map +1 -1
- package/lib/esm/Entity.js +3 -3
- package/lib/esm/Entity.js.map +1 -1
- package/lib/esm/IModelDb.d.ts +6 -1
- package/lib/esm/IModelDb.d.ts.map +1 -1
- package/lib/esm/IModelDb.js +14 -7
- package/lib/esm/IModelDb.js.map +1 -1
- package/lib/esm/IModelHost.d.ts +1 -1
- package/lib/esm/IModelHost.js +1 -1
- package/lib/esm/IModelHost.js.map +1 -1
- package/lib/esm/NativeHost.d.ts.map +1 -1
- package/lib/esm/NativeHost.js +4 -1
- package/lib/esm/NativeHost.js.map +1 -1
- package/lib/esm/SQLiteDb.d.ts.map +1 -1
- package/lib/esm/SQLiteDb.js +5 -4
- package/lib/esm/SQLiteDb.js.map +1 -1
- package/lib/esm/ViewStore.d.ts.map +1 -1
- package/lib/esm/ViewStore.js +28 -28
- package/lib/esm/ViewStore.js.map +1 -1
- package/lib/esm/core-backend.d.ts +1 -0
- package/lib/esm/core-backend.d.ts.map +1 -1
- package/lib/esm/core-backend.js +1 -0
- package/lib/esm/core-backend.js.map +1 -1
- package/lib/esm/internal/ChannelAdmin.js +5 -5
- package/lib/esm/internal/ChannelAdmin.js.map +1 -1
- package/lib/esm/internal/workspace/WorkspaceImpl.d.ts +2 -16
- package/lib/esm/internal/workspace/WorkspaceImpl.d.ts.map +1 -1
- package/lib/esm/internal/workspace/WorkspaceImpl.js +36 -100
- package/lib/esm/internal/workspace/WorkspaceImpl.js.map +1 -1
- package/lib/esm/test/standalone/SnapshotDb.test.js +2 -2
- package/lib/esm/test/standalone/SnapshotDb.test.js.map +1 -1
- package/lib/esm/test/standalone/Workspace.test.js +4 -3
- package/lib/esm/test/standalone/Workspace.test.js.map +1 -1
- package/lib/esm/workspace/Workspace.d.ts +6 -13
- package/lib/esm/workspace/Workspace.d.ts.map +1 -1
- package/lib/esm/workspace/Workspace.js.map +1 -1
- package/lib/esm/workspace/WorkspaceEditor.d.ts +2 -7
- package/lib/esm/workspace/WorkspaceEditor.d.ts.map +1 -1
- package/lib/esm/workspace/WorkspaceEditor.js.map +1 -1
- package/package.json +12 -12
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module iModels
|
|
3
|
+
*/
|
|
4
|
+
import { type CatalogIModel, IModelConnectionProps } from "@itwin/core-common";
|
|
5
|
+
import { IpcHandler } from "./IpcHost";
|
|
6
|
+
import { StandaloneDb } from "./IModelDb";
|
|
7
|
+
/** A [[StandaloneDb]] that provides read-only access to the contents of a [CatalogIModel]($common).
|
|
8
|
+
* @see [[CatalogDb.openReadonly]] to instantiate this type.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export interface CatalogDb extends StandaloneDb {
|
|
12
|
+
/** Get the catalog's manifest. */
|
|
13
|
+
getManifest(): CatalogIModel.Manifest | undefined;
|
|
14
|
+
/** Get the catalog's version information. */
|
|
15
|
+
getVersion(): string;
|
|
16
|
+
/** Get the catalog's manifest and version. */
|
|
17
|
+
getInfo(): {
|
|
18
|
+
manifest?: CatalogIModel.Manifest;
|
|
19
|
+
version: string;
|
|
20
|
+
};
|
|
21
|
+
/** Returns true if the catalog was opened in read-write mode. */
|
|
22
|
+
isEditable(): this is EditableCatalogDb;
|
|
23
|
+
}
|
|
24
|
+
/** A writable [[CatalogDb]].
|
|
25
|
+
* @see [[CatalogDb.openEditable]] to instantiate this type.
|
|
26
|
+
* @beta
|
|
27
|
+
*/
|
|
28
|
+
export interface EditableCatalogDb extends CatalogDb {
|
|
29
|
+
/** Update the contents of the catalog manifest. */
|
|
30
|
+
updateCatalogManifest(manifest: CatalogIModel.Manifest): void;
|
|
31
|
+
}
|
|
32
|
+
/** @beta */
|
|
33
|
+
export declare namespace CatalogDb {
|
|
34
|
+
/** Create a new [[BlobContainer]] to hold versions of a [[CatalogDb]].
|
|
35
|
+
* @returns The properties of the newly created container.
|
|
36
|
+
* @note creating new containers requires "admin" authorization.
|
|
37
|
+
*/
|
|
38
|
+
function createNewContainer(args: CatalogIModel.CreateNewContainerArgs): Promise<CatalogIModel.NewContainerProps>;
|
|
39
|
+
/** Acquire the write lock for a [CatalogIModel]($common) container. Only one person may obtain the write lock at a time.
|
|
40
|
+
* You must obtain the lock before attempting to write to the container via functions like [[CatalogDb.openEditable]] and [[CatalogDb.createNewVersion]].
|
|
41
|
+
* @note This requires "write" authorization to the container
|
|
42
|
+
*/
|
|
43
|
+
function acquireWriteLock(args: {
|
|
44
|
+
/** The id of the container */
|
|
45
|
+
containerId: string;
|
|
46
|
+
/**
|
|
47
|
+
* The name of the individual acquiring the lock. This will be shown to others who attempt to acquire the lock while it is held.
|
|
48
|
+
* It is also stored in the "lastEditedBy" field of the manifest of any new version edited while the lock is held.
|
|
49
|
+
*/
|
|
50
|
+
username: string;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/** Release the write lock on a [CatalogIModel]($common) container. This uploads all changes made while the lock is held, so they become visible to other users. */
|
|
53
|
+
function releaseWriteLock(args: {
|
|
54
|
+
/** The id of the container */
|
|
55
|
+
containerId: string;
|
|
56
|
+
/** If true, abandon all local changes before releasing the lock */
|
|
57
|
+
abandon?: true;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/** Open an [[EditableCatalogDb]] for write access.
|
|
60
|
+
* @note Once a version of a catalog iModel has been published (i.e. the write lock has been released), it is no longer editable, *unless* it is a prerelease version.
|
|
61
|
+
* @note The write lock must be held for this operation to succeed
|
|
62
|
+
*/
|
|
63
|
+
function openEditable(args: CatalogIModel.OpenArgs): Promise<EditableCatalogDb>;
|
|
64
|
+
/** Open a [[CatalogDb]] for read-only access. */
|
|
65
|
+
function openReadonly(args: CatalogIModel.OpenArgs): Promise<CatalogDb>;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new version of a [CatalogIModel]($common) as a copy of an existing version. Immediately after this operation, the new version will be an exact copy
|
|
68
|
+
* of the source CatalogIModel. Then, use [[CatalogDb.openEditable]] to modify the new version with new content.
|
|
69
|
+
* @note The write lock must be held for this operation to succeed
|
|
70
|
+
*/
|
|
71
|
+
function createNewVersion(args: CatalogIModel.CreateNewVersionArgs): Promise<{
|
|
72
|
+
oldDb: CatalogIModel.NameAndVersion;
|
|
73
|
+
newDb: CatalogIModel.NameAndVersion;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Handler for Ipc access to CatalogIModels. Registered by NativeHost.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export declare class CatalogIModelHandler extends IpcHandler implements CatalogIModel.IpcMethods {
|
|
81
|
+
get channelName(): CatalogIModel.IpcChannel;
|
|
82
|
+
createNewContainer(args: CatalogIModel.CreateNewContainerArgs): Promise<CatalogIModel.NewContainerProps>;
|
|
83
|
+
acquireWriteLock(args: {
|
|
84
|
+
containerId: string;
|
|
85
|
+
username: string;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
releaseWriteLock(args: {
|
|
88
|
+
containerId: string;
|
|
89
|
+
abandon?: true;
|
|
90
|
+
}): Promise<void>;
|
|
91
|
+
openReadonly(args: CatalogIModel.OpenArgs): Promise<IModelConnectionProps>;
|
|
92
|
+
openEditable(args: CatalogIModel.OpenArgs): Promise<IModelConnectionProps>;
|
|
93
|
+
createNewVersion(args: CatalogIModel.CreateNewVersionArgs): Promise<{
|
|
94
|
+
oldDb: CatalogIModel.NameAndVersion;
|
|
95
|
+
newDb: CatalogIModel.NameAndVersion;
|
|
96
|
+
}>;
|
|
97
|
+
getInfo(key: string): Promise<{
|
|
98
|
+
manifest?: CatalogIModel.Manifest;
|
|
99
|
+
version: string;
|
|
100
|
+
}>;
|
|
101
|
+
updateCatalogManifest(key: string, manifest: CatalogIModel.Manifest): Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=CatalogDb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogDb.d.ts","sourceRoot":"","sources":["../../src/CatalogDb.ts"],"names":[],"mappings":"AAIA;;GAEG;AAMH,OAAO,EAAkC,KAAK,aAAa,EAAoB,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACjI,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkE1C;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,YAAY;IAC7C,kCAAkC;IAClC,WAAW,IAAI,aAAa,CAAC,QAAQ,GAAG,SAAS,CAAC;IAClD,6CAA6C;IAC7C,UAAU,IAAI,MAAM,CAAC;IACrB,8CAA8C;IAC9C,OAAO,IAAI;QAA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AC;KAAE,CAAC,CAIvK;CACF;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAW,YAAW,aAAa,CAAC,UAAU;IACtF,IAAW,WAAW,IAAI,aAAa,CAAC,UAAU,CAAgC;IAErE,kBAAkB,CAAC,IAAI,EAAE,aAAa,CAAC,sBAAsB,GAAG,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAC;IAGxG,gBAAgB,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAGjF,gBAAgB,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,IAAI,CAAC;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAG/E,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC,QAAQ,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAG1E,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC,QAAQ,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAG1E,gBAAgB,CAAC,IAAI,EAAE,aAAa,CAAC,oBAAoB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC;QAAC,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC;KAAE,CAAC;IAGlJ,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAGrF,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjG"}
|
|
@@ -0,0 +1,271 @@
|
|
|
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 iModels
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CatalogIModelHandler = exports.CatalogDb = void 0;
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const CloudSqlite_1 = require("./CloudSqlite");
|
|
14
|
+
const IModelHost_1 = require("./IModelHost");
|
|
15
|
+
const core_common_1 = require("@itwin/core-common");
|
|
16
|
+
const IpcHost_1 = require("./IpcHost");
|
|
17
|
+
const IModelDb_1 = require("./IModelDb");
|
|
18
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
19
|
+
const Symbols_1 = require("./internal/Symbols");
|
|
20
|
+
const NativePlatform_1 = require("./internal/NativePlatform");
|
|
21
|
+
let readonlyCloudCache;
|
|
22
|
+
let writeableCloudCache;
|
|
23
|
+
const catalogManifestName = "CatalogManifest";
|
|
24
|
+
// we make a readonly CloudCache and a writeable CloudCache. That way the access token authorizations are distinct.
|
|
25
|
+
function makeCloudCache(arg, writeable) {
|
|
26
|
+
const cache = CloudSqlite_1.CloudSqlite.CloudCaches.getCache(arg);
|
|
27
|
+
// if the cache was just created, add the "catalog" members as hidden
|
|
28
|
+
if (undefined === cache.catalogContainers) {
|
|
29
|
+
CloudSqlite_1.CloudSqlite.addHiddenProperty(cache, "catalogContainers", new Map());
|
|
30
|
+
CloudSqlite_1.CloudSqlite.addHiddenProperty(cache, "writeable", writeable);
|
|
31
|
+
}
|
|
32
|
+
return cache;
|
|
33
|
+
}
|
|
34
|
+
// find an existing CloudContainer for accessing a CatalogIModel, or make a new one and connect it
|
|
35
|
+
async function getCatalogContainerObj(cache, containerId) {
|
|
36
|
+
const cloudContainer = cache.catalogContainers.get(containerId);
|
|
37
|
+
if (undefined !== cloudContainer)
|
|
38
|
+
return cloudContainer;
|
|
39
|
+
const accessLevel = cache.writeable ? "write" : "read";
|
|
40
|
+
const tokenProps = await CloudSqlite_1.CloudSqlite.getBlobService().requestToken({ containerId, accessLevel, userToken: await IModelHost_1.IModelHost.getAccessToken() });
|
|
41
|
+
const container = CloudSqlite_1.CloudSqlite.createCloudContainer({
|
|
42
|
+
accessLevel,
|
|
43
|
+
baseUri: tokenProps.baseUri,
|
|
44
|
+
containerId,
|
|
45
|
+
storageType: tokenProps.provider,
|
|
46
|
+
writeable: cache.writeable,
|
|
47
|
+
accessToken: tokenProps.token
|
|
48
|
+
});
|
|
49
|
+
cache.catalogContainers.set(containerId, container); // save the container in the map of ContainerIds so we can reuse them
|
|
50
|
+
container.connect(cache);
|
|
51
|
+
return container;
|
|
52
|
+
}
|
|
53
|
+
function getReadonlyCloudCache() { return readonlyCloudCache ??= makeCloudCache({ cacheName: "catalogs", cacheSize: "10G" }, false); }
|
|
54
|
+
;
|
|
55
|
+
function getWritableCloudCache() { return writeableCloudCache ??= makeCloudCache({ cacheName: "writeableCatalogs", cacheSize: "10G" }, true); }
|
|
56
|
+
;
|
|
57
|
+
async function getReadonlyContainer(containerId) { return getCatalogContainerObj(getReadonlyCloudCache(), containerId); }
|
|
58
|
+
;
|
|
59
|
+
async function getWriteableContainer(containerId) { return getCatalogContainerObj(getWritableCloudCache(), containerId); }
|
|
60
|
+
;
|
|
61
|
+
/** Throw an error if the write lock is not held for the supplied container */
|
|
62
|
+
function ensureLocked(container, reason) {
|
|
63
|
+
if (!container.hasWriteLock)
|
|
64
|
+
core_common_1.CloudSqliteError.throwError("write-lock-not-held", { message: `Write lock must be held to ${reason}` });
|
|
65
|
+
}
|
|
66
|
+
/** update the manifest in a CatalogIModel (calls `saveChanges`) */
|
|
67
|
+
function updateManifest(nativeDb, manifest) {
|
|
68
|
+
nativeDb.saveLocalValue(catalogManifestName, JSON.stringify(manifest));
|
|
69
|
+
nativeDb.saveChanges("update manifest");
|
|
70
|
+
}
|
|
71
|
+
function catalogDbNameWithDefault(dbName) {
|
|
72
|
+
return dbName ?? "catalog-db";
|
|
73
|
+
}
|
|
74
|
+
/** A StandaloneDb that holds a CatalogIModel */
|
|
75
|
+
class CatalogDbImpl extends IModelDb_1.StandaloneDb {
|
|
76
|
+
isEditable() {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
getManifest() {
|
|
80
|
+
const manifestString = this[Symbols_1._nativeDb].queryLocalValue(catalogManifestName);
|
|
81
|
+
if (undefined === manifestString)
|
|
82
|
+
return undefined;
|
|
83
|
+
return JSON.parse(manifestString);
|
|
84
|
+
}
|
|
85
|
+
getVersion() {
|
|
86
|
+
return CloudSqlite_1.CloudSqlite.parseDbFileName(this[Symbols_1._nativeDb].getFilePath()).version;
|
|
87
|
+
}
|
|
88
|
+
getInfo() {
|
|
89
|
+
return { manifest: this.getManifest(), version: this.getVersion() };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A CatalogDb that permits editing.
|
|
94
|
+
* This class ensures that CatalogIModels never have a Txn table when they are published.
|
|
95
|
+
* It also automatically updates the `lastEditedBy` field in the CatalogManifest.
|
|
96
|
+
*/
|
|
97
|
+
class EditableCatalogDbImpl extends CatalogDbImpl {
|
|
98
|
+
isEditable() {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
updateCatalogManifest(manifest) {
|
|
102
|
+
updateManifest(this[Symbols_1._nativeDb], manifest);
|
|
103
|
+
}
|
|
104
|
+
// Make sure the txn table is deleted and update the manifest every time we close.
|
|
105
|
+
beforeClose() {
|
|
106
|
+
try {
|
|
107
|
+
const manifest = this.getManifest();
|
|
108
|
+
const container = this.cloudContainer;
|
|
109
|
+
if (container && manifest) {
|
|
110
|
+
manifest.lastEditedBy = CloudSqlite_1.CloudSqlite.getWriteLockHeldBy(container);
|
|
111
|
+
this.updateCatalogManifest(manifest);
|
|
112
|
+
}
|
|
113
|
+
// when saved, CatalogIModels should never have any Txns. If we wanted to create a changeset, we'd have to do it here.
|
|
114
|
+
this[Symbols_1._nativeDb].deleteAllTxns();
|
|
115
|
+
}
|
|
116
|
+
catch { } // ignore errors attempting to update
|
|
117
|
+
// might also want to vacuum here?
|
|
118
|
+
super.beforeClose();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function findCatalogByKey(key) {
|
|
122
|
+
return CatalogDbImpl.findByKey(key);
|
|
123
|
+
}
|
|
124
|
+
/** @beta */
|
|
125
|
+
var CatalogDb;
|
|
126
|
+
(function (CatalogDb) {
|
|
127
|
+
/** Create a new [[BlobContainer]] to hold versions of a [[CatalogDb]].
|
|
128
|
+
* @returns The properties of the newly created container.
|
|
129
|
+
* @note creating new containers requires "admin" authorization.
|
|
130
|
+
*/
|
|
131
|
+
async function createNewContainer(args) {
|
|
132
|
+
const dbName = catalogDbNameWithDefault(args.dbName);
|
|
133
|
+
CloudSqlite_1.CloudSqlite.validateDbName(dbName);
|
|
134
|
+
CloudSqlite_1.CloudSqlite.validateDbVersion(args.version);
|
|
135
|
+
const tmpName = (0, path_1.join)(IModelHost_1.KnownLocations.tmpdir, `temp-${dbName}`);
|
|
136
|
+
try {
|
|
137
|
+
// make a copy of the file they supplied so we can modify its contents safely
|
|
138
|
+
fs.copyFileSync(args.localCatalogFile, tmpName);
|
|
139
|
+
const nativeDb = new NativePlatform_1.IModelNative.platform.DgnDb();
|
|
140
|
+
nativeDb.openIModel(tmpName, core_bentley_1.OpenMode.ReadWrite);
|
|
141
|
+
nativeDb.setITwinId(core_bentley_1.Guid.empty); // catalogs must be a StandaloneDb
|
|
142
|
+
nativeDb.setIModelId(core_bentley_1.Guid.createValue()); // make sure its iModelId is unique
|
|
143
|
+
updateManifest(nativeDb, args.manifest); // store the manifest inside the Catalog
|
|
144
|
+
nativeDb.deleteAllTxns(); // Catalogs should never have Txns (and, this must be empty before resetting BriefcaseId)
|
|
145
|
+
nativeDb.resetBriefcaseId(core_common_1.BriefcaseIdValue.Unassigned); // catalogs should always be unassigned
|
|
146
|
+
nativeDb.saveChanges(); // save change to briefcaseId
|
|
147
|
+
nativeDb.vacuum();
|
|
148
|
+
nativeDb.closeFile();
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
core_common_1.CatalogError.throwError("invalid-seed-catalog", { message: "Illegal seed catalog", ...args, cause: e });
|
|
152
|
+
}
|
|
153
|
+
const userToken = await IModelHost_1.IModelHost.getAccessToken();
|
|
154
|
+
// create tne new container from the blob service, requires "admin" authorization
|
|
155
|
+
const cloudContainerProps = await CloudSqlite_1.CloudSqlite.getBlobService().create({ scope: { iTwinId: args.iTwinId }, metadata: { ...args.metadata, containerType: "CatalogIModel" }, userToken });
|
|
156
|
+
// now create a CloudSqlite container object to access it
|
|
157
|
+
const container = CloudSqlite_1.CloudSqlite.createCloudContainer({
|
|
158
|
+
accessToken: await CloudSqlite_1.CloudSqlite.requestToken(cloudContainerProps),
|
|
159
|
+
accessLevel: "admin",
|
|
160
|
+
writeable: true,
|
|
161
|
+
baseUri: cloudContainerProps.baseUri,
|
|
162
|
+
containerId: cloudContainerProps.containerId,
|
|
163
|
+
storageType: cloudContainerProps.provider,
|
|
164
|
+
});
|
|
165
|
+
// initialize the container for use by CloudSqlite
|
|
166
|
+
container.initializeContainer({ blockSize: 4 * 1024 * 1024 });
|
|
167
|
+
container.connect(getWritableCloudCache());
|
|
168
|
+
// upload the initial version of the Catalog
|
|
169
|
+
await CloudSqlite_1.CloudSqlite.withWriteLock({ user: "initialize", container }, async () => {
|
|
170
|
+
await CloudSqlite_1.CloudSqlite.uploadDb(container, { dbName: CloudSqlite_1.CloudSqlite.makeSemverName(dbName, args.version), localFileName: tmpName });
|
|
171
|
+
fs.unlinkSync(tmpName); // delete temporary copy of catalog
|
|
172
|
+
});
|
|
173
|
+
container.disconnect();
|
|
174
|
+
return cloudContainerProps;
|
|
175
|
+
}
|
|
176
|
+
CatalogDb.createNewContainer = createNewContainer;
|
|
177
|
+
/** Acquire the write lock for a [CatalogIModel]($common) container. Only one person may obtain the write lock at a time.
|
|
178
|
+
* You must obtain the lock before attempting to write to the container via functions like [[CatalogDb.openEditable]] and [[CatalogDb.createNewVersion]].
|
|
179
|
+
* @note This requires "write" authorization to the container
|
|
180
|
+
*/
|
|
181
|
+
async function acquireWriteLock(args) {
|
|
182
|
+
const container = await getWriteableContainer(args.containerId);
|
|
183
|
+
return CloudSqlite_1.CloudSqlite.acquireWriteLock({ container, user: args.username });
|
|
184
|
+
}
|
|
185
|
+
CatalogDb.acquireWriteLock = acquireWriteLock;
|
|
186
|
+
/** Release the write lock on a [CatalogIModel]($common) container. This uploads all changes made while the lock is held, so they become visible to other users. */
|
|
187
|
+
async function releaseWriteLock(args) {
|
|
188
|
+
const container = await getWriteableContainer(args.containerId);
|
|
189
|
+
if (args.abandon)
|
|
190
|
+
container.abandonChanges();
|
|
191
|
+
CloudSqlite_1.CloudSqlite.releaseWriteLock(container);
|
|
192
|
+
}
|
|
193
|
+
CatalogDb.releaseWriteLock = releaseWriteLock;
|
|
194
|
+
/** Open an [[EditableCatalogDb]] for write access.
|
|
195
|
+
* @note Once a version of a catalog iModel has been published (i.e. the write lock has been released), it is no longer editable, *unless* it is a prerelease version.
|
|
196
|
+
* @note The write lock must be held for this operation to succeed
|
|
197
|
+
*/
|
|
198
|
+
async function openEditable(args) {
|
|
199
|
+
const dbName = catalogDbNameWithDefault(args.dbName);
|
|
200
|
+
if (undefined === args.containerId) // local file?
|
|
201
|
+
return EditableCatalogDbImpl.openFile(dbName, core_bentley_1.OpenMode.ReadWrite, args);
|
|
202
|
+
const container = await getWriteableContainer(args.containerId);
|
|
203
|
+
ensureLocked(container, "open a Catalog for editing"); // editing Catalogs requires the write lock
|
|
204
|
+
// look up the full name with version
|
|
205
|
+
const dbFullName = CloudSqlite_1.CloudSqlite.querySemverMatch({ container, dbName, version: args.version ?? "*" });
|
|
206
|
+
if (!CloudSqlite_1.CloudSqlite.isSemverEditable(dbFullName, container))
|
|
207
|
+
core_common_1.CloudSqliteError.throwError("already-published", { message: "Catalog has already been published and is not editable. Make a new version first.", ...args });
|
|
208
|
+
if (args.prefetch)
|
|
209
|
+
CloudSqlite_1.CloudSqlite.startCloudPrefetch(container, dbFullName);
|
|
210
|
+
return EditableCatalogDbImpl.openFile(dbFullName, core_bentley_1.OpenMode.ReadWrite, { container, ...args });
|
|
211
|
+
}
|
|
212
|
+
CatalogDb.openEditable = openEditable;
|
|
213
|
+
/** Open a [[CatalogDb]] for read-only access. */
|
|
214
|
+
async function openReadonly(args) {
|
|
215
|
+
const dbName = catalogDbNameWithDefault(args.dbName);
|
|
216
|
+
if (undefined === args.containerId) // local file?
|
|
217
|
+
return CatalogDbImpl.openFile(dbName, core_bentley_1.OpenMode.Readonly, args);
|
|
218
|
+
const container = await getReadonlyContainer(args.containerId);
|
|
219
|
+
if (args.syncWithCloud)
|
|
220
|
+
container.checkForChanges();
|
|
221
|
+
const dbFullName = CloudSqlite_1.CloudSqlite.querySemverMatch({ container, ...args, dbName });
|
|
222
|
+
if (args.prefetch)
|
|
223
|
+
CloudSqlite_1.CloudSqlite.startCloudPrefetch(container, dbFullName);
|
|
224
|
+
return CatalogDbImpl.openFile(dbFullName, core_bentley_1.OpenMode.Readonly, { container, ...args });
|
|
225
|
+
}
|
|
226
|
+
CatalogDb.openReadonly = openReadonly;
|
|
227
|
+
/**
|
|
228
|
+
* Create a new version of a [CatalogIModel]($common) as a copy of an existing version. Immediately after this operation, the new version will be an exact copy
|
|
229
|
+
* of the source CatalogIModel. Then, use [[CatalogDb.openEditable]] to modify the new version with new content.
|
|
230
|
+
* @note The write lock must be held for this operation to succeed
|
|
231
|
+
*/
|
|
232
|
+
async function createNewVersion(args) {
|
|
233
|
+
const container = await getWriteableContainer(args.containerId);
|
|
234
|
+
ensureLocked(container, "create a new version");
|
|
235
|
+
return CloudSqlite_1.CloudSqlite.createNewDbVersion(container, { ...args, fromDb: { ...args.fromDb, dbName: catalogDbNameWithDefault(args.fromDb.dbName) } });
|
|
236
|
+
}
|
|
237
|
+
CatalogDb.createNewVersion = createNewVersion;
|
|
238
|
+
})(CatalogDb || (exports.CatalogDb = CatalogDb = {}));
|
|
239
|
+
/**
|
|
240
|
+
* Handler for Ipc access to CatalogIModels. Registered by NativeHost.
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
243
|
+
class CatalogIModelHandler extends IpcHost_1.IpcHandler {
|
|
244
|
+
get channelName() { return "catalogIModel/ipc"; }
|
|
245
|
+
async createNewContainer(args) {
|
|
246
|
+
return CatalogDb.createNewContainer(args);
|
|
247
|
+
}
|
|
248
|
+
async acquireWriteLock(args) {
|
|
249
|
+
return CatalogDb.acquireWriteLock(args);
|
|
250
|
+
}
|
|
251
|
+
async releaseWriteLock(args) {
|
|
252
|
+
return CatalogDb.releaseWriteLock(args);
|
|
253
|
+
}
|
|
254
|
+
async openReadonly(args) {
|
|
255
|
+
return ((await CatalogDb.openReadonly(args)).getConnectionProps());
|
|
256
|
+
}
|
|
257
|
+
async openEditable(args) {
|
|
258
|
+
return (await CatalogDb.openEditable(args)).getConnectionProps();
|
|
259
|
+
}
|
|
260
|
+
async createNewVersion(args) {
|
|
261
|
+
return CatalogDb.createNewVersion(args);
|
|
262
|
+
}
|
|
263
|
+
async getInfo(key) {
|
|
264
|
+
return findCatalogByKey(key).getInfo();
|
|
265
|
+
}
|
|
266
|
+
async updateCatalogManifest(key, manifest) {
|
|
267
|
+
findCatalogByKey(key).updateCatalogManifest(manifest);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.CatalogIModelHandler = CatalogIModelHandler;
|
|
271
|
+
//# sourceMappingURL=CatalogDb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogDb.js","sourceRoot":"","sources":["../../src/CatalogDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yBAAyB;AACzB,+BAA4B;AAC5B,+CAA4C;AAC5C,6CAA0D;AAC1D,o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,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IACM,KAAK,CAAC,YAAY,CAAC,IAA4B;QACpD,OAAO,CAAC,CAAC,MAAM,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACrE,CAAC;IACM,KAAK,CAAC,YAAY,CAAC,IAA4B;QACpD,OAAO,CAAC,MAAM,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACnE,CAAC;IACM,KAAK,CAAC,gBAAgB,CAAC,IAAwC;QACpE,OAAO,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IACM,KAAK,CAAC,OAAO,CAAC,GAAW;QAC9B,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IACzC,CAAC;IACM,KAAK,CAAC,qBAAqB,CAAC,GAAW,EAAE,QAAgC;QAC9E,gBAAgB,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;CACF;AA3BD,oDA2BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\nimport * as fs from \"fs\";\nimport { join } from \"path\";\nimport { CloudSqlite } from \"./CloudSqlite\";\nimport { IModelHost, KnownLocations } from \"./IModelHost\";\nimport { BriefcaseIdValue, CatalogError, type CatalogIModel, CloudSqliteError, IModelConnectionProps } from \"@itwin/core-common\";\nimport { IpcHandler } from \"./IpcHost\";\nimport { StandaloneDb } from \"./IModelDb\";\nimport { Guid, OpenMode } from \"@itwin/core-bentley\";\nimport { _nativeDb } from \"./internal/Symbols\";\nimport { IModelNative } from \"./internal/NativePlatform\";\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\n\ninterface CatalogCloudCache extends CloudSqlite.CloudCache {\n writeable: boolean;\n catalogContainers: Map<string, CloudSqlite.CloudContainer>;\n}\n\nlet readonlyCloudCache: CatalogCloudCache | undefined;\nlet writeableCloudCache: CatalogCloudCache | undefined;\nconst catalogManifestName = \"CatalogManifest\";\n\n// we make a readonly CloudCache and a writeable CloudCache. That way the access token authorizations are distinct.\nfunction makeCloudCache(arg: CloudSqlite.CreateCloudCacheArg, writeable: boolean) {\n const cache = CloudSqlite.CloudCaches.getCache(arg) as CatalogCloudCache;\n // if the cache was just created, add the \"catalog\" members as hidden\n if (undefined === cache.catalogContainers) {\n CloudSqlite.addHiddenProperty(cache, \"catalogContainers\", new Map<string, CloudSqlite.CloudContainer>());\n CloudSqlite.addHiddenProperty(cache, \"writeable\", writeable);\n }\n return cache;\n}\n\n// find an existing CloudContainer for accessing a CatalogIModel, or make a new one and connect it\nasync function getCatalogContainerObj(cache: CatalogCloudCache, containerId: string): Promise<CloudSqlite.CloudContainer> {\n const cloudContainer = cache.catalogContainers.get(containerId);\n if (undefined !== cloudContainer)\n return cloudContainer;\n\n const accessLevel = cache.writeable ? \"write\" : \"read\";\n const tokenProps = await CloudSqlite.getBlobService().requestToken({ containerId, accessLevel, userToken: await IModelHost.getAccessToken() });\n const container = CloudSqlite.createCloudContainer({\n accessLevel,\n baseUri: tokenProps.baseUri,\n containerId,\n storageType: tokenProps.provider,\n writeable: cache.writeable,\n accessToken: tokenProps.token\n });\n cache.catalogContainers.set(containerId, container); // save the container in the map of ContainerIds so we can reuse them\n container.connect(cache);\n return container;\n}\n\nfunction getReadonlyCloudCache() { return readonlyCloudCache ??= makeCloudCache({ cacheName: \"catalogs\", cacheSize: \"10G\" }, false) };\nfunction getWritableCloudCache() { return writeableCloudCache ??= makeCloudCache({ cacheName: \"writeableCatalogs\", cacheSize: \"10G\" }, true) };\nasync function getReadonlyContainer(containerId: string) { return getCatalogContainerObj(getReadonlyCloudCache(), containerId) };\nasync function getWriteableContainer(containerId: string) { return getCatalogContainerObj(getWritableCloudCache(), containerId) };\n\n/** Throw an error if the write lock is not held for the supplied container */\nfunction ensureLocked(container: CloudSqlite.CloudContainer, reason: string) {\n if (!container.hasWriteLock)\n CloudSqliteError.throwError(\"write-lock-not-held\", { message: `Write lock must be held to ${reason}` });\n}\n/** update the manifest in a CatalogIModel (calls `saveChanges`) */\nfunction updateManifest(nativeDb: IModelJsNative.DgnDb, manifest: CatalogIModel.Manifest) {\n nativeDb.saveLocalValue(catalogManifestName, JSON.stringify(manifest));\n nativeDb.saveChanges(\"update manifest\");\n}\nfunction catalogDbNameWithDefault(dbName?: string): string {\n return dbName ?? \"catalog-db\";\n}\n\n/** A [[StandaloneDb]] that provides read-only access to the contents of a [CatalogIModel]($common).\n * @see [[CatalogDb.openReadonly]] to instantiate this type.\n * @beta\n */\nexport interface CatalogDb extends StandaloneDb {\n /** Get the catalog's manifest. */\n getManifest(): CatalogIModel.Manifest | undefined;\n /** Get the catalog's version information. */\n getVersion(): string;\n /** Get the catalog's manifest and version. */\n getInfo(): { manifest?: CatalogIModel.Manifest, version: string };\n /** Returns true if the catalog was opened in read-write mode. */\n isEditable(): this is EditableCatalogDb;\n}\n\n/** A writable [[CatalogDb]].\n * @see [[CatalogDb.openEditable]] to instantiate this type.\n * @beta\n */\nexport interface EditableCatalogDb extends CatalogDb {\n /** Update the contents of the catalog manifest. */\n updateCatalogManifest(manifest: CatalogIModel.Manifest): void;\n}\n\n/** A StandaloneDb that holds a CatalogIModel */\nclass CatalogDbImpl extends StandaloneDb implements CatalogDb {\n public isEditable(): this is EditableCatalogDb {\n return false;\n }\n\n public getManifest(): CatalogIModel.Manifest | undefined {\n const manifestString = this[_nativeDb].queryLocalValue(catalogManifestName);\n if (undefined === manifestString)\n return undefined;\n return JSON.parse(manifestString) as CatalogIModel.Manifest;\n }\n\n public getVersion(): string {\n return CloudSqlite.parseDbFileName(this[_nativeDb].getFilePath()).version;\n }\n\n public getInfo() {\n return { manifest: this.getManifest(), version: this.getVersion() };\n }\n}\n\n/**\n * A CatalogDb that permits editing.\n * This class ensures that CatalogIModels never have a Txn table when they are published.\n * It also automatically updates the `lastEditedBy` field in the CatalogManifest.\n */\nclass EditableCatalogDbImpl extends CatalogDbImpl implements EditableCatalogDb {\n public override isEditable(): this is EditableCatalogDb {\n return true;\n }\n\n public updateCatalogManifest(manifest: CatalogIModel.Manifest): void {\n updateManifest(this[_nativeDb], manifest);\n }\n\n // Make sure the txn table is deleted and update the manifest every time we close.\n public override beforeClose(): void {\n try {\n const manifest = this.getManifest();\n const container = this.cloudContainer;\n if (container && manifest) {\n manifest.lastEditedBy = CloudSqlite.getWriteLockHeldBy(container);\n this.updateCatalogManifest(manifest);\n }\n\n // when saved, CatalogIModels should never have any Txns. If we wanted to create a changeset, we'd have to do it here.\n this[_nativeDb].deleteAllTxns();\n } catch { } // ignore errors attempting to update\n\n // might also want to vacuum here?\n super.beforeClose();\n }\n}\n\nfunction findCatalogByKey(key: string): CatalogDbImpl & EditableCatalogDb {\n return CatalogDbImpl.findByKey(key) as CatalogDbImpl & EditableCatalogDb;\n}\n\n/** @beta */\nexport namespace CatalogDb {\n /** Create a new [[BlobContainer]] to hold versions of a [[CatalogDb]].\n * @returns The properties of the newly created container.\n * @note creating new containers requires \"admin\" authorization.\n */\n export async function createNewContainer(args: CatalogIModel.CreateNewContainerArgs): Promise<CatalogIModel.NewContainerProps> {\n const dbName = catalogDbNameWithDefault(args.dbName);\n CloudSqlite.validateDbName(dbName);\n CloudSqlite.validateDbVersion(args.version);\n\n const tmpName = join(KnownLocations.tmpdir, `temp-${dbName}`);\n try {\n // make a copy of the file they supplied so we can modify its contents safely\n fs.copyFileSync(args.localCatalogFile, tmpName);\n const nativeDb = new IModelNative.platform.DgnDb();\n nativeDb.openIModel(tmpName, OpenMode.ReadWrite);\n nativeDb.setITwinId(Guid.empty); // catalogs must be a StandaloneDb\n nativeDb.setIModelId(Guid.createValue()); // make sure its iModelId is unique\n updateManifest(nativeDb, args.manifest); // store the manifest inside the Catalog\n nativeDb.deleteAllTxns(); // Catalogs should never have Txns (and, this must be empty before resetting BriefcaseId)\n nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned); // catalogs should always be unassigned\n nativeDb.saveChanges(); // save change to briefcaseId\n nativeDb.vacuum();\n nativeDb.closeFile();\n } catch (e: unknown) {\n CatalogError.throwError(\"invalid-seed-catalog\", { message: \"Illegal seed catalog\", ...args, cause: e });\n }\n\n const userToken = await IModelHost.getAccessToken();\n // create tne new container from the blob service, requires \"admin\" authorization\n const cloudContainerProps = await CloudSqlite.getBlobService().create({ scope: { iTwinId: args.iTwinId }, metadata: { ...args.metadata, containerType: \"CatalogIModel\" }, userToken });\n\n // now create a CloudSqlite container object to access it\n const container = CloudSqlite.createCloudContainer({\n accessToken: await CloudSqlite.requestToken(cloudContainerProps),\n accessLevel: \"admin\",\n writeable: true,\n baseUri: cloudContainerProps.baseUri,\n containerId: cloudContainerProps.containerId,\n storageType: cloudContainerProps.provider,\n });\n\n // initialize the container for use by CloudSqlite\n container.initializeContainer({ blockSize: 4 * 1024 * 1024 });\n container.connect(getWritableCloudCache());\n\n // upload the initial version of the Catalog\n await CloudSqlite.withWriteLock({ user: \"initialize\", container }, async () => {\n await CloudSqlite.uploadDb(container, { dbName: CloudSqlite.makeSemverName(dbName, args.version), localFileName: tmpName });\n fs.unlinkSync(tmpName); // delete temporary copy of catalog\n });\n container.disconnect();\n return cloudContainerProps;\n }\n\n /** Acquire the write lock for a [CatalogIModel]($common) container. Only one person may obtain the write lock at a time.\n * You must obtain the lock before attempting to write to the container via functions like [[CatalogDb.openEditable]] and [[CatalogDb.createNewVersion]].\n * @note This requires \"write\" authorization to the container\n */\n export async function acquireWriteLock(args: {\n /** The id of the container */\n containerId: string,\n /**\n * The name of the individual acquiring the lock. This will be shown to others who attempt to acquire the lock while it is held.\n * It is also stored in the \"lastEditedBy\" field of the manifest of any new version edited while the lock is held.\n */\n username: string;\n }): Promise<void> {\n const container = await getWriteableContainer(args.containerId);\n return CloudSqlite.acquireWriteLock({ container, user: args.username });\n }\n\n /** Release the write lock on a [CatalogIModel]($common) container. This uploads all changes made while the lock is held, so they become visible to other users. */\n export async function releaseWriteLock(args: {\n /** The id of the container */\n containerId: string,\n /** If true, abandon all local changes before releasing the lock */\n abandon?: true\n }): Promise<void> {\n const container = await getWriteableContainer(args.containerId);\n if (args.abandon)\n container.abandonChanges();\n CloudSqlite.releaseWriteLock(container);\n }\n\n /** Open an [[EditableCatalogDb]] for write access.\n * @note Once a version of a catalog iModel has been published (i.e. the write lock has been released), it is no longer editable, *unless* it is a prerelease version.\n * @note The write lock must be held for this operation to succeed\n */\n export async function openEditable(args: CatalogIModel.OpenArgs): Promise<EditableCatalogDb> {\n const dbName = catalogDbNameWithDefault(args.dbName);\n if (undefined === args.containerId) // local file?\n return EditableCatalogDbImpl.openFile(dbName, OpenMode.ReadWrite, args) as EditableCatalogDbImpl;\n\n const container = await getWriteableContainer(args.containerId);\n ensureLocked(container, \"open a Catalog for editing\"); // editing Catalogs requires the write lock\n\n // look up the full name with version\n const dbFullName = CloudSqlite.querySemverMatch({ container, dbName, version: args.version ?? \"*\" });\n if (!CloudSqlite.isSemverEditable(dbFullName, container))\n CloudSqliteError.throwError(\"already-published\", { message: \"Catalog has already been published and is not editable. Make a new version first.\", ...args })\n\n if (args.prefetch)\n CloudSqlite.startCloudPrefetch(container, dbFullName);\n\n return EditableCatalogDbImpl.openFile(dbFullName, OpenMode.ReadWrite, { container, ...args }) as EditableCatalogDbImpl;\n }\n\n /** Open a [[CatalogDb]] for read-only access. */\n export async function openReadonly(args: CatalogIModel.OpenArgs): Promise<CatalogDb> {\n const dbName = catalogDbNameWithDefault(args.dbName);\n if (undefined === args.containerId) // local file?\n return CatalogDbImpl.openFile(dbName, OpenMode.Readonly, args) as CatalogDbImpl;\n\n const container = await getReadonlyContainer(args.containerId);\n if (args.syncWithCloud)\n container.checkForChanges();\n\n const dbFullName = CloudSqlite.querySemverMatch({ container, ...args, dbName });\n if (args.prefetch)\n CloudSqlite.startCloudPrefetch(container, dbFullName);\n\n return CatalogDbImpl.openFile(dbFullName, OpenMode.Readonly, { container, ...args }) as CatalogDbImpl;\n }\n\n /**\n * Create a new version of a [CatalogIModel]($common) as a copy of an existing version. Immediately after this operation, the new version will be an exact copy\n * of the source CatalogIModel. Then, use [[CatalogDb.openEditable]] to modify the new version with new content.\n * @note The write lock must be held for this operation to succeed\n */\n export async function createNewVersion(args: CatalogIModel.CreateNewVersionArgs): Promise<{ oldDb: CatalogIModel.NameAndVersion; newDb: CatalogIModel.NameAndVersion; }> {\n const container = await getWriteableContainer(args.containerId);\n ensureLocked(container, \"create a new version\");\n return CloudSqlite.createNewDbVersion(container, { ...args, fromDb: { ...args.fromDb, dbName: catalogDbNameWithDefault(args.fromDb.dbName) } });\n }\n}\n\n/**\n * Handler for Ipc access to CatalogIModels. Registered by NativeHost.\n * @internal\n */\nexport class CatalogIModelHandler extends IpcHandler implements CatalogIModel.IpcMethods {\n public get channelName(): CatalogIModel.IpcChannel { return \"catalogIModel/ipc\"; }\n\n public async createNewContainer(args: CatalogIModel.CreateNewContainerArgs): Promise<CatalogIModel.NewContainerProps> {\n return CatalogDb.createNewContainer(args);\n }\n public async acquireWriteLock(args: { containerId: string, username: string; }): Promise<void> {\n return CatalogDb.acquireWriteLock(args);\n }\n public async releaseWriteLock(args: { containerId: string, abandon?: true; }): Promise<void> {\n return CatalogDb.releaseWriteLock(args);\n }\n public async openReadonly(args: CatalogIModel.OpenArgs): Promise<IModelConnectionProps> {\n return ((await CatalogDb.openReadonly(args)).getConnectionProps());\n }\n public async openEditable(args: CatalogIModel.OpenArgs): Promise<IModelConnectionProps> {\n return (await CatalogDb.openEditable(args)).getConnectionProps();\n }\n public async createNewVersion(args: CatalogIModel.CreateNewVersionArgs): Promise<{ oldDb: CatalogIModel.NameAndVersion; newDb: CatalogIModel.NameAndVersion; }> {\n return CatalogDb.createNewVersion(args);\n }\n public async getInfo(key: string): Promise<{ manifest?: CatalogIModel.Manifest, version: string }> {\n return findCatalogByKey(key).getInfo();\n }\n public async updateCatalogManifest(key: string, manifest: CatalogIModel.Manifest): Promise<void> {\n findCatalogByKey(key).updateCatalogManifest(manifest);\n }\n}\n"]}
|
package/lib/cjs/CloudSqlite.d.ts
CHANGED
|
@@ -11,11 +11,20 @@ import type { SQLiteDb, VersionedSqliteDb } from "./SQLiteDb";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare namespace CloudSqlite {
|
|
13
13
|
export type RequestTokenArgs = Optional<BlobContainer.RequestTokenProps, "userToken">;
|
|
14
|
+
/** Add (or replace) a property to an object that is not enumerable.
|
|
15
|
+
* This is important so this member will be skipped when the object is the target of
|
|
16
|
+
* [structuredClone](https://developer.mozilla.org/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
17
|
+
* (e.g. when the object is part of an exception that is marshalled across process boundaries.)
|
|
18
|
+
*/
|
|
19
|
+
export function addHiddenProperty<T>(o: T, p: PropertyKey, value?: any): T;
|
|
20
|
+
export function getBlobService(): BlobContainer.ContainerService;
|
|
14
21
|
/**
|
|
15
22
|
* Request a new AccessToken for a cloud container using the [[BlobContainer]] service.
|
|
16
23
|
* If the service is unavailable or returns an error, an empty token is returned.
|
|
17
24
|
*/
|
|
18
25
|
export function requestToken(args: RequestTokenArgs): Promise<AccessToken>;
|
|
26
|
+
export function noLeadingOrTrailingSpaces(name: string, msg: string): void;
|
|
27
|
+
export function validateDbName(dbName: DbName): void;
|
|
19
28
|
/**
|
|
20
29
|
* Create a new CloudContainer from a ContainerAccessProps. For non-public containers, a valid accessToken must be provided before the container
|
|
21
30
|
* can be used (e.g. via [[CloudSqlite.requestToken]]).
|
|
@@ -135,16 +144,65 @@ export declare namespace CloudSqlite {
|
|
|
135
144
|
/** The total number of attached containers on this cache. */
|
|
136
145
|
readonly attachedContainers?: number;
|
|
137
146
|
}
|
|
147
|
+
/** The base name of a CloudSqlite database, without any version information.
|
|
148
|
+
* The name must conform to the following constraints:
|
|
149
|
+
* - Case-insensitively unique among all databases in the same [[CloudSqlite.CloudContainer]]
|
|
150
|
+
* - Between 1 and 255 characters in length.
|
|
151
|
+
* - A legal filename on both [Windows](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions) and UNIX.
|
|
152
|
+
* - Contain none of the following characters: forward or backward slash, period, single or double quote, backtick, colon, and "#".
|
|
153
|
+
* - Begin or end with a whitespace character.
|
|
154
|
+
* @see [[CloudSqlite.DbFullName]] for the fully-specified name, including version information.
|
|
155
|
+
*/
|
|
156
|
+
export type DbName = string;
|
|
157
|
+
/** The fully-specified name of a CloudSqlite database, combining its [[CloudSqlite.DbName]] and [[CloudSqlite.DbVersion]] in the format "name:version".
|
|
158
|
+
*/
|
|
159
|
+
export type DbFullName = string;
|
|
160
|
+
/** A [semver](https://github.com/npm/node-semver) string describing the version of a database, e.g., "4.2.11".
|
|
161
|
+
*/
|
|
162
|
+
export type DbVersion = string;
|
|
163
|
+
/** A [semver string](https://github.com/npm/node-semver?tab=readme-ov-file#ranges) describing a range of acceptable versions,
|
|
164
|
+
* e.g., ">=1.2.7 <1.3.0".
|
|
165
|
+
*/
|
|
166
|
+
export type DbVersionRange = string;
|
|
167
|
+
/** Specifies the name and version of a CloudSqlite database.
|
|
168
|
+
*/
|
|
169
|
+
export interface DbNameAndVersion {
|
|
170
|
+
/** The name of the database */
|
|
171
|
+
readonly dbName: DbName;
|
|
172
|
+
/** The range of acceptable versions of the database of the specified [[dbName]].
|
|
173
|
+
* If omitted, it defaults to the newest available version.
|
|
174
|
+
*/
|
|
175
|
+
readonly version?: DbVersionRange;
|
|
176
|
+
}
|
|
177
|
+
export interface LoadProps extends DbNameAndVersion {
|
|
178
|
+
readonly container: CloudContainer;
|
|
179
|
+
/** If true, allow semver [prerelease versions](https://github.com/npm/node-semver?tab=readme-ov-file#prerelease-tags), e.g., "1.4.2-beta.0".
|
|
180
|
+
* By default, only released version are allowed.
|
|
181
|
+
*/
|
|
182
|
+
readonly includePrerelease?: boolean;
|
|
183
|
+
/** If true, start a prefetch operation whenever this database is opened, to begin downloading pages of the database before they are needed. */
|
|
184
|
+
readonly prefetch?: boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The release increment for a version number, used as part of [[CloudSqlite.CreateNewDbVersionArgs]] to specify the kind of version to create.
|
|
188
|
+
* @see [semver.ReleaseType](https://www.npmjs.com/package/semver)
|
|
189
|
+
*/
|
|
190
|
+
export type SemverIncrement = "major" | "minor" | "patch" | "premajor" | "preminor" | "prepatch" | "prerelease";
|
|
191
|
+
/**
|
|
192
|
+
* Arguments supplied to [[CloudSqlite.createNewDbVersion]].
|
|
193
|
+
*/
|
|
194
|
+
export interface CreateNewDbVersionArgs {
|
|
195
|
+
readonly fromDb: DbNameAndVersion;
|
|
196
|
+
/** The type of version increment to apply to the source version. */
|
|
197
|
+
readonly versionType: SemverIncrement;
|
|
198
|
+
/** For prerelease versions, a string that becomes part of the version name. */
|
|
199
|
+
readonly identifier?: string;
|
|
200
|
+
}
|
|
138
201
|
/** The name of a CloudSqlite database within a CloudContainer. */
|
|
139
202
|
export interface DbNameProp {
|
|
140
203
|
/** the name of the database within the CloudContainer.
|
|
141
204
|
* @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/
|
|
142
|
-
dbName:
|
|
143
|
-
}
|
|
144
|
-
/** Properties for accessing a database within a CloudContainer */
|
|
145
|
-
export interface DbProps extends DbNameProp {
|
|
146
|
-
/** the name of the local file to access the database. */
|
|
147
|
-
localFileName: LocalFileName;
|
|
205
|
+
dbName: DbFullName;
|
|
148
206
|
}
|
|
149
207
|
export type TransferDirection = "upload" | "download";
|
|
150
208
|
export interface TransferProgress {
|
|
@@ -161,7 +219,10 @@ export declare namespace CloudSqlite {
|
|
|
161
219
|
/** The number of prefetch requests to issue while there is foreground activity. Default is 3. */
|
|
162
220
|
minRequests?: number;
|
|
163
221
|
}
|
|
164
|
-
export
|
|
222
|
+
export interface TransferDbProps extends DbNameProp, TransferProgress, CloudHttpProps {
|
|
223
|
+
/** the name of the local file to access the database for uploading and downloading */
|
|
224
|
+
localFileName: LocalFileName;
|
|
225
|
+
}
|
|
165
226
|
/** Properties for creating a CloudCache. */
|
|
166
227
|
export interface CacheProps extends CloudHttpProps {
|
|
167
228
|
/** full path of directory for cache to store its files. Must be on a (preferably fast) local drive, and must be empty when the cache is first created. */
|
|
@@ -517,25 +578,48 @@ export declare namespace CloudSqlite {
|
|
|
517
578
|
container: CloudContainer;
|
|
518
579
|
busyHandler?: WriteLockBusyHandler;
|
|
519
580
|
}): Promise<void>;
|
|
581
|
+
export function getWriteLockHeldBy(container: CloudContainer): string | undefined;
|
|
582
|
+
/** release the write lock on a container. */
|
|
583
|
+
export function releaseWriteLock(container: CloudContainer): void;
|
|
520
584
|
/**
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
585
|
+
* Perform an asynchronous write operation on a CloudContainer with the write lock held.
|
|
586
|
+
* 1. if write lock is already held by the current user, refresh write lock's expiry time, call operation and return.
|
|
587
|
+
* 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
|
|
588
|
+
* 3. perform the operation
|
|
589
|
+
* 3.a if the operation throws, abandon all changes and re-throw
|
|
590
|
+
* 4. release the write lock.
|
|
591
|
+
* 5. return value from operation
|
|
592
|
+
* @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
|
|
593
|
+
* @param container the CloudContainer for which the lock is to be acquired
|
|
594
|
+
* @param operation an asynchronous operation performed with the write lock held.
|
|
595
|
+
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
596
|
+
* @returns a Promise with the result of `operation`
|
|
597
|
+
*/
|
|
534
598
|
export function withWriteLock<T>(args: {
|
|
535
599
|
user: string;
|
|
536
600
|
container: CloudContainer;
|
|
537
601
|
busyHandler?: WriteLockBusyHandler;
|
|
538
602
|
}, operation: () => Promise<T>): Promise<T>;
|
|
603
|
+
/**
|
|
604
|
+
* Parse the name of a Db stored in a CloudContainer into the dbName and version number. A single CloudContainer may hold
|
|
605
|
+
* many versions of the same Db. The name of the Db in the CloudContainer is in the format "name:version". This
|
|
606
|
+
* function splits them into separate strings.
|
|
607
|
+
*/
|
|
608
|
+
export function parseDbFileName(dbFileName: DbFullName): {
|
|
609
|
+
dbName: DbName;
|
|
610
|
+
version: DbVersion;
|
|
611
|
+
};
|
|
612
|
+
export function validateDbVersion(version?: DbVersion): string;
|
|
613
|
+
export function isSemverPrerelease(version: string): true | readonly (string | number)[] | null;
|
|
614
|
+
export function isSemverEditable(dbFullName: string, container: CloudContainer): boolean | readonly (string | number)[];
|
|
615
|
+
/** Create a dbName for a database from its base name and version. This will be in the format "name:version" */
|
|
616
|
+
export function makeSemverName(dbName: DbName, version?: DbVersion): DbName;
|
|
617
|
+
/** query the databases in the supplied container for the highest SemVer match according to the version range. Throws if no version available for the range. */
|
|
618
|
+
export function querySemverMatch(props: LoadProps): DbFullName;
|
|
619
|
+
export function createNewDbVersion(container: CloudContainer, args: CreateNewDbVersionArgs): Promise<{
|
|
620
|
+
oldDb: DbNameAndVersion;
|
|
621
|
+
newDb: DbNameAndVersion;
|
|
622
|
+
}>;
|
|
539
623
|
/** Arguments to create or find a CloudCache */
|
|
540
624
|
export interface CreateCloudCacheArg {
|
|
541
625
|
/** The name of the CloudCache. CloudCache names must be unique. */
|