@itwin/workspace-editor 4.9.0-dev.1 → 4.9.0-dev.3

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.
@@ -17,7 +17,6 @@ const core_common_1 = require("@itwin/core-common");
17
17
  // cspell:ignore nodir nocase
18
18
  /* eslint-disable id-blacklist,no-console */
19
19
  /** Currently executing an "@" script? */
20
- let inScript = false;
21
20
  let wsEditor;
22
21
  async function askQuestion(query) {
23
22
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
@@ -45,13 +44,12 @@ function friendlyFileSize(size) {
45
44
  const units = Math.floor(Math.log(size) / Math.log(1024));
46
45
  return `${Math.round(size / Math.pow(1024, units))}${["", "K", "M", "G", "T"][units]}`;
47
46
  }
48
- // /** Create a new empty WorkspaceDb */
49
- // async function createWorkspaceDb(args: CreateWorkspaceDbOpt) {
50
- // const wsFile = WorkspaceEditor.createEmptyDb(args);, IModelHost.appWorkspace.getContainer(args));
51
- // await wsFile.createDb({ manifest: { workspaceName: args.workspaceName } });
52
- // showMessage(`created WorkspaceDb ${wsFile.sqliteDb.nativeDb.getFilePath()}`);
53
- // wsFile.close();
54
- // }
47
+ /** Create a new empty WorkspaceDb */
48
+ async function createWorkspaceDb(args) {
49
+ const container = getWriteContainer(args);
50
+ const wsDb = container.createDb({ ...args, dbName: args.dbName, manifest: { workspaceName: args.workspaceName } });
51
+ showMessage(`created WorkspaceDb ${(await wsDb).dbName}`);
52
+ }
55
53
  /** open, call a function to process, then close a WorkspaceDb */
56
54
  async function processWorkspace(args, ws, fn) {
57
55
  ws.open();
@@ -65,7 +63,7 @@ async function processWorkspace(args, ws, fn) {
65
63
  }
66
64
  /** get a WorkspaceContainer that may or may not be a cloud container. */
67
65
  function getWriteContainer(args) {
68
- return wsEditor.getContainer(args);
66
+ return wsEditor.getContainer({ ...args, writeable: true });
69
67
  }
70
68
  function getReadContainer(args) {
71
69
  return core_backend_1.IModelHost.appWorkspace.getContainer(args);
@@ -113,9 +111,9 @@ async function listWorkspaceDb(args) {
113
111
  const nameAndSize = (stmt, size, info) => showMessage(` name=${stmt.getValueString(0)}, size=${friendlyFileSize(size ?? stmt.getValueInteger(1))}${info ?? ""}`);
114
112
  if (args.strings) {
115
113
  showMessage(" strings:");
116
- file.sqliteDb.withSqliteStatement("SELECT id,LENGTH(value) FROM strings ORDER BY id COLLATE NOCASE", (stmt) => {
114
+ file.sqliteDb.withSqliteStatement("SELECT id,value FROM strings ORDER BY id COLLATE NOCASE", (stmt) => {
117
115
  while (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step())
118
- nameAndSize(stmt);
116
+ showMessage(` name="${stmt.getValueString(0)}" value=${stmt.getValueString(1)}`);
119
117
  });
120
118
  }
121
119
  if (args.blobs) {
@@ -310,13 +308,13 @@ async function initializeWorkspace(args) {
310
308
  if (undefined === args.storageType || !args.baseUri)
311
309
  throw new Error("No cloud container supplied");
312
310
  if (!args.noPrompt) {
313
- const yesNo = await askQuestion(`Are you sure you want to initialize ${sayContainer(args)}"? [y/n]: `);
311
+ const yesNo = await askQuestion(`Are you sure you want to initialize "${sayContainer(args)}"? [y/n]: `);
314
312
  if (yesNo[0].toUpperCase() !== "Y")
315
313
  return;
316
314
  }
317
315
  const container = core_backend_1.CloudSqlite.createCloudContainer(args);
318
316
  container.initializeContainer({ checksumBlockNames: true, blockSize: 4 * 1024 * 1024 });
319
- showMessage(`container "${args.containerId} initialized`);
317
+ showMessage(`container "${args.containerId}" initialized`);
320
318
  }
321
319
  /** purge unused (garbage) blocks from a WorkspaceContainer. */
322
320
  async function purgeWorkspace(args) {
@@ -399,14 +397,15 @@ async function queryWorkspaceDbs(args) {
399
397
  showMessage(` "${dbName}", size=${friendlyFileSize(db.totalBlocks * blockSize)}, ${friendlyFileSize(db.localBlocks * blockSize)} downloaded (${(100 * db.localBlocks / db.totalBlocks).toFixed(0)}%)${editable}${dirty}`);
400
398
  }
401
399
  }
400
+ if (dbs.length === 0) {
401
+ showMessage("...there aren't any.");
402
+ }
402
403
  }
403
404
  /** Start `IModelHost`, then run a WorkspaceEditor command. Errors are logged to console. */
404
405
  function runCommand(cmd, readonly) {
405
406
  return async (args) => {
406
407
  if (readonly === "readonly")
407
408
  args.forReadOnly = true;
408
- if (inScript)
409
- return cmd(args);
410
409
  try {
411
410
  const workspace = {
412
411
  containerDir: args.directory,
@@ -461,7 +460,7 @@ Yargs.options({
461
460
  });
462
461
  Yargs.command({
463
462
  command: "add <dbName> <files>",
464
- describe: "add files into a WorkspaceDb",
463
+ describe: "add a resource into a WorkspaceDb",
465
464
  builder: addOrReplace,
466
465
  handler: runCommand(addResource),
467
466
  });
@@ -498,14 +497,14 @@ Yargs.command({
498
497
  describe: "delete a WorkspaceDb from a cloud container",
499
498
  handler: runCommand(deleteWorkspaceDb),
500
499
  });
501
- // Yargs.command<CreateWorkspaceDbOpt>({
502
- // command: "createDb <dbName>",
503
- // describe: "create a new WorkspaceDb",
504
- // builder: {
505
- // workspaceName: { describe: "user interface name for the WorkspaceDb", string: true },
506
- // },
507
- // handler: runCommand(createWorkspaceDb),
508
- // });
500
+ Yargs.command({
501
+ command: "createDb <dbName>",
502
+ describe: "create a new WorkspaceDb",
503
+ builder: {
504
+ workspaceName: { describe: "user interface name for the WorkspaceDb", string: true },
505
+ },
506
+ handler: runCommand(createWorkspaceDb),
507
+ });
509
508
  Yargs.command({
510
509
  command: "copyDb <dbName> <newDbName>",
511
510
  describe: "make a copy of a WorkspaceDb in a cloud container with a new name",
@@ -582,7 +581,6 @@ Yargs.command({
582
581
  });
583
582
  /** execute an "@" script - a list of WorkspaceEditor commands */
584
583
  async function runScript(arg) {
585
- inScript = true;
586
584
  const val = fs.readFileSync(arg.scriptName, "utf-8");
587
585
  const lines = val.split(/\r?\n/);
588
586
  let i = 0;
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.9.0-dev.1",
5
+ "version": "4.9.0-dev.3",
6
6
  "bin": {
7
7
  "WorkspaceEditor": "./lib/WorkspaceEditor.js"
8
8
  },
@@ -17,9 +17,9 @@
17
17
  "dependencies": {
18
18
  "glob": "^10.3.12",
19
19
  "yargs": "^17.4.0",
20
- "@itwin/core-bentley": "4.9.0-dev.1",
21
- "@itwin/core-common": "4.9.0-dev.1",
22
- "@itwin/core-backend": "4.9.0-dev.1"
20
+ "@itwin/core-bentley": "4.9.0-dev.3",
21
+ "@itwin/core-common": "4.9.0-dev.3",
22
+ "@itwin/core-backend": "4.9.0-dev.3"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@itwin/eslint-plugin": "^4.0.2",
@@ -31,7 +31,7 @@
31
31
  "mocha": "^10.2.0",
32
32
  "rimraf": "^3.0.2",
33
33
  "typescript": "~5.3.3",
34
- "@itwin/build-tools": "4.9.0-dev.1"
34
+ "@itwin/build-tools": "4.9.0-dev.3"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsc 1>&2",