@itwin/core-backend 3.0.0-dev.148 → 3.0.0-dev.153
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/BackendHubAccess.d.ts +1 -1
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +2 -0
- package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
- package/lib/cjs/ChangedElementsDb.js +1 -1
- package/lib/cjs/ChangedElementsDb.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +25 -11
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +52 -3
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +1 -1
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +1 -1
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/ServerBasedLocks.d.ts +4 -10
- package/lib/cjs/ServerBasedLocks.d.ts.map +1 -1
- package/lib/cjs/ServerBasedLocks.js +11 -19
- package/lib/cjs/ServerBasedLocks.js.map +1 -1
- package/lib/cjs/workspace/CloudSqlite.d.ts +36 -16
- package/lib/cjs/workspace/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/workspace/CloudSqlite.js +33 -19
- package/lib/cjs/workspace/CloudSqlite.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +149 -99
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +154 -97
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +15 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../../src/workspace/CloudSqlite.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,8DAA6H;AAC7H,sDAAgE;AAChE,oDAAgE;AAEhE,8CAA2C;AAc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M,4BAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QACrE,IAAI,IAAI,CAAC,MAAM,KAAK,uBAAQ,CAAC,YAAY;YACvC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;CACF;AA1GD,kCA0GC","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\nimport { BlobCacheProps, BlobContainerProps, BlobDaemon, BlobDaemonCommandArg, DaemonProps } from \"@bentley/imodeljs-native\";\r\nimport { BriefcaseStatus, DbResult } from \"@itwin/core-bentley\";\r\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { ChildProcess } from \"child_process\";\r\nimport { IModelHost } from \"../IModelHost\";\r\n\r\n/** @beta */\r\nexport namespace CloudSqlite {\r\n export type DbAlias = string;\r\n export type AccountProps = BlobCacheProps;\r\n export type ContainerProps = BlobContainerProps;\r\n export type AccessProps = AccountProps & ContainerProps;\r\n export type DownloadProps = AccessProps & { onProgress?: (loaded: number, total: number) => number };\r\n export type Logger = (stream: NodeJS.ReadableStream) => void;\r\n export type ProcessProps = DaemonProps & AccountProps & { stdoutLogger?: Logger, stderrLogger?: Logger };\r\n export interface DbProps { dbAlias: DbAlias, localFile: LocalFileName }\r\n}\r\n\r\n/** @beta */\r\nexport class CloudSqlite {\r\n private static cloudProcess?: ChildProcess;\r\n private static removeShutdownListener?: VoidFunction;\r\n private static killProcess() {\r\n if (this.cloudProcess) {\r\n this.cloudProcess.kill();\r\n this.cloudProcess = undefined;\r\n }\r\n }\r\n\r\n public static get isRunning() {\r\n return undefined !== this.cloudProcess;\r\n }\r\n\r\n public static async startProcess(props: CloudSqlite.ProcessProps) {\r\n if (this.isRunning)\r\n return;\r\n\r\n this.cloudProcess = BlobDaemon.start(props);\r\n\r\n // set up a listener to kill the containerProcess when we shut down\r\n this.removeShutdownListener = IModelHost.onBeforeShutdown.addOnce(() => this.killProcess());\r\n }\r\n\r\n public static stopProcess() {\r\n if (this.removeShutdownListener) {\r\n this.removeShutdownListener();\r\n this.removeShutdownListener = undefined;\r\n }\r\n this.killProcess();\r\n }\r\n\r\n public static async attach(dbAlias: CloudSqlite.DbAlias, props: CloudSqlite.AccessProps) {\r\n const args: BlobDaemonCommandArg & CloudSqlite.ProcessProps = {\r\n log: \"meh\",\r\n maxCacheSize: \"10G\",\r\n pollTime: 600,\r\n addr: \"127.0.0.2\",\r\n portNumber: 2030,\r\n persistAcrossSessions: true,\r\n lazy: false,\r\n dbAlias,\r\n // spawnOptions: {\r\n // stdio: \"inherit\",\r\n // },\r\n ...props,\r\n };\r\n\r\n if (!this.isRunning)\r\n await this.startProcess(args);\r\n\r\n const stat = await BlobDaemon.command(\"attach\", args);\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot attach: ${stat.errMsg}`);\r\n\r\n return BlobDaemon.getDbFileName(args);\r\n }\r\n\r\n public static async create(props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"create\", { ...props, dbAlias: \"\" });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot create container: ${stat.errMsg}`);\r\n }\r\n\r\n public static async downloadDb(db: CloudSqlite.DbProps, props: CloudSqlite.DownloadProps) {\r\n const downloader = new IModelHost.platform.CloudDbTransfer({ direction: \"download\", ...db, ...props });\r\n\r\n let timer: NodeJS.Timeout | undefined;\r\n try {\r\n let total = 0;\r\n const onProgress = props.onProgress;\r\n if (onProgress) {\r\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\r\n const progress = downloader.getProgress();\r\n total = progress.total;\r\n if (onProgress(progress.loaded, progress.total))\r\n downloader.cancelTransfer();\r\n }, 250);\r\n }\r\n await downloader.promise;\r\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\r\n } catch (err: any) {\r\n throw (err.message === \"cancelled\") ? new IModelError(BriefcaseStatus.DownloadCancelled, \"download cancelled\") : err;\r\n } finally {\r\n if (timer)\r\n clearInterval(timer);\r\n }\r\n }\r\n\r\n public static async copyDb(oldVersion: string, newVersion: string, props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"copy\", { dbAlias: oldVersion, toAlias: newVersion, ...props });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot copy db: ${stat.errMsg}`);\r\n }\r\n\r\n public static async uploadDb(db: CloudSqlite.DbProps, props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"upload\", { ...db, ...props });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot upload db: ${stat.errMsg}`);\r\n }\r\n\r\n public static async deleteDb(db: CloudSqlite.DbProps, props: CloudSqlite.AccessProps) {\r\n const stat = await BlobDaemon.command(\"delete\", { ...db, ...props });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot delete db: ${stat.errMsg}`);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"CloudSqlite.js","sourceRoot":"","sources":["../../../src/workspace/CloudSqlite.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,8DAAyF;AACzF,sDAAgE;AAChE,oDAAgE;AAChE,8CAA2C;AA6B3C,YAAY;AACZ,MAAa,WAAW;IAGd,MAAM,CAAC,WAAW;QACxB,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YACzB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;SAC/B;IACH,CAAC;IAEM,MAAM,KAAK,SAAS;QACzB,OAAO,SAAS,KAAK,IAAI,CAAC,YAAY,CAAC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AAQ,CAAC,YAAY;YACvC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACtD,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAA4D;QACvF,MAAM,IAAI,GAAG,MAAM,4BAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7G,IAAI,IAAI,CAAC,MAAM,KAAK,uBAAQ,CAAC,YAAY;YACvC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;CACF;AAzHD,kCAyHC","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\nimport { ChildProcess } from \"child_process\";\r\nimport { BlobDaemon, BlobDaemonCommandArg, DaemonProps } from \"@bentley/imodeljs-native\";\r\nimport { BriefcaseStatus, DbResult } from \"@itwin/core-bentley\";\r\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelHost } from \"../IModelHost\";\r\n\r\n/** @beta */\r\nexport namespace CloudSqlite {\r\n export type DbName = string;\r\n\r\n export interface AccountProps {\r\n /** blob storage module: e.g. \"azure\", \"google\", \"aws\". May also include URI style parameters. */\r\n storageType: string;\r\n /** blob store account name. */\r\n accountName: string;\r\n }\r\n export interface ContainerProps {\r\n /** the name of the container. */\r\n containerId: string;\r\n /** SAS token that grants access to the container. */\r\n sasToken: string;\r\n }\r\n export type ContainerAccessProps = AccountProps & ContainerProps;\r\n export type Logger = (stream: NodeJS.ReadableStream) => void;\r\n export type ProcessProps = DaemonProps & AccountProps & { stdoutLogger?: Logger, stderrLogger?: Logger };\r\n export interface DbNameProp { dbName: DbName }\r\n export interface DbProps extends DbNameProp { localFile: LocalFileName }\r\n export type TransferDirection = \"upload\" | \"download\";\r\n export interface TransferProgress { onProgress?: (loaded: number, total: number) => number }\r\n export type TransferProps = ContainerAccessProps & TransferProgress;\r\n export type TransferDbProps = TransferProps & DbProps;\r\n}\r\n\r\n/** @beta */\r\nexport class CloudSqlite {\r\n private static cloudProcess?: ChildProcess;\r\n private static removeShutdownListener?: VoidFunction;\r\n private static killProcess() {\r\n if (this.cloudProcess) {\r\n this.cloudProcess.kill();\r\n this.cloudProcess = undefined;\r\n }\r\n }\r\n\r\n public static get isRunning() {\r\n return undefined !== this.cloudProcess;\r\n }\r\n\r\n public static async startProcess(props: CloudSqlite.ProcessProps) {\r\n if (this.isRunning)\r\n return;\r\n\r\n this.cloudProcess = BlobDaemon.start(this.toBlobAccountProps(props));\r\n\r\n // set up a listener to kill the containerProcess when we shut down\r\n this.removeShutdownListener = IModelHost.onBeforeShutdown.addOnce(() => this.killProcess());\r\n }\r\n\r\n public static stopProcess() {\r\n if (this.removeShutdownListener) {\r\n this.removeShutdownListener();\r\n this.removeShutdownListener = undefined;\r\n }\r\n this.killProcess();\r\n }\r\n\r\n private static toBlobAccountProps(props: CloudSqlite.AccountProps) {\r\n return {\r\n user: props.accountName,\r\n ...props,\r\n };\r\n }\r\n private static toBlobAccessProps(props: CloudSqlite.ContainerAccessProps) {\r\n return {\r\n container: props.containerId,\r\n auth: props.sasToken,\r\n ...this.toBlobAccountProps(props),\r\n };\r\n }\r\n public static async attach(dbAlias: CloudSqlite.DbName, props: CloudSqlite.ContainerAccessProps) {\r\n const args: BlobDaemonCommandArg & CloudSqlite.ProcessProps = {\r\n log: \"meh\",\r\n maxCacheSize: \"10G\",\r\n pollTime: 600,\r\n addr: \"127.0.0.2\",\r\n portNumber: 2030,\r\n persistAcrossSessions: true,\r\n lazy: false,\r\n dbAlias,\r\n // spawnOptions: {\r\n // stdio: \"inherit\",\r\n // },\r\n ...this.toBlobAccessProps(props),\r\n };\r\n\r\n if (!this.isRunning)\r\n await this.startProcess(args);\r\n\r\n const stat = await BlobDaemon.command(\"attach\", args);\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot attach: ${stat.errMsg}`);\r\n\r\n return BlobDaemon.getDbFileName(args);\r\n }\r\n\r\n public static async initializeContainer(props: CloudSqlite.ContainerAccessProps) {\r\n const stat = await BlobDaemon.command(\"create\", { ...this.toBlobAccessProps(props), dbAlias: \"\" });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot initialize container: ${stat.errMsg}`);\r\n }\r\n\r\n public static async transferDb(direction: CloudSqlite.TransferDirection, props: CloudSqlite.TransferDbProps) {\r\n const transfer = new IModelHost.platform.CloudDbTransfer({ direction, ...props, dbAlias: props.dbName, ...this.toBlobAccessProps(props) });\r\n\r\n let timer: NodeJS.Timeout | undefined;\r\n try {\r\n let total = 0;\r\n const onProgress = props.onProgress;\r\n if (onProgress) {\r\n timer = setInterval(async () => { // set an interval timer to show progress every 250ms\r\n const progress = transfer.getProgress();\r\n total = progress.total;\r\n if (onProgress(progress.loaded, progress.total))\r\n transfer.cancelTransfer();\r\n }, 250);\r\n }\r\n await transfer.promise;\r\n onProgress?.(total, total); // make sure we call progress func one last time when download completes\r\n } catch (err: any) {\r\n throw (err.message === \"cancelled\") ? new IModelError(BriefcaseStatus.DownloadCancelled, `${direction} cancelled`) : err;\r\n } finally {\r\n if (timer)\r\n clearInterval(timer);\r\n }\r\n }\r\n\r\n public static async uploadDb(props: CloudSqlite.TransferDbProps) {\r\n return this.transferDb(\"upload\", props);\r\n }\r\n\r\n public static async downloadDb(props: CloudSqlite.TransferDbProps) {\r\n return this.transferDb(\"download\", props);\r\n }\r\n\r\n public static async copyDb(oldVersion: string, newVersion: string, props: CloudSqlite.ContainerAccessProps) {\r\n const stat = await BlobDaemon.command(\"copy\", { dbAlias: oldVersion, toAlias: newVersion, ...this.toBlobAccessProps(props) });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot copy db: ${stat.errMsg}`);\r\n }\r\n\r\n public static async deleteDb(props: CloudSqlite.ContainerAccessProps & { dbName: string }) {\r\n const stat = await BlobDaemon.command(\"delete\", { dbAlias: props.dbName, ...this.toBlobAccessProps(props) });\r\n if (stat.result !== DbResult.BE_SQLITE_OK)\r\n throw new Error(`Cannot delete db: ${stat.errMsg}`);\r\n }\r\n}\r\n"]}
|
|
@@ -1,102 +1,120 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Workspace
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { IModelJsNative } from "@bentley/imodeljs-native";
|
|
5
|
+
import { BeEvent, Optional } from "@itwin/core-bentley";
|
|
5
6
|
import { LocalDirName, LocalFileName } from "@itwin/core-common";
|
|
6
7
|
import { SQLiteDb } from "../SQLiteDb";
|
|
7
|
-
import { Settings, SettingsPriority } from "./Settings";
|
|
8
8
|
import { CloudSqlite } from "./CloudSqlite";
|
|
9
|
+
import { Settings, SettingsPriority } from "./Settings";
|
|
9
10
|
/**
|
|
10
|
-
* The name of a
|
|
11
|
-
*
|
|
12
|
-
* the actual
|
|
13
|
-
* WorkspaceContainerId, if multiple purposes are served by the same
|
|
11
|
+
* The name of a WorkspaceContainer. This is the user-supplied name of a WorkspaceContainer, used to specify its *purpose* within a workspace.
|
|
12
|
+
* WorkspaceContainerName can be "aliased" by `WorkspaceSetting.containerAlias` settings so that "resolved" [[WorkspaceContainerId]] that supplies
|
|
13
|
+
* the actual WorkspaceContainer for a WorkspaceContainerName may vary. Also note that more than one WorkspaceContainerName may resolve to the same
|
|
14
|
+
* WorkspaceContainerId, if multiple purposes are served by the same WorkspaceContainer.
|
|
14
15
|
* @note there are no constraints on the contents or length of `WorkspaceContainerName`s, although short descriptive names are recommended.
|
|
15
|
-
* However, when no alias exists in WorkspaceSetting.
|
|
16
|
+
* However, when no alias exists in WorkspaceSetting.containerAlias for a WorkspaceContainerName, then the WorkspaceContainerName becomes
|
|
16
17
|
* the WorkspaceContainerId, and the constraints on WorkspaceContainerId apply.
|
|
17
18
|
* @beta
|
|
18
19
|
*/
|
|
19
20
|
export declare type WorkspaceContainerName = string;
|
|
20
21
|
/**
|
|
21
|
-
* The unique identifier of a WorkspaceContainer. This becomes the base name for the local
|
|
22
|
-
*
|
|
23
|
-
* so users may not recognize the actual WorkspaceContainerId supplying resources for a
|
|
22
|
+
* The unique identifier of a WorkspaceContainer. This becomes the base name for the local directory holding the WorkspaceDbs from a WorkspaceContainer.
|
|
23
|
+
* `WorkspaceContainerName`s are resolved to WorkspaceContainerId through `WorkspaceSetting.containerAlias` settings,
|
|
24
|
+
* so users may not recognize the actual WorkspaceContainerId supplying resources for a WorkspaceDbName.
|
|
24
25
|
*
|
|
25
|
-
* `WorkspaceContainerId`s
|
|
26
|
-
* -
|
|
27
|
-
* -
|
|
28
|
-
* -
|
|
29
|
-
* - contain characters reserved for filename, device, wildcard, or url syntax (e.g. "#\.<>:"/\\"`'|?*")
|
|
26
|
+
* `WorkspaceContainerId`s :
|
|
27
|
+
* - may only contain lower case letters, numbers or dashes
|
|
28
|
+
* - may not start or end with with a dash
|
|
29
|
+
* - be shorter than 3 or longer than 63 characters
|
|
30
30
|
* @beta
|
|
31
31
|
*/
|
|
32
32
|
export declare type WorkspaceContainerId = string;
|
|
33
|
+
/** The name of a WorkspaceDb within a WorkspaceContainer.
|
|
34
|
+
* @beta
|
|
35
|
+
*/
|
|
36
|
+
export declare type WorkspaceDbName = string;
|
|
33
37
|
/**
|
|
34
|
-
* The version name for a
|
|
38
|
+
* The version name for a WorkspaceDb. More than one version of a WorkspaceDb may be stored in the same WorkspaceContainer. This
|
|
35
39
|
* string identifies a specific version.
|
|
36
40
|
* @beta
|
|
37
41
|
*/
|
|
38
|
-
export declare type
|
|
42
|
+
export declare type WorkspaceDbVersion = string;
|
|
39
43
|
/**
|
|
40
|
-
* The name for identifying WorkspaceResources in a [[
|
|
44
|
+
* The name for identifying WorkspaceResources in a [[WorkspaceDb]].
|
|
41
45
|
* * `WorkspaceResourceName`s may not:
|
|
42
46
|
* - be blank or start or end with a space
|
|
43
47
|
* - be longer than 1024 characters
|
|
44
|
-
* @note a single
|
|
48
|
+
* @note a single WorkspaceDb may hold WorkspaceResources of type 'blob', 'string' and 'file', all with the same WorkspaceResourceName.
|
|
45
49
|
* @beta
|
|
46
50
|
*/
|
|
47
51
|
export declare type WorkspaceResourceName = string;
|
|
52
|
+
/** supply either container name of id, not both
|
|
53
|
+
* @beta
|
|
54
|
+
*/
|
|
55
|
+
export declare type ContainerNameOrId = {
|
|
56
|
+
containerName: WorkspaceContainerName;
|
|
57
|
+
containerId?: never;
|
|
58
|
+
} | {
|
|
59
|
+
containerId: WorkspaceContainerId;
|
|
60
|
+
containerName?: never;
|
|
61
|
+
};
|
|
48
62
|
/**
|
|
49
|
-
* Properties that specify a WorkspaceContainer.
|
|
50
|
-
*
|
|
51
|
-
* it is used directly. Otherwise
|
|
63
|
+
* Properties that specify a WorkspaceContainer.
|
|
64
|
+
* This can either be a WorkspaceContainerName or a WorkspaceContainerId. If id is supplied,
|
|
65
|
+
* it is used directly. Otherwise name must be resolved via [[Workspace.resolveContainerId]].
|
|
66
|
+
* @beta
|
|
67
|
+
*/
|
|
68
|
+
export declare type WorkspaceContainerProps = ContainerNameOrId & {
|
|
69
|
+
cloudProps?: CloudSqlite.TransferProps;
|
|
70
|
+
};
|
|
71
|
+
/** Properties of a WorkspaceDb
|
|
52
72
|
* @beta
|
|
53
73
|
*/
|
|
54
|
-
export declare type
|
|
55
|
-
|
|
74
|
+
export declare type WorkspaceDbProps = WorkspaceContainerProps & {
|
|
75
|
+
/** the name of the WorkspaceDb */
|
|
76
|
+
dbName: WorkspaceDbName;
|
|
56
77
|
};
|
|
57
|
-
/** Properties that specify a WorkspaceResource within a
|
|
78
|
+
/** Properties that specify a WorkspaceResource within a WorkspaceDb.
|
|
58
79
|
* @beta
|
|
59
80
|
*/
|
|
60
|
-
export
|
|
61
|
-
/** the
|
|
62
|
-
container: WorkspaceContainerProps;
|
|
63
|
-
/** the name of the resource within [[container]] */
|
|
81
|
+
export declare type WorkspaceResourceProps = WorkspaceDbProps & {
|
|
82
|
+
/** the name of the resource within [[db]] */
|
|
64
83
|
rscName: WorkspaceResourceName;
|
|
65
|
-
}
|
|
84
|
+
};
|
|
66
85
|
/**
|
|
67
|
-
* A
|
|
68
|
-
* synchronized
|
|
69
|
-
* Resources of type `string` and `blob` may be loaded directly from the `
|
|
70
|
-
* copied from the
|
|
86
|
+
* A WorkspaceDb holds workspace resources. `WorkspaceDb`s may just be local files, or they may be stored and
|
|
87
|
+
* synchronized in WorkspaceContainers. Each `WorkspaceResource` in a WorkspaceDb is identified by a [[WorkspaceResourceName]].
|
|
88
|
+
* Resources of type `string` and `blob` may be loaded directly from the `WorkspaceDb`. Resources of type `file` are
|
|
89
|
+
* copied from the WorkspaceDb into a temporary local file so they can be accessed directly.
|
|
71
90
|
* @beta
|
|
72
91
|
*/
|
|
73
|
-
export interface
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/** event raised when the container is closed. */
|
|
83
|
-
readonly onContainerClosed: BeEvent<() => void>;
|
|
84
|
-
/** Get a string resource from this container, if present. */
|
|
92
|
+
export interface WorkspaceDb {
|
|
93
|
+
readonly container: WorkspaceContainer;
|
|
94
|
+
/** The WorkspaceDbName of this WorkspaceDb. */
|
|
95
|
+
readonly dbName: WorkspaceDbName;
|
|
96
|
+
/** event raised when this WorkspaceDb is closed. */
|
|
97
|
+
readonly onClosed: BeEvent<() => void>;
|
|
98
|
+
/** The name of the local file for holding this WorkspaceDb. */
|
|
99
|
+
readonly localFile: LocalDirName;
|
|
100
|
+
/** Get a string resource from this WorkspaceDb, if present. */
|
|
85
101
|
getString(rscName: WorkspaceResourceName): string | undefined;
|
|
86
|
-
/** Get a blob resource from this
|
|
102
|
+
/** Get a blob resource from this WorkspaceDb, if present. */
|
|
87
103
|
getBlob(rscName: WorkspaceResourceName): Uint8Array | undefined;
|
|
88
|
-
/**
|
|
89
|
-
|
|
104
|
+
/** @internal */
|
|
105
|
+
getBlobReader(rscName: WorkspaceResourceName): IModelJsNative.BlobIO;
|
|
106
|
+
/** Extract a local copy of a file resource from this WorkspaceDb, if present.
|
|
107
|
+
* @param rscName The name of the file resource in the WorkspaceDb
|
|
90
108
|
* @param targetFileName optional name for extracted file. Some applications require files in specific locations or filenames. If
|
|
91
109
|
* you know the full path to use for the extracted file, you can supply it. Generally, it is best to *not* supply the filename and
|
|
92
|
-
* keep the extracted files in the
|
|
110
|
+
* keep the extracted files in the container filesDir.
|
|
93
111
|
* @returns the full path to a file on the local filesystem.
|
|
94
|
-
* @note The file is copied from the
|
|
95
|
-
* as necessary, if the local file doesn't exist, or if it is out-of-date because it was updated in the
|
|
112
|
+
* @note The file is copied from the file into the local filesystem so it may be accessed directly. This happens only
|
|
113
|
+
* as necessary, if the local file doesn't exist, or if it is out-of-date because it was updated in the file.
|
|
96
114
|
* For this reason, you should not save the local file name, and instead call this method every time you access it, so its
|
|
97
115
|
* content is always holds the correct version.
|
|
98
116
|
* @note The filename will be a hash value, not the resource name.
|
|
99
|
-
* @note Workspace resource files are set readonly as they are copied from the
|
|
117
|
+
* @note Workspace resource files are set readonly as they are copied from the file.
|
|
100
118
|
* To edit them, you must first copy them to another location.
|
|
101
119
|
*/
|
|
102
120
|
getFile(rscName: WorkspaceResourceName, targetFileName?: LocalFileName): LocalFileName | undefined;
|
|
@@ -106,15 +124,11 @@ export interface WorkspaceContainer {
|
|
|
106
124
|
* @beta
|
|
107
125
|
*/
|
|
108
126
|
export interface WorkspaceOpts {
|
|
109
|
-
/** The local directory for the
|
|
110
|
-
* for files named `${this.containerId}.itwin-workspace
|
|
127
|
+
/** The local directory for the WorkspaceDb files. The [[Workspace]] will (only) look in this directory
|
|
128
|
+
* for files named `${this.containerId}/${this.dbId}.itwin-workspace`.
|
|
111
129
|
* @note if not supplied, defaults to `iTwin/Workspace` in the user-local folder.
|
|
112
130
|
*/
|
|
113
131
|
containerDir?: LocalDirName;
|
|
114
|
-
/** A local directory to store temporary files extracted for file-resources.
|
|
115
|
-
* @note if not supplied, defaults to `a folder named "Files" inside [[containerDir]]
|
|
116
|
-
*/
|
|
117
|
-
filesDir?: LocalDirName;
|
|
118
132
|
}
|
|
119
133
|
/**
|
|
120
134
|
* Settings and resources that customize an application for the current session.
|
|
@@ -122,97 +136,129 @@ export interface WorkspaceOpts {
|
|
|
122
136
|
* @beta
|
|
123
137
|
*/
|
|
124
138
|
export interface Workspace {
|
|
125
|
-
/** The local directory for the
|
|
139
|
+
/** The local directory for the WorkspaceDb files with the name `${containerId}.itwin-workspace`. */
|
|
126
140
|
readonly containerDir: LocalDirName;
|
|
127
|
-
/** the local directory where this Workspace will store temporary files extracted for file-resources. */
|
|
128
|
-
readonly filesDir: LocalDirName;
|
|
129
141
|
/** The [[Settings]] for this Workspace */
|
|
130
142
|
readonly settings: Settings;
|
|
143
|
+
getContainer(props: WorkspaceContainerProps): WorkspaceContainer;
|
|
131
144
|
/**
|
|
132
145
|
* Resolve a WorkspaceContainerProps to a WorkspaceContainerId. If props is an object with an `id` member, that value is returned unchanged.
|
|
133
|
-
* If it is a string, then the highest priority [[WorkspaceSetting.
|
|
134
|
-
* is used. If no WorkspaceSetting.
|
|
146
|
+
* If it is a string, then the highest priority [[WorkspaceSetting.containerAlias]] setting with an entry for the WorkspaceContainerName
|
|
147
|
+
* is used. If no WorkspaceSetting.containerAlias entry for the WorkspaceContainerName can be found, the name is returned as the id.
|
|
135
148
|
*/
|
|
136
149
|
resolveContainerId(props: WorkspaceContainerProps): WorkspaceContainerId;
|
|
137
150
|
/**
|
|
138
|
-
* Get an open [[
|
|
151
|
+
* Get an open [[WorkspaceDb]]. If the WorkspaceDb is present but not open, it is opened first.
|
|
139
152
|
* If `cloudProps` are supplied, and if container is not present or not up-to-date, it is downloaded first.
|
|
140
153
|
* @returns a Promise that is resolved when the container is local, opened, and available for access.
|
|
141
154
|
*/
|
|
142
|
-
|
|
155
|
+
getWorkspaceDb(props: WorkspaceDbProps): Promise<WorkspaceDb>;
|
|
143
156
|
/** Load a WorkspaceResource of type string, parse it, and add it to the current Settings for this Workspace.
|
|
144
157
|
* @note settingsRsc must specify a resource holding a stringified JSON representation of a [[SettingDictionary]]
|
|
145
158
|
* @returns a Promise that is resolved when the settings resource has been loaded.
|
|
146
159
|
*/
|
|
147
160
|
loadSettingsDictionary(settingRsc: WorkspaceResourceProps, priority: SettingsPriority): Promise<void>;
|
|
161
|
+
/** Close this Workspace. All WorkspaceContainers are dropped. */
|
|
162
|
+
close(): void;
|
|
163
|
+
}
|
|
164
|
+
/** A WorkspaceContainer holds WorkspaceDbs.
|
|
165
|
+
* @beta
|
|
166
|
+
*/
|
|
167
|
+
export interface WorkspaceContainer {
|
|
168
|
+
readonly dirName: LocalDirName;
|
|
169
|
+
/** the local directory where this WorkspaceContainer will store temporary files extracted for file-resources. */
|
|
170
|
+
readonly filesDir: LocalDirName;
|
|
171
|
+
readonly id: WorkspaceContainerId;
|
|
172
|
+
readonly workspace: Workspace;
|
|
148
173
|
/** @internal */
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
174
|
+
addWorkspaceDb(toAdd: ITwinWorkspaceDb): void;
|
|
175
|
+
getWorkspaceDb(props: Optional<WorkspaceDbProps, "containerName">): Promise<WorkspaceDb>;
|
|
176
|
+
/** Close and remove a currently opened [[WorkspaceDb]] from this Workspace. */
|
|
177
|
+
dropWorkspaceDb(container: WorkspaceDb): void;
|
|
178
|
+
/** Close this WorkspaceContainer. All currently opened WorkspaceDbs are dropped. */
|
|
153
179
|
close(): void;
|
|
154
180
|
}
|
|
155
181
|
/** @internal */
|
|
156
182
|
export declare class ITwinWorkspace implements Workspace {
|
|
157
183
|
private _containers;
|
|
158
|
-
readonly filesDir: LocalDirName;
|
|
159
184
|
readonly containerDir: LocalDirName;
|
|
160
185
|
readonly settings: Settings;
|
|
161
186
|
constructor(settings: Settings, opts?: WorkspaceOpts);
|
|
162
|
-
addContainer(
|
|
163
|
-
getContainer(props: WorkspaceContainerProps
|
|
187
|
+
addContainer(toAdd: ITwinWorkspaceContainer): void;
|
|
188
|
+
getContainer(props: WorkspaceContainerProps): WorkspaceContainer;
|
|
189
|
+
getWorkspaceDb(props: WorkspaceDbProps): Promise<WorkspaceDb>;
|
|
164
190
|
loadSettingsDictionary(settingRsc: WorkspaceResourceProps, priority: SettingsPriority): Promise<void>;
|
|
165
191
|
close(): void;
|
|
166
|
-
dropContainer(toDrop: WorkspaceContainer): void;
|
|
167
192
|
resolveContainerId(props: WorkspaceContainerProps): WorkspaceContainerId;
|
|
168
193
|
}
|
|
194
|
+
/** @internal */
|
|
195
|
+
export declare class ITwinWorkspaceContainer implements WorkspaceContainer {
|
|
196
|
+
readonly workspace: ITwinWorkspace;
|
|
197
|
+
readonly filesDir: LocalDirName;
|
|
198
|
+
readonly id: WorkspaceContainerId;
|
|
199
|
+
private _wsDbs;
|
|
200
|
+
get dirName(): string;
|
|
201
|
+
/** rules for ContainerIds (from Azure, see https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata)
|
|
202
|
+
* - may only contain lower case letters, numbers or dashes
|
|
203
|
+
* - may not start or end with with a dash nor have more than one dash in a row
|
|
204
|
+
* - may not be shorter than 3 or longer than 63 characters
|
|
205
|
+
*/
|
|
206
|
+
private static validateContainerId;
|
|
207
|
+
constructor(workspace: ITwinWorkspace, id: WorkspaceContainerId);
|
|
208
|
+
addWorkspaceDb(toAdd: ITwinWorkspaceDb): void;
|
|
209
|
+
getWorkspaceDb(props: Optional<WorkspaceDbProps, "containerName">): Promise<WorkspaceDb>;
|
|
210
|
+
dropWorkspaceDb(toDrop: WorkspaceDb): void;
|
|
211
|
+
close(): void;
|
|
212
|
+
purgeContainerFiles(): void;
|
|
213
|
+
}
|
|
169
214
|
/**
|
|
170
|
-
* A local file holding a
|
|
215
|
+
* A local file holding a WorkspaceDb.
|
|
171
216
|
* @beta
|
|
172
217
|
*/
|
|
173
|
-
export declare class
|
|
174
|
-
|
|
175
|
-
readonly
|
|
176
|
-
readonly
|
|
218
|
+
export declare class ITwinWorkspaceDb implements WorkspaceDb {
|
|
219
|
+
readonly sqliteDb: SQLiteDb;
|
|
220
|
+
readonly dbName: WorkspaceDbName;
|
|
221
|
+
readonly container: WorkspaceContainer;
|
|
177
222
|
localFile: LocalFileName;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
223
|
+
readonly onClosed: BeEvent<() => void>;
|
|
224
|
+
protected static noLeadingOrTrailingSpaces(name: string, msg: string): void;
|
|
225
|
+
private static validateDbName;
|
|
181
226
|
get isOpen(): boolean;
|
|
182
|
-
|
|
227
|
+
queryFileResource(rscName: WorkspaceResourceName): {
|
|
183
228
|
localFileName: string;
|
|
184
|
-
info:
|
|
229
|
+
info: IModelJsNative.EmbedFileQuery;
|
|
185
230
|
} | undefined;
|
|
186
|
-
|
|
187
|
-
private static validateContainerId;
|
|
188
|
-
constructor(containerId: WorkspaceContainerId, workspace: Workspace);
|
|
189
|
-
purgeContainerFiles(): void;
|
|
231
|
+
constructor(dbName: WorkspaceDbName, container: WorkspaceContainer);
|
|
190
232
|
open(): void;
|
|
191
233
|
close(): void;
|
|
192
234
|
getString(rscName: WorkspaceResourceName): string | undefined;
|
|
235
|
+
/** Get a BlobIO reader for a blob WorkspaceResource.
|
|
236
|
+
* @note when finished, caller must call `close` on the BlobIO.
|
|
237
|
+
*/
|
|
238
|
+
getBlobReader(rscName: WorkspaceResourceName): IModelJsNative.BlobIO;
|
|
193
239
|
getBlob(rscName: WorkspaceResourceName): Uint8Array | undefined;
|
|
194
240
|
getFile(rscName: WorkspaceResourceName, targetFileName?: LocalFileName): LocalFileName | undefined;
|
|
195
241
|
}
|
|
196
242
|
/**
|
|
197
|
-
* An editable [[
|
|
243
|
+
* An editable [[WorkspaceDb]]. This is used by administrators for creating and modifying `WorkspaceDb`s.
|
|
198
244
|
* For cloud-backed containers, the write token must be obtained before this class may be used. Only one user at at time
|
|
199
245
|
* may be editing.
|
|
200
246
|
* @beta
|
|
201
247
|
*/
|
|
202
|
-
export declare class
|
|
248
|
+
export declare class EditableWorkspaceDb extends ITwinWorkspaceDb {
|
|
203
249
|
private _isCloudOpen;
|
|
204
250
|
private static validateResourceName;
|
|
205
251
|
private validateResourceSize;
|
|
206
|
-
openCloudDb(props: CloudSqlite.
|
|
252
|
+
openCloudDb(props: CloudSqlite.ContainerAccessProps): Promise<void>;
|
|
207
253
|
open(): void;
|
|
208
254
|
close(): void;
|
|
209
255
|
private getFileModifiedTime;
|
|
210
256
|
private performWriteSql;
|
|
211
|
-
/** Create a new, empty,
|
|
212
|
-
create(
|
|
213
|
-
static cloneVersion(oldVersion:
|
|
214
|
-
upload(cloudProps: CloudSqlite.
|
|
215
|
-
/** Add a new string resource to this
|
|
257
|
+
/** Create a new, empty, EditableWorkspaceDb for importing Workspace resources. */
|
|
258
|
+
create(): void;
|
|
259
|
+
static cloneVersion(oldVersion: WorkspaceDbVersion, newVersion: WorkspaceDbVersion, cloudProps: CloudSqlite.ContainerAccessProps): Promise<void>;
|
|
260
|
+
upload(cloudProps: CloudSqlite.TransferProps): Promise<void>;
|
|
261
|
+
/** Add a new string resource to this WorkspaceDb.
|
|
216
262
|
* @param rscName The name of the string resource.
|
|
217
263
|
* @param val The string to save.
|
|
218
264
|
*/
|
|
@@ -225,7 +271,7 @@ export declare class EditableWorkspaceFile extends WorkspaceFile {
|
|
|
225
271
|
updateString(rscName: WorkspaceResourceName, val: string): void;
|
|
226
272
|
/** Remove a string resource. */
|
|
227
273
|
removeString(rscName: WorkspaceResourceName): void;
|
|
228
|
-
/** Add a new blob resource to this
|
|
274
|
+
/** Add a new blob resource to this WorkspaceDb.
|
|
229
275
|
* @param rscName The name of the blob resource.
|
|
230
276
|
* @param val The blob to save.
|
|
231
277
|
*/
|
|
@@ -236,13 +282,17 @@ export declare class EditableWorkspaceFile extends WorkspaceFile {
|
|
|
236
282
|
* @throws if rscName does not exist
|
|
237
283
|
*/
|
|
238
284
|
updateBlob(rscName: WorkspaceResourceName, val: Uint8Array): void;
|
|
285
|
+
/** Get a BlobIO writer for a previously-added blob WorkspaceResource.
|
|
286
|
+
* @note after writing is complete, caller must call `close` on the BlobIO and must call `saveChanges` on the `db`.
|
|
287
|
+
*/
|
|
288
|
+
getBlobWriter(rscName: WorkspaceResourceName): IModelJsNative.BlobIO;
|
|
239
289
|
/** Remove a blob resource. */
|
|
240
290
|
removeBlob(rscName: WorkspaceResourceName): void;
|
|
241
|
-
/** Copy the contents of an existing local file into this
|
|
291
|
+
/** Copy the contents of an existing local file into this WorkspaceDb as a file resource.
|
|
242
292
|
* @param rscName The name of the file resource.
|
|
243
293
|
* @param localFileName The name of a local file to be read.
|
|
244
294
|
* @param fileExt The extension (do not include the leading ".") to be appended to the generated fileName
|
|
245
|
-
* when this
|
|
295
|
+
* when this WorkspaceDb is extracted from the WorkspaceDb. By default the characters after the last "." in `localFileName`
|
|
246
296
|
* are used. Pass this argument to override that.
|
|
247
297
|
*/
|
|
248
298
|
addFile(rscName: WorkspaceResourceName, localFileName: LocalFileName, fileExt?: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../../src/workspace/Workspace.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../../src/workspace/Workspace.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,OAAO,EAAsB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAe,YAAY,EAAE,a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