@itwin/workspace-editor 4.0.0-dev.24 → 4.0.0-dev.30

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.
@@ -82,19 +82,17 @@ function getCloudContainer(args) {
82
82
  return cloudContainer;
83
83
  }
84
84
  function fixVersionArg(args) {
85
- var _a;
86
85
  const dbParts = core_backend_1.ITwinWorkspaceContainer.parseDbFileName(args.dbName);
87
86
  args.dbName = dbParts.dbName;
88
- args.version = (_a = args.version) !== null && _a !== void 0 ? _a : dbParts.version;
87
+ args.version = args.version ?? dbParts.version;
89
88
  args.dbFileName = core_backend_1.ITwinWorkspaceContainer.makeDbFileName(dbParts.dbName, dbParts.version);
90
89
  }
91
90
  /** Open for write, call a function to process, then close a WorkspaceDb */
92
91
  async function editWorkspace(args, fn) {
93
- var _a;
94
92
  fixVersionArg(args);
95
93
  const ws = new core_backend_1.EditableWorkspaceDb(args, getContainer(args));
96
94
  const cloudContainer = ws.container.cloudContainer;
97
- if (cloudContainer && ((_a = cloudContainer.queryDatabase(ws.dbFileName)) === null || _a === void 0 ? void 0 : _a.state) !== "copied")
95
+ if (cloudContainer && cloudContainer.queryDatabase(ws.dbFileName)?.state !== "copied")
98
96
  throw new Error(`${args.dbFileName} is not editable. Create a new version first`);
99
97
  await processWorkspace(args, ws, fn);
100
98
  }
@@ -115,7 +113,7 @@ async function listWorkspaceDb(args) {
115
113
  }
116
114
  if (!args.strings && !args.blobs && !args.files)
117
115
  args.blobs = args.files = args.strings = true;
118
- const nameAndSize = (stmt, size, info) => showMessage(` name=${stmt.getValueString(0)}, size=${friendlyFileSize(size !== null && size !== void 0 ? size : stmt.getValueInteger(1))}${info !== null && info !== void 0 ? info : ""}`);
116
+ const nameAndSize = (stmt, size, info) => showMessage(` name=${stmt.getValueString(0)}, size=${friendlyFileSize(size ?? stmt.getValueInteger(1))}${info ?? ""}`);
119
117
  if (args.strings) {
120
118
  showMessage(" strings:");
121
119
  file.sqliteDb.withSqliteStatement("SELECT id,LENGTH(value) FROM strings ORDER BY id COLLATE NOCASE", (stmt) => {
@@ -161,13 +159,11 @@ async function listWorkspaceDb(args) {
161
159
  /** Add files into a WorkspaceDb. */
162
160
  async function addResource(args) {
163
161
  return editWorkspace(args, async (wsFile, args) => {
164
- var _a;
165
- glob.sync(args.files, { cwd: (_a = args.root) !== null && _a !== void 0 ? _a : process.cwd(), nodir: true }).forEach((filePath) => {
166
- var _a;
162
+ glob.sync(args.files, { cwd: args.root ?? process.cwd(), nodir: true }).forEach((filePath) => {
167
163
  const file = args.root ? (0, path_1.join)(args.root, filePath) : filePath;
168
164
  if (!core_backend_1.IModelJsFs.existsSync(file))
169
165
  throw new Error(`file [${file}] does not exist`);
170
- const name = (_a = args.rscName) !== null && _a !== void 0 ? _a : filePath;
166
+ const name = args.rscName ?? filePath;
171
167
  try {
172
168
  if (args.type === "string") {
173
169
  const val = fs.readFileSync(file, "utf-8");
@@ -191,13 +187,11 @@ async function addResource(args) {
191
187
  /** Replace files in a WorkspaceDb. */
192
188
  async function replaceResource(args) {
193
189
  return editWorkspace(args, async (wsFile, args) => {
194
- var _a;
195
- glob.sync(args.files, { cwd: (_a = args.root) !== null && _a !== void 0 ? _a : process.cwd(), nodir: true }).forEach((filePath) => {
196
- var _a;
190
+ glob.sync(args.files, { cwd: args.root ?? process.cwd(), nodir: true }).forEach((filePath) => {
197
191
  const file = args.root ? (0, path_1.join)(args.root, filePath) : filePath;
198
192
  if (!core_backend_1.IModelJsFs.existsSync(file))
199
193
  throw new Error(`file [${file}] does not exist`);
200
- const name = (_a = args.rscName) !== null && _a !== void 0 ? _a : filePath;
194
+ const name = args.rscName ?? filePath;
201
195
  try {
202
196
  if (args.type === "string") {
203
197
  const val = fs.readFileSync(file, "utf-8");
@@ -284,12 +278,11 @@ async function performTransfer(container, direction, args) {
284
278
  }
285
279
  /** import a WorkspaceDb to a cloud WorkspaceContainer. */
286
280
  async function importWorkspaceDb(args) {
287
- var _a;
288
281
  const container = getCloudContainer(args);
289
282
  if ("" === (0, path_1.extname)(args.localFileName))
290
283
  args.localFileName = `${args.localFileName}.${core_backend_1.ITwinWorkspaceDb.fileExt}`;
291
284
  if (!core_backend_1.IModelJsFs.existsSync(args.localFileName))
292
- args.localFileName = (0, path_1.join)((_a = args.directory) !== null && _a !== void 0 ? _a : core_backend_1.IModelHost.appWorkspace.containerDir, args.localFileName);
285
+ args.localFileName = (0, path_1.join)(args.directory ?? core_backend_1.IModelHost.appWorkspace.containerDir, args.localFileName);
293
286
  await core_backend_1.CloudSqlite.withWriteLock(args.user, container, async () => {
294
287
  await performTransfer(container, "upload", args);
295
288
  });
@@ -412,7 +405,6 @@ async function queryWorkspaceDbs(args) {
412
405
  /** Start `IModelHost`, then run a WorkspaceEditor command. Errors are logged to console. */
413
406
  function runCommand(cmd) {
414
407
  return async (args) => {
415
- var _a;
416
408
  if (inScript)
417
409
  return cmd(args);
418
410
  try {
@@ -427,7 +419,7 @@ function runCommand(cmd) {
427
419
  if (true === args.logging) {
428
420
  core_bentley_1.Logger.initializeToConsole();
429
421
  core_bentley_1.Logger.setLevel("CloudSqlite", core_bentley_1.LogLevel.Trace);
430
- (_a = core_backend_1.IModelHost.appWorkspace.cloudCache) === null || _a === void 0 ? void 0 : _a.setLogMask(core_backend_1.CloudSqlite.LoggingMask.All);
422
+ core_backend_1.IModelHost.appWorkspace.cloudCache?.setLogMask(core_backend_1.CloudSqlite.LoggingMask.All);
431
423
  logTimer = setInterval(() => flushLog(), 250); // logging from other threads is buffered. This causes it to appear every 1/4 second.
432
424
  }
433
425
  await cmd(args);
@@ -610,8 +602,7 @@ async function runScript(arg) {
610
602
  }
611
603
  /** Parse and execute WorkspaceEditor commands */
612
604
  async function main() {
613
- var _a;
614
- if (process.argv.length > 1 && ((_a = process.argv[2]) === null || _a === void 0 ? void 0 : _a[0]) === "@") {
605
+ if (process.argv.length > 1 && process.argv[2]?.[0] === "@") {
615
606
  const parsed = Yargs.parseSync(process.argv.slice(3));
616
607
  if (parsed.config)
617
608
  process.env.WORKSPACE_EDITOR_CONFIG = parsed.config;
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.0.0-dev.24",
5
+ "version": "4.0.0-dev.30",
6
6
  "bin": {
7
7
  "WorkspaceEditor": "./lib/WorkspaceEditor.js"
8
8
  },
@@ -14,15 +14,15 @@
14
14
  "url": "https://github.com/iTwin/itwinjs-core/tree/master/utils/workspace-editor"
15
15
  },
16
16
  "dependencies": {
17
- "@itwin/core-bentley": "4.0.0-dev.24",
18
- "@itwin/core-common": "4.0.0-dev.24",
19
- "@itwin/core-backend": "4.0.0-dev.24",
17
+ "@itwin/core-bentley": "4.0.0-dev.30",
18
+ "@itwin/core-common": "4.0.0-dev.30",
19
+ "@itwin/core-backend": "4.0.0-dev.30",
20
20
  "glob": "^7.1.2",
21
21
  "yargs": "^17.4.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@itwin/build-tools": "4.0.0-dev.24",
25
- "@itwin/eslint-plugin": "4.0.0-dev.24",
24
+ "@itwin/build-tools": "4.0.0-dev.30",
25
+ "@itwin/eslint-plugin": "4.0.0-dev.30",
26
26
  "@types/chai": "4.3.1",
27
27
  "@types/mocha": "^8.2.2",
28
28
  "@types/yargs": "17.0.19",