@bentley/imodeljs-native 3.4.9 → 3.4.12

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.
@@ -1,166 +1,120 @@
1
- /** @packageDocumentation
2
- * @module iModels
3
- */
4
- /// <reference types="node" />
5
- import * as child_process from "child_process";
6
- import { IModelJsNative } from "./NativeLibrary";
7
- /**
8
- * @note This package may only have **dev** dependencies on @itwin packages, so they are *not* available at runtime. Therefore we can only import **types** from them.
9
- */
10
- import type { LocalFileName } from "@itwin/core-common";
11
- export declare namespace CloudSqlite {
12
- const enum LogMask {
13
- LOG_HTTP = 1,
14
- LOG_UPLOAD = 2,
15
- LOG_CLEANUP = 4,
16
- LOG_EVENT = 8
17
- }
18
- /** Properties that specify how to access the account for a cloud blob-store container. */
19
- interface AccountAccessProps {
20
- /** blob storage module: e.g. "azure", "google", "aws". May also include URI style parameters. */
21
- storageType: string;
22
- /** blob store account name, or a URI for custom domains. */
23
- accessName: string;
24
- }
25
- /** Properties of a CloudContainer. */
26
- interface ContainerProps {
27
- /** the name of the container. */
28
- containerId: string;
29
- /** an alias for the container. Defaults to `containerId` */
30
- alias?: string;
31
- /** token that grants access to the container. For sas=1 `storageType`s, this is the sasToken. For sas=0, this is the account key */
32
- accessToken: string;
33
- /** if true, container is attached with write permissions, and accessToken must provide write access to the cloud container. */
34
- writeable?: boolean;
35
- /** if true, container is attached in "secure" mode (blocks are encrypted). Only supported in daemon mode. */
36
- secure?: boolean;
37
- }
38
- /** Returned from `CloudContainer.queryDatabase` describing one database in the container */
39
- interface CachedDbProps {
40
- /** The total of (4Mb) blocks in the database. */
41
- readonly totalBlocks: number;
42
- /** the number of blocks of the database that have been downloaded into the CloudCache */
43
- readonly localBlocks: number;
44
- /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */
45
- readonly dirtyBlocks: number;
46
- /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */
47
- readonly transactions: boolean;
48
- /** the state of this database. Indicates whether the database is new or deleted since last upload */
49
- readonly state: "" | "copied" | "deleted";
50
- }
51
- /** Properties for accessing a CloudContainer */
52
- type ContainerAccessProps = AccountAccessProps & ContainerProps & {
53
- /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */
54
- durationSeconds?: number;
55
- };
56
- /** The name of a CloudSqlite database within a CloudContainer. */
57
- interface DbNameProp {
58
- /** the name of the database within the CloudContainer.
59
- * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/
60
- dbName: string;
61
- }
62
- /** Properties for accessing a database within a CloudContainer */
63
- interface DbProps extends DbNameProp {
64
- /** the name of the local file to access the database. */
65
- localFileName: LocalFileName;
66
- }
67
- type TransferDirection = "upload" | "download";
68
- interface TransferProgress {
69
- /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */
70
- onProgress?: (loaded: number, total: number) => number;
71
- }
72
- interface CloudHttpProps {
73
- /** The number of simultaneous HTTP requests. Default is 6. */
74
- nRequests?: number;
75
- }
76
- interface PrefetchProps extends CloudHttpProps {
77
- /** timeout between requests, in milliseconds. Default is 100. */
78
- timeout?: number;
79
- /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */
80
- minRequests?: number;
81
- }
82
- type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;
83
- /** Properties for creating a CloudCache. */
84
- interface CacheProps extends CloudHttpProps {
85
- /** 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. */
86
- rootDir: string;
87
- /** name of this cache. It is possible to have more than one CloudCache in the same session. */
88
- name: string;
89
- /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */
90
- cacheSize?: string;
91
- /** turn on diagnostics for `curl` (outputs to stderr) */
92
- curlDiagnostics?: boolean;
93
- }
94
- /** Properties for creating a new instance of a daemon process. */
95
- interface DaemonProps {
96
- /** full path name of daemon.exe file. Default is to find "iTwinDaemon.exe" in the same directory as this library. */
97
- exePath?: string;
98
- /** daemon connection address. Default is "127.0.0.1" */
99
- addr?: string;
100
- /** port number. Default 22002 */
101
- portNumber?: number;
102
- /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */
103
- cacheSize?: string;
104
- /** logging options */
105
- log?: string;
106
- /** if true, don't include timestamps in log messages */
107
- noTimeStamps?: boolean;
108
- /** The amount of time, in seconds before an http request made to cloud storage by the daemon times out. Default 600 seconds. */
109
- httptimeout?: number;
110
- /** options for spawn */
111
- spawnOptions?: child_process.SpawnOptions;
112
- }
113
- type DaemonCommandArg = DbNameProp & AccountAccessProps & CacheProps & ContainerProps;
114
- class Daemon {
115
- private static exeName;
116
- static daemonDir(props: CacheProps): string;
117
- /** Start the Daemon process using the supplied properties. The process will be detached from the current process. */
118
- static start(props: DaemonProps & CacheProps): child_process.ChildProcess;
119
- }
120
- /** @internal */
121
- function transferDb(direction: TransferDirection, container: IModelJsNative.CloudContainer, props: TransferDbProps): Promise<void>;
122
- /** Upload a database into a CloudContainer
123
- * @param container the CloudContainer holding the database. Must be connected.
124
- * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
125
- * @note this function requires that the write lock be held on the container
126
- */
127
- function uploadDb(container: IModelJsNative.CloudContainer, props: TransferDbProps): Promise<void>;
128
- /** Download a database from a CloudContainer
129
- * @param container the CloudContainer holding the database. Must be connected.
130
- * @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
131
- * @returns a Promise that is resolved when the download completes.
132
- * @note the download is "restartable." If the transfer is aborted and then re-requested, it will continue from where
133
- * it left off rather than re-downloading the entire file.
134
- */
135
- function downloadDb(container: IModelJsNative.CloudContainer, props: TransferDbProps): Promise<void>;
136
- /** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.
137
- * @param lockedBy The identifier supplied by the application/user that currently holds the lock.
138
- * @param expires a stringified Date (in local time) indicating when the lock will expire.
139
- * @return "stop" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.
140
- */
141
- type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | "stop">;
142
- /**
143
- * Attempt to acquire the write lock for a container, with retries.
144
- * If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns "stop", throw. Otherwise try again.
145
- * @note if write lock is already held, this function does nothing.
146
- * @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
147
- * @param container the CloudContainer for which the lock is to be acquired
148
- * @param busyHandler if present, function called when the write lock is currently held by another user.
149
- */
150
- function acquireWriteLock(user: string, container: IModelJsNative.CloudContainer, busyHandler?: WriteLockBusyHandler): Promise<void>;
151
- /**
152
- * Perform an asynchronous write operation on a CloudContainer with the write lock held.
153
- * 1. if write lock is already held, call operation and return.
154
- * 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
155
- * 3. perform the operation
156
- * 3.a if the operation throws, abandon all changes and re-throw
157
- * 4. release the write lock.
158
- * 5. return value from operation
159
- * @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
160
- * @param container the CloudContainer for which the lock is to be acquired
161
- * @param operation an asynchronous operation performed with the write lock held.
162
- * @param busyHandler if present, function called when the write lock is currently held by another user.
163
- */
164
- function withWriteLock<T>(user: string, container: IModelJsNative.CloudContainer, operation: () => T, busyHandler?: WriteLockBusyHandler): Promise<T>;
165
- }
166
- //# sourceMappingURL=CloudSqlite.d.ts.map
1
+ /** @packageDocumentation
2
+ * @module iModels
3
+ */
4
+ /// <reference types="node" />
5
+ import * as child_process from "child_process";
6
+ /**
7
+ * @note This package may only have **dev** dependencies on @itwin packages, so they are *not* available at runtime. Therefore we can only import **types** from them.
8
+ */
9
+ import type { LocalFileName } from "@itwin/core-common";
10
+ export declare namespace NativeCloudSqlite {
11
+ const enum LogMask {
12
+ LOG_HTTP = 1,
13
+ LOG_UPLOAD = 2,
14
+ LOG_CLEANUP = 4,
15
+ LOG_EVENT = 8
16
+ }
17
+ /** Properties that specify how to access the account for a cloud blob-store container. */
18
+ interface AccountAccessProps {
19
+ /** blob storage module: e.g. "azure", "google", "aws". May also include URI style parameters. */
20
+ storageType: string;
21
+ /** blob store account name, or a URI for custom domains. */
22
+ accessName: string;
23
+ }
24
+ /** Properties of a CloudContainer. */
25
+ interface ContainerProps {
26
+ /** the name of the container. */
27
+ containerId: string;
28
+ /** an alias for the container. Defaults to `containerId` */
29
+ alias?: string;
30
+ /** token that grants access to the container. For sas=1 `storageType`s, this is the sasToken. For sas=0, this is the account key */
31
+ accessToken: string;
32
+ /** if true, container is attached with write permissions, and accessToken must provide write access to the cloud container. */
33
+ writeable?: boolean;
34
+ /** if true, container is attached in "secure" mode (blocks are encrypted). Only supported in daemon mode. */
35
+ secure?: boolean;
36
+ }
37
+ /** Returned from `CloudContainer.queryDatabase` describing one database in the container */
38
+ interface CachedDbProps {
39
+ /** The total of (4Mb) blocks in the database. */
40
+ readonly totalBlocks: number;
41
+ /** the number of blocks of the database that have been downloaded into the CloudCache */
42
+ readonly localBlocks: number;
43
+ /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */
44
+ readonly dirtyBlocks: number;
45
+ /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */
46
+ readonly transactions: boolean;
47
+ /** the state of this database. Indicates whether the database is new or deleted since last upload */
48
+ readonly state: "" | "copied" | "deleted";
49
+ }
50
+ /** Properties for accessing a CloudContainer */
51
+ type ContainerAccessProps = AccountAccessProps & ContainerProps & {
52
+ /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */
53
+ durationSeconds?: number;
54
+ };
55
+ /** The name of a CloudSqlite database within a CloudContainer. */
56
+ interface DbNameProp {
57
+ /** the name of the database within the CloudContainer.
58
+ * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/
59
+ dbName: string;
60
+ }
61
+ /** Properties for accessing a database within a CloudContainer */
62
+ interface DbProps extends DbNameProp {
63
+ /** the name of the local file to access the database. */
64
+ localFileName: LocalFileName;
65
+ }
66
+ type TransferDirection = "upload" | "download";
67
+ interface TransferProgress {
68
+ /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */
69
+ onProgress?: (loaded: number, total: number) => number;
70
+ }
71
+ interface CloudHttpProps {
72
+ /** The number of simultaneous HTTP requests. Default is 6. */
73
+ nRequests?: number;
74
+ }
75
+ interface PrefetchProps extends CloudHttpProps {
76
+ /** timeout between requests, in milliseconds. Default is 100. */
77
+ timeout?: number;
78
+ /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */
79
+ minRequests?: number;
80
+ }
81
+ type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;
82
+ /** Properties for creating a CloudCache. */
83
+ interface CacheProps extends CloudHttpProps {
84
+ /** 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. */
85
+ rootDir: string;
86
+ /** name of this cache. It is possible to have more than one CloudCache in the same session. */
87
+ name: string;
88
+ /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */
89
+ cacheSize?: string;
90
+ /** turn on diagnostics for `curl` (outputs to stderr) */
91
+ curlDiagnostics?: boolean;
92
+ }
93
+ /** Properties for creating a new instance of a daemon process. */
94
+ interface DaemonProps {
95
+ /** full path name of daemon.exe file. Default is to find "iTwinDaemon.exe" in the same directory as this library. */
96
+ exePath?: string;
97
+ /** daemon connection address. Default is "127.0.0.1" */
98
+ addr?: string;
99
+ /** port number. Default 22002 */
100
+ portNumber?: number;
101
+ /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */
102
+ cacheSize?: string;
103
+ /** logging options */
104
+ log?: string;
105
+ /** if true, don't include timestamps in log messages */
106
+ noTimeStamps?: boolean;
107
+ /** The amount of time, in seconds before an http request made to cloud storage by the daemon times out. Default 600 seconds. */
108
+ httptimeout?: number;
109
+ /** options for spawn */
110
+ spawnOptions?: child_process.SpawnOptions;
111
+ }
112
+ type DaemonCommandArg = DbNameProp & AccountAccessProps & CacheProps & ContainerProps;
113
+ class Daemon {
114
+ static exeName(props: DaemonProps): string;
115
+ static daemonDir(props: CacheProps): string;
116
+ /** Start the Daemon process using the supplied properties. The process will be detached from the current process. */
117
+ static start(props: DaemonProps & CacheProps): child_process.ChildProcess;
118
+ }
119
+ }
120
+ //# sourceMappingURL=NativeCloudSqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeCloudSqlite.d.ts","sourceRoot":"","sources":["../src/NativeCloudSqlite.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAEH,OAAO,KAAK,aAAa,MAAM,eAAe,CAAC;AAM/C;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKxD,yBAAiB,iBAAiB,CAAC;IAEjC,WAAkB,OAAO;QACvB,QAAQ,IAAS;QAAE,UAAU,IAAS;QAAE,WAAW,IAAS;QAAE,SAAS,IAAS;KACjF;IAED,0FAA0F;IAC1F,UAAiB,kBAAkB;QACjC,iGAAiG;QACjG,WAAW,EAAE,MAAM,CAAC;QACpB,4DAA4D;QAC5D,UAAU,EAAE,MAAM,CAAC;KACpB;IAED,sCAAsC;IACtC,UAAiB,cAAc;QAC7B,iCAAiC;QACjC,WAAW,EAAE,MAAM,CAAC;QACpB,4DAA4D;QAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,oIAAoI;QACpI,WAAW,EAAE,MAAM,CAAC;QACpB,+HAA+H;QAC/H,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,6GAA6G;QAC7G,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB;IAED,4FAA4F;IAC5F,UAAiB,aAAa;QAC5B,iDAAiD;QACjD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,yFAAyF;QACzF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,iHAAiH;QACjH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,kIAAkI;QAClI,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;QAC/B,qGAAqG;QACr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CAAiC;QACjC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,oHAAoH;QACpH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,sBAAsB;QACtB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,wDAAwD;QACxD,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,gIAAgI;QAChI,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,wBAAwB;QACxB,YAAY,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC;KAC3C;IACD,KAAY,gBAAgB,GAAG,UAAU,GAAG,kBAAkB,GAAG,UAAU,GAAG,cAAc,CAAC;IAE7F,MAAa,MAAM;eACH,OAAO,CAAC,KAAK,EAAE,WAAW;eAG1B,SAAS,CAAC,KAAK,EAAE,UAAU;QAIzC,qHAAqH;eACvG,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,aAAa,CAAC,YAAY;KAoBjF;CAEF"}
@@ -0,0 +1,53 @@
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.NativeCloudSqlite = void 0;
11
+ const child_process = require("child_process");
12
+ const fs = require("fs");
13
+ const os = require("os");
14
+ const path = require("path");
15
+ const NativeLibrary_1 = require("./NativeLibrary");
16
+ // cspell:ignore polltime cachesize notimestamps deletetime gctime retrytime nwrite ndelete prefetch httptimeout
17
+ /* eslint-disable no-restricted-syntax */
18
+ var NativeCloudSqlite;
19
+ (function (NativeCloudSqlite) {
20
+ ;
21
+ class Daemon {
22
+ static exeName(props) {
23
+ var _a;
24
+ return (_a = props.exePath) !== null && _a !== void 0 ? _a : path.join(__dirname, NativeLibrary_1.NativeLibrary.archName, os.platform() === "win32" ? "iTwinDaemon.exe" : "iTwinDaemon");
25
+ }
26
+ static daemonDir(props) {
27
+ var _a;
28
+ return (_a = props.rootDir) !== null && _a !== void 0 ? _a : path.join(NativeLibrary_1.NativeLibrary.defaultCacheDir, "itwin-daemon");
29
+ }
30
+ /** Start the Daemon process using the supplied properties. The process will be detached from the current process. */
31
+ static start(props) {
32
+ const dir = this.daemonDir(props);
33
+ fs.mkdirSync(dir, { recursive: true }); // make sure the directory exists before starting the daemon
34
+ const args = [`daemon`];
35
+ if (props.addr !== undefined)
36
+ args.push(`-addr`, `${props.addr}`);
37
+ if (props.portNumber !== undefined)
38
+ args.push(`-port`, `${props.portNumber}`);
39
+ if (props.cacheSize)
40
+ args.push(`-cachesize`, `${props.cacheSize}`);
41
+ if (props.log)
42
+ args.push(`-log`, `${props.log}`);
43
+ if (props.noTimeStamps)
44
+ args.push(`-notimestamps`);
45
+ if (props.httptimeout !== undefined)
46
+ args.push(`-httptimeout`, `${props.httptimeout}`);
47
+ args.push(`${dir}`); // This MUST be the last arg when starting the daemon.
48
+ return child_process.spawn(this.exeName(props), args, Object.assign(Object.assign({}, props.spawnOptions), { windowsVerbatimArguments: true }));
49
+ }
50
+ }
51
+ NativeCloudSqlite.Daemon = Daemon;
52
+ })(NativeCloudSqlite = exports.NativeCloudSqlite || (exports.NativeCloudSqlite = {}));
53
+ //# sourceMappingURL=NativeCloudSqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeCloudSqlite.js","sourceRoot":"","sources":["../src/NativeCloudSqlite.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,yBAAyB;AACzB,yBAAyB;AACzB,6BAA6B;AAC7B,mDAAgD;AAOhD,gHAAgH;AAChH,yCAAyC;AAEzC,IAAiB,iBAAiB,CAiJjC;AAjJD,WAAiB,iBAAiB;IAI/B,CAAC;IA8GF,MAAa,MAAM;QACV,MAAM,CAAC,OAAO,CAAC,KAAkB;;YACtC,OAAO,MA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K,SAAS;gBACjC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;YACnD,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,sDAAsD;YAC3E,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,kCAAO,KAAK,CAAC,YAAY,KAAE,wBAAwB,EAAE,IAAI,IAAG,CAAC;QACnH,CAAC;KACF;IA7BY,wBAAM,SA6BlB,CAAA;AAEH,CAAC,EAjJgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAiJjC","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 iModels\r\n */\r\n\r\nimport * as child_process from \"child_process\";\r\nimport * as fs from \"fs\";\r\nimport * as os from \"os\";\r\nimport * as path from \"path\";\r\nimport { NativeLibrary } from \"./NativeLibrary\";\r\n\r\n/**\r\n * @note This package may only have **dev** dependencies on @itwin packages, so they are *not* available at runtime. Therefore we can only import **types** from them.\r\n */\r\nimport type { LocalFileName } from \"@itwin/core-common\";\r\n\r\n// cspell:ignore polltime cachesize notimestamps deletetime gctime retrytime nwrite ndelete prefetch httptimeout\r\n/* eslint-disable no-restricted-syntax */\r\n\r\nexport namespace NativeCloudSqlite {\r\n\r\n export const enum LogMask {\r\n LOG_HTTP = 0x0001, LOG_UPLOAD = 0x0002, LOG_CLEANUP = 0x0004, LOG_EVENT = 0x0008\r\n };\r\n\r\n /** Properties that specify how to access the account for a cloud blob-store container. */\r\n export interface AccountAccessProps {\r\n /** blob storage module: e.g. \"azure\", \"google\", \"aws\". May also include URI style parameters. */\r\n storageType: string;\r\n /** blob store account name, or a URI for custom domains. */\r\n accessName: string;\r\n }\r\n\r\n /** Properties of a CloudContainer. */\r\n export interface ContainerProps {\r\n /** the name of the container. */\r\n containerId: string;\r\n /** an alias for the container. Defaults to `containerId` */\r\n alias?: string;\r\n /** token that grants access to the container. For sas=1 `storageType`s, this is the sasToken. For sas=0, this is the account key */\r\n accessToken: string;\r\n /** if true, container is attached with write permissions, and accessToken must provide write access to the cloud container. */\r\n writeable?: boolean;\r\n /** if true, container is attached in \"secure\" mode (blocks are encrypted). Only supported in daemon mode. */\r\n secure?: boolean;\r\n }\r\n\r\n /** Returned from `CloudContainer.queryDatabase` describing one database in the container */\r\n export interface CachedDbProps {\r\n /** The total of (4Mb) blocks in the database. */\r\n readonly totalBlocks: number,\r\n /** the number of blocks of the database that have been downloaded into the CloudCache */\r\n readonly localBlocks: number,\r\n /** the number of blocks from this database that have been modified in the CloudCache and need to be uploaded. */\r\n readonly dirtyBlocks: number,\r\n /** If true, the database currently has transactions in the WAL file and may not be uploaded until they have been checkPointed. */\r\n readonly transactions: boolean;\r\n /** the state of this database. Indicates whether the database is new or deleted since last upload */\r\n readonly state: \"\" | \"copied\" | \"deleted\";\r\n }\r\n\r\n /** Properties for accessing a CloudContainer */\r\n export type ContainerAccessProps = AccountAccessProps & ContainerProps & {\r\n /** Duration for holding write lock, in seconds. After this time the write lock expires if not refreshed. Default is one hour. */\r\n durationSeconds?: number\r\n };\r\n\r\n /** The name of a CloudSqlite database within a CloudContainer. */\r\n export interface DbNameProp {\r\n /** the name of the database within the CloudContainer.\r\n * @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/\r\n dbName: string\r\n }\r\n\r\n /** Properties for accessing a database within a CloudContainer */\r\n export interface DbProps extends DbNameProp {\r\n /** the name of the local file to access the database. */\r\n localFileName: LocalFileName\r\n }\r\n\r\n export type TransferDirection = \"upload\" | \"download\";\r\n export interface TransferProgress {\r\n /** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */\r\n onProgress?: (loaded: number, total: number) => number\r\n }\r\n\r\n export interface CloudHttpProps {\r\n /** The number of simultaneous HTTP requests. Default is 6. */\r\n nRequests?: number;\r\n }\r\n\r\n export interface PrefetchProps extends CloudHttpProps {\r\n /** timeout between requests, in milliseconds. Default is 100. */\r\n timeout?: number;\r\n /** The number of prefetch requests to issue while there is foreground activity. Default is 3. */\r\n minRequests?: number;\r\n }\r\n\r\n export type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;\r\n\r\n /** Properties for creating a CloudCache. */\r\n export interface CacheProps extends CloudHttpProps {\r\n /** full path of directory for cache to store its files. Must be on a (preferably fast) local drive, and must be empty when the cache is first created. */\r\n rootDir: string;\r\n /** name of this cache. It is possible to have more than one CloudCache in the same session. */\r\n name: string;\r\n /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */\r\n cacheSize?: string;\r\n /** turn on diagnostics for `curl` (outputs to stderr) */\r\n curlDiagnostics?: boolean;\r\n }\r\n\r\n /** Properties for creating a new instance of a daemon process. */\r\n export interface DaemonProps {\r\n /** full path name of daemon.exe file. Default is to find \"iTwinDaemon.exe\" in the same directory as this library. */\r\n exePath?: string;\r\n /** daemon connection address. Default is \"127.0.0.1\" */\r\n addr?: string;\r\n /** port number. Default 22002 */\r\n portNumber?: number;\r\n /** maximum cache Size. Must be a number followed by either M (for megabytes) or G (for gigabytes.) Default is 1G */\r\n cacheSize?: string;\r\n /** logging options */\r\n log?: string;\r\n /** if true, don't include timestamps in log messages */\r\n noTimeStamps?: boolean;\r\n /** The amount of time, in seconds before an http request made to cloud storage by the daemon times out. Default 600 seconds. */\r\n httptimeout?: number;\r\n /** options for spawn */\r\n spawnOptions?: child_process.SpawnOptions;\r\n }\r\n export type DaemonCommandArg = DbNameProp & AccountAccessProps & CacheProps & ContainerProps;\r\n\r\n export class Daemon {\r\n public static exeName(props: DaemonProps) {\r\n return props.exePath ?? path.join(__dirname, NativeLibrary.archName, os.platform() === \"win32\" ? \"iTwinDaemon.exe\" : \"iTwinDaemon\");\r\n }\r\n public static daemonDir(props: CacheProps) {\r\n return props.rootDir ?? path.join(NativeLibrary.defaultCacheDir, \"itwin-daemon\");\r\n }\r\n\r\n /** Start the Daemon process using the supplied properties. The process will be detached from the current process. */\r\n public static start(props: DaemonProps & CacheProps): child_process.ChildProcess {\r\n const dir = this.daemonDir(props);\r\n fs.mkdirSync(dir, { recursive: true }); // make sure the directory exists before starting the daemon\r\n\r\n const args = [`daemon`];\r\n if (props.addr !== undefined)\r\n args.push(`-addr`, `${props.addr}`);\r\n if (props.portNumber !== undefined)\r\n args.push(`-port`, `${props.portNumber}`);\r\n if (props.cacheSize)\r\n args.push(`-cachesize`, `${props.cacheSize}`);\r\n if (props.log)\r\n args.push(`-log`, `${props.log}`);\r\n if (props.noTimeStamps)\r\n args.push(`-notimestamps`);\r\n if (props.httptimeout !== undefined)\r\n args.push(`-httptimeout`, `${props.httptimeout}`)\r\n args.push(`${dir}`); // This MUST be the last arg when starting the daemon.\r\n return child_process.spawn(this.exeName(props), args, { ...props.spawnOptions, windowsVerbatimArguments: true });\r\n }\r\n }\r\n\r\n}\r\n"]}