@itwin/workspace-editor 4.5.0-dev.9 → 4.6.0-dev.0

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright © 2017-2023 Bentley Systems, Incorporated. All rights reserved.
3
+ Copyright © 2017-2024 Bentley Systems, Incorporated. All rights reserved.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
@@ -17,7 +17,6 @@ const core_common_1 = require("@itwin/core-common");
17
17
  /* eslint-disable id-blacklist,no-console */
18
18
  /** Currently executing an "@" script? */
19
19
  let inScript = false;
20
- let logTimer;
21
20
  async function askQuestion(query) {
22
21
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
23
22
  return new Promise((resolve) => rl.question(query, (ans) => {
@@ -25,13 +24,8 @@ async function askQuestion(query) {
25
24
  resolve(ans);
26
25
  }));
27
26
  }
28
- function flushLog() {
29
- core_backend_1.IModelHost.platform.flushLog();
30
- }
31
- /** show a message, potentially flushing log messages first */
27
+ /** show a message */
32
28
  function showMessage(msg) {
33
- if (logTimer)
34
- flushLog();
35
29
  console.log(msg);
36
30
  }
37
31
  /** perform a vacuum on a database, with a message while it's happening */
@@ -52,7 +46,7 @@ function friendlyFileSize(size) {
52
46
  /** Create a new empty WorkspaceDb */
53
47
  async function createWorkspaceDb(args) {
54
48
  args.writeable = true;
55
- const wsFile = new core_backend_1.EditableWorkspaceDb(args, core_backend_1.IModelHost.appWorkspace.getContainer(args));
49
+ const wsFile = core_backend_1.EditableWorkspaceDb.construct(args, core_backend_1.IModelHost.appWorkspace.getContainer(args));
56
50
  await wsFile.createDb();
57
51
  showMessage(`created WorkspaceDb ${wsFile.sqliteDb.nativeDb.getFilePath()}`);
58
52
  wsFile.close();
@@ -82,15 +76,15 @@ function getCloudContainer(args) {
82
76
  return cloudContainer;
83
77
  }
84
78
  function fixVersionArg(args) {
85
- const dbParts = core_backend_1.ITwinWorkspaceContainer.parseDbFileName(args.dbName);
79
+ const dbParts = core_backend_1.WorkspaceContainer.parseDbFileName(args.dbName);
86
80
  args.dbName = dbParts.dbName;
87
81
  args.version = args.version ?? dbParts.version;
88
- args.dbFileName = core_backend_1.ITwinWorkspaceContainer.makeDbFileName(dbParts.dbName, dbParts.version);
82
+ args.dbFileName = core_backend_1.WorkspaceContainer.makeDbFileName(dbParts.dbName, dbParts.version);
89
83
  }
90
84
  /** Open for write, call a function to process, then close a WorkspaceDb */
91
85
  async function editWorkspace(args, fn) {
92
86
  fixVersionArg(args);
93
- const ws = new core_backend_1.EditableWorkspaceDb(args, getContainer(args));
87
+ const ws = core_backend_1.EditableWorkspaceDb.construct(args, getContainer(args));
94
88
  const cloudContainer = ws.container.cloudContainer;
95
89
  if (cloudContainer && cloudContainer.queryDatabase(ws.dbFileName)?.state !== "copied")
96
90
  throw new Error(`${args.dbFileName} is not editable. Create a new version first`);
@@ -99,7 +93,7 @@ async function editWorkspace(args, fn) {
99
93
  /** Open for read, call a function to process, then close a WorkspaceDb */
100
94
  async function readWorkspace(args, fn) {
101
95
  fixVersionArg(args);
102
- return processWorkspace(args, new core_backend_1.ITwinWorkspaceDb(args, getContainer(args)), fn);
96
+ return processWorkspace(args, core_backend_1.WorkspaceDb.construct(args, getContainer(args)), fn);
103
97
  }
104
98
  /** List the contents of a WorkspaceDb */
105
99
  async function listWorkspaceDb(args) {
@@ -248,7 +242,7 @@ async function removeResource(args) {
248
242
  async function vacuumWorkspaceDb(args) {
249
243
  const container = getContainer(args);
250
244
  fixVersionArg(args);
251
- const localFile = new core_backend_1.ITwinWorkspaceDb(args, container).dbFileName;
245
+ const localFile = core_backend_1.WorkspaceDb.construct(args, container).dbFileName;
252
246
  doVacuum(localFile, container.cloudContainer);
253
247
  }
254
248
  /** Either upload or download a WorkspaceDb to/from a cloud WorkspaceContainer. Shows progress % during transfer */
@@ -280,7 +274,7 @@ async function performTransfer(container, direction, args) {
280
274
  async function importWorkspaceDb(args) {
281
275
  const container = getCloudContainer(args);
282
276
  if ("" === (0, path_1.extname)(args.localFileName))
283
- args.localFileName = `${args.localFileName}.${core_backend_1.ITwinWorkspaceDb.fileExt}`;
277
+ args.localFileName = `${args.localFileName}.${core_backend_1.WorkspaceDb.fileExt}`;
284
278
  if (!core_backend_1.IModelJsFs.existsSync(args.localFileName))
285
279
  args.localFileName = (0, path_1.join)(args.directory ?? core_backend_1.IModelHost.appWorkspace.containerDir, args.localFileName);
286
280
  await core_backend_1.CloudSqlite.withWriteLock({ ...args, container }, async () => {
@@ -291,8 +285,8 @@ async function importWorkspaceDb(args) {
291
285
  /** export a WorkspaceDb from a cloud WorkspaceContainer. */
292
286
  async function exportWorkspaceDb(args) {
293
287
  if (!(0, path_1.extname)(args.localFileName))
294
- args.localFileName = `${args.localFileName}.${core_backend_1.ITwinWorkspaceDb.fileExt}`;
295
- const dbParts = core_backend_1.ITwinWorkspaceContainer.parseDbFileName(args.dbName);
288
+ args.localFileName = `${args.localFileName}.${core_backend_1.WorkspaceDb.fileExt}`;
289
+ const dbParts = core_backend_1.WorkspaceContainer.parseDbFileName(args.dbName);
296
290
  if (!dbParts.version)
297
291
  throw new Error("exportDb requires a version");
298
292
  await performTransfer(getCloudContainer(args), "download", args);
@@ -337,19 +331,20 @@ async function detachWorkspace(args) {
337
331
  }
338
332
  /** Make a copy of a WorkspaceDb with a new name. */
339
333
  async function copyWorkspaceDb(args) {
340
- const container = getCloudContainer(args);
341
- const oldName = core_backend_1.ITwinWorkspaceContainer.resolveCloudFileName(container, args);
342
- const newVersion = core_backend_1.ITwinWorkspaceContainer.parseDbFileName(args.newDbName);
343
- core_backend_1.ITwinWorkspaceContainer.validateDbName(newVersion.dbName);
344
- const newName = core_backend_1.ITwinWorkspaceContainer.makeDbFileName(newVersion.dbName, core_backend_1.ITwinWorkspaceContainer.validateVersion(newVersion.version));
345
- await core_backend_1.CloudSqlite.withWriteLock({ ...args, container }, async () => container.copyDatabase(oldName, newName));
334
+ const container = getContainer(args);
335
+ const oldName = container.resolveDbFileName(args);
336
+ const newVersion = core_backend_1.WorkspaceContainer.parseDbFileName(args.newDbName);
337
+ core_backend_1.WorkspaceContainer.validateDbName(newVersion.dbName);
338
+ const newName = core_backend_1.WorkspaceContainer.makeDbFileName(newVersion.dbName, core_backend_1.WorkspaceContainer.validateVersion(newVersion.version));
339
+ const cloudContainer = getCloudContainer(args);
340
+ await core_backend_1.CloudSqlite.withWriteLock({ ...args, container: cloudContainer }, async () => cloudContainer.copyDatabase(oldName, newName));
346
341
  showMessage(`copied WorkspaceDb [${oldName}] to [${newName}] in ${sayContainer(args)}`);
347
342
  }
348
343
  /** Make a copy of a WorkspaceDb with a new name. */
349
344
  async function versionWorkspaceDb(args) {
350
345
  fixVersionArg(args);
351
- const container = getCloudContainer(args);
352
- const result = await core_backend_1.ITwinWorkspaceContainer.makeNewVersion(container, args, args.versionType);
346
+ const container = getContainer(args);
347
+ const result = await container.makeNewVersion(args, args.versionType);
353
348
  showMessage(`created new version: [${result.newName}] from [${result.oldName}] in ${sayContainer(args)}`);
354
349
  }
355
350
  /** pin a WorkspaceDb from a WorkspaceContainer. */
@@ -420,7 +415,6 @@ function runCommand(cmd) {
420
415
  core_bentley_1.Logger.initializeToConsole();
421
416
  core_bentley_1.Logger.setLevel("CloudSqlite", core_bentley_1.LogLevel.Trace);
422
417
  core_backend_1.IModelHost.appWorkspace.getCloudCache().setLogMask(core_backend_1.CloudSqlite.LoggingMask.All);
423
- logTimer = setInterval(() => flushLog(), 250); // logging from other threads is buffered. This causes it to appear every 1/4 second.
424
418
  }
425
419
  await cmd(args);
426
420
  }
@@ -431,10 +425,6 @@ function runCommand(cmd) {
431
425
  console.log(core_bentley_1.BentleyError.getErrorMessage(e));
432
426
  }
433
427
  finally {
434
- if (logTimer) {
435
- flushLog();
436
- clearInterval(logTimer);
437
- }
438
428
  await core_backend_1.IModelHost.shutdown();
439
429
  }
440
430
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@itwin/workspace-editor",
3
3
  "license": "MIT",
4
4
  "main": "lib/WorkspaceEditor.js",
5
- "version": "4.5.0-dev.9",
5
+ "version": "4.6.0-dev.0",
6
6
  "bin": {
7
7
  "WorkspaceEditor": "./lib/WorkspaceEditor.js"
8
8
  },
@@ -17,9 +17,9 @@
17
17
  "dependencies": {
18
18
  "glob": "^7.1.2",
19
19
  "yargs": "^17.4.0",
20
- "@itwin/core-bentley": "4.5.0-dev.9",
21
- "@itwin/core-common": "4.5.0-dev.9",
22
- "@itwin/core-backend": "4.5.0-dev.9"
20
+ "@itwin/core-backend": "4.6.0-dev.0",
21
+ "@itwin/core-common": "4.6.0-dev.0",
22
+ "@itwin/core-bentley": "4.6.0-dev.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@itwin/eslint-plugin": "4.0.0-dev.44",
@@ -31,7 +31,7 @@
31
31
  "mocha": "^10.2.0",
32
32
  "rimraf": "^3.0.2",
33
33
  "typescript": "~5.0.2",
34
- "@itwin/build-tools": "4.5.0-dev.9"
34
+ "@itwin/build-tools": "4.6.0-dev.0"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsc 1>&2",