un-cli 0.0.66 → 0.0.69

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/cmd.txt CHANGED
@@ -1,2 +1,2 @@
1
- export subnetworks --all --folder c:\temp
1
+ export subnetworks --all
2
2
  exit
package/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { AdminLog } from "./adminlog.mjs"
7
7
  import { logger } from "./logger.mjs"
8
8
  import fetch from "node-fetch"
9
9
  //update version
10
- let version = "0.0.66";
10
+ let version = "0.0.69";
11
11
  const GENERATE_TOKEN_TIME_MIN = 30;
12
12
 
13
13
  let rl = null;
@@ -172,8 +172,8 @@ const inputs = {
172
172
  "update subnetworks --all": "Update all dirty subnetworks synchronously",
173
173
  "update subnetworks --deleted": "Update all deleted dirty subnetworks synchronously",
174
174
  "update subnetworks --all --async": "Update all dirty subnetworks asynchronously",
175
- "export subnetworks --all": "Export all subnetworks with ACK ",
176
- "export subnetworks --new": "Export all subnetworks with ACK that haven't been exported ",
175
+ "export subnetworks --all [--folder]": "Export all subnetworks with ACK --folder where exported files are saved",
176
+ "export subnetworks --new [--folder]": "Export all subnetworks with ACK that haven't been exported --folder where exported files are saved",
177
177
  "export subnetworks --deleted": "Export all subnetworks with ACK that are deleted ",
178
178
  "count": "Lists the number of rows in all feature layers.",
179
179
  "count --system": "Lists the number of rows in system layers.",
@@ -247,7 +247,7 @@ const inputs = {
247
247
  // console.log('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyan
248
248
  const topoMoments = networkMoments.networkMoments.map(m => {
249
249
  const t = m.time === 0 ? "N/A": new Date(m.time*1000)
250
- const d = m.duration === 0 ? "N/A" : numberWithCommas(Math.round(m.duration/1000)) + " s"
250
+ const d = m.duration === 0 ? "N/A" : numberWithCommas(Math.round(m.duration)) + " ms"
251
251
  m.time = t.toString()
252
252
  m.duration = d;
253
253
  return m;
@@ -265,7 +265,7 @@ const inputs = {
265
265
  const result = await un.enableTopology()
266
266
  const toDate = new Date();
267
267
  const timeEnable = toDate.getTime() - fromDate.getTime();
268
- result.duration = numberWithCommas(Math.round(timeEnable/1000)) + " s"
268
+ result.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
269
269
  console.table(result)
270
270
  },
271
271
  "^topology --disable$": async () => {
@@ -274,7 +274,7 @@ const inputs = {
274
274
  const result = await un.disableTopology()
275
275
  const toDate = new Date();
276
276
  const timeEnable = toDate.getTime() - fromDate.getTime();
277
- result.duration = numberWithCommas(Math.round(timeEnable/1000)) + " s"
277
+ result.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
278
278
  console.table(result)
279
279
  },
280
280
  "^evaluate$": async () => {
@@ -296,7 +296,7 @@ const inputs = {
296
296
  const result = {}
297
297
  const toDate = new Date();
298
298
  const timeEnable = toDate.getTime() - fromDate.getTime();
299
- result.duration = numberWithCommas(Math.round(timeEnable/1000)) + " s"
299
+ result.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
300
300
  console.log(result)
301
301
  },
302
302
 
@@ -341,7 +341,7 @@ const inputs = {
341
341
  const result = await un.validateNetworkTopology("sde.DEFAULT", e)
342
342
  const toDate = new Date();
343
343
  const timeEnable = toDate.getTime() - fromDate.getTime();
344
- const duration = numberWithCommas(Math.round(timeEnable/1000)) + " s"
344
+ const duration = numberWithCommas(Math.round(timeEnable)) + " ms"
345
345
  console.clear()
346
346
  console.log("Validating extent " + e.xmin)
347
347
  console.table({duration})
@@ -357,7 +357,7 @@ const inputs = {
357
357
  const result = await un.validateNetworkTopology()
358
358
  const toDate = new Date();
359
359
  const timeEnable = toDate.getTime() - fromDate.getTime();
360
- result.duration = numberWithCommas(Math.round(timeEnable/1000)) + " s"
360
+ result.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
361
361
  console.table(result)
362
362
  },
363
363
  "^subnetworks --dirty$": async () => {
@@ -387,22 +387,21 @@ const inputs = {
387
387
 
388
388
  "^update subnetworks --deleted$" : async () => {
389
389
  console.log("Querying all subnetworks that are dirty and deleted.");
390
- let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1 and isdeleted=1");
390
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1 and isdeleted=1","domainnetworkname,tiername,subnetworkname");
391
391
  console.log(`Discovered ${subnetworks.features.length} dirty deleted subnetworks.`);
392
392
  for (let i = 0; i < subnetworks.features.length; i++) {
393
393
  const f = subnetworks.features[i]
394
394
  console.log("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
395
395
 
396
396
  const fromDate = new Date();
397
-
398
-
397
+
399
398
  const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
400
399
 
401
400
  //code
402
401
 
403
402
  const toDate = new Date();
404
403
  const timeEnable = toDate.getTime() - fromDate.getTime();
405
- subnetworkResult.duration = numberWithCommas(Math.round(timeEnable/1000)) + " s"
404
+ subnetworkResult.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
406
405
 
407
406
 
408
407
  console.log(`Result ${JSON.stringify(subnetworkResult)}`)
@@ -410,30 +409,34 @@ const inputs = {
410
409
  },
411
410
 
412
411
  "^update subnetworks --all$" : async () => {
413
- console.log("Querying all subnetworks that are dirty.");
414
- let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1");
415
- console.log(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
416
-
417
-
418
- for (let i = 0; i < subnetworks.features.length; i++) {
419
- const f = subnetworks.features[i]
420
- console.log("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
421
-
422
- const fromDate = new Date();
423
-
424
-
425
- const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
426
-
427
- const toDate = new Date();
428
- const timeEnable = toDate.getTime() - fromDate.getTime();
429
- subnetworkResult.duration = numberWithCommas(Math.round(timeEnable/1000)) + " s"
412
+
413
+ do {
414
+ console.log("Querying all subnetworks that are dirty.");
415
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1", "domainnetworkname,tiername,subnetworkname");
416
+ console.log(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
417
+
418
+ for (let i = 0; i < subnetworks.features.length; i++) {
419
+ const f = subnetworks.features[i]
420
+ console.log("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
421
+
422
+ const fromDate = new Date();
423
+
424
+ const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
425
+
426
+ const toDate = new Date();
427
+ const timeEnable = toDate.getTime() - fromDate.getTime();
428
+ subnetworkResult.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
429
+
430
+ console.log(`Result ${JSON.stringify(subnetworkResult)}`)
431
+ }
430
432
 
431
- console.log(`Result ${JSON.stringify(subnetworkResult)}`)
432
- }
433
+ }
434
+ while (subnetworks.features.length > 0)
435
+
433
436
  },
434
437
  "^update subnetworks --all --async$" : async () => {
435
438
  console.log("Querying all subnetworks that are dirty.");
436
- let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1");
439
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1", "domainnetworkname,tiername,subnetworkname");
437
440
  console.log(`Discovered ${subnetworks.features.length} dirty subnetworks.`);
438
441
  for (let i = 0; i < subnetworks.features.length; i++) {
439
442
  const f = subnetworks.features[i]
@@ -443,8 +446,7 @@ const inputs = {
443
446
  }
444
447
  },
445
448
  "^export subnetworks --all --folder .*$|^export subnetworks --all$" : async input => {
446
-
447
-
449
+
448
450
  //create folder
449
451
  const file = input.match(/--folder .*/gm)
450
452
  let inputDir = "Exported"
@@ -452,40 +454,49 @@ const inputs = {
452
454
  inputDir = file[0].replace("--folder ", "")
453
455
  //create directory if doesn't exists
454
456
  if (!fs.existsSync(inputDir)) fs.mkdirSync(inputDir)
455
-
456
-
457
- console.log("Querying all subnetworks that are clean.");
458
- let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=0");
459
- console.log(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
460
- for (let i = 0; i < subnetworks.features.length; i++) {
461
- const f = subnetworks.features[i]
462
- const subnetworkName = v(f.attributes,"subnetworkName")
463
- console.log("Exporting subnetworks " + v(f.attributes,"subnetworkName"));
464
-
465
- const fromDate = new Date();
466
-
467
- const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
468
-
469
-
470
- //code
471
-
472
- const toDate = new Date();
473
- const timeEnable = toDate.getTime() - fromDate.getTime();
474
- subnetworkResult.duration = numberWithCommas(timeEnable) + " ms"
475
-
476
-
477
- //fetch the json and write it to disk
478
- const subContent = await fetch(subnetworkResult.url);
479
- //check if the response is 200 only then attempt to parse to json
480
- //although the response is json, its easier to treat it as text (handle error cases) since we will only write it to disk.
481
- // if we want to do something with the response then make it json
482
- const jsonExport = await subContent.text();
483
- fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, jsonExport)
484
-
485
-
486
- console.log(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
487
-
457
+
458
+ do {
459
+
460
+ console.log("Querying all subnetworks that are clean.");
461
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=0","domainnetworkname,tiername,subnetworkname");
462
+ console.log(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
463
+ for (let i = 0; i < subnetworks.features.length; i++) {
464
+ const f = subnetworks.features[i]
465
+ const subnetworkName = v(f.attributes,"subnetworkName")
466
+ console.log("Exporting subnetworks " + v(f.attributes,"subnetworkName"));
467
+
468
+ const fromDate = new Date();
469
+
470
+ const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
471
+
472
+
473
+ //code
474
+
475
+ const toDate = new Date();
476
+ const timeEnable = toDate.getTime() - fromDate.getTime();
477
+ subnetworkResult.duration = numberWithCommas(timeEnable) + " ms"
478
+ //if undefined exit
479
+ if (!subnetworkResult.url)
480
+ {
481
+ console.log("Export subnetwork failed " + JSON.stringify(subnetworkResult))
482
+ continue;
483
+ }
484
+
485
+ //fetch the json and write it to disk
486
+ const subContent = await fetch(subnetworkResult.url);
487
+ //check if the response is 200 only then attempt to parse to json
488
+ //although the response is json, its easier to treat it as text (handle error cases) since we will only write it to disk.
489
+ // if we want to do something with the response then make it json
490
+ const jsonExport = await subContent.text();
491
+ fs.writeFileSync(`${inputDir}/${subnetworkName}.json`, jsonExport)
492
+
493
+
494
+ console.log(`Result ${JSON.stringify(subnetworkResult)} written to file ${process.cwd()}/${inputDir}/${subnetworkName}.json`)
495
+
496
+ }
488
497
  }
498
+ while (subnetworks.features.length > 0)
499
+
489
500
  },
490
501
 
491
502
 
@@ -501,7 +512,7 @@ const inputs = {
501
512
 
502
513
 
503
514
  console.log("Querying all subnetworks that are clean and not exported.");
504
- let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty = 0 and (LASTACKEXPORTSUBNETWORK is null or LASTACKEXPORTSUBNETWORK < LASTUPDATESUBNETWORK)");
515
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty = 0 and (LASTACKEXPORTSUBNETWORK is null or LASTACKEXPORTSUBNETWORK < LASTUPDATESUBNETWORK)","domainnetworkname,tiername,subnetworkname");
505
516
  console.log(`Discovered ${subnetworks.features.length} subnetworks that can be exported.`);
506
517
  for (let i = 0; i < subnetworks.features.length; i++) {
507
518
  const f = subnetworks.features[i]
@@ -555,7 +566,7 @@ const inputs = {
555
566
  const toDate = new Date();
556
567
  const timeRun = toDate.getTime() - fromDate.getTime();
557
568
  const newResult = {}
558
- newResult.duration = numberWithCommas(Math.round(timeRun/1000)) + " s"
569
+ newResult.duration = numberWithCommas(Math.round(timeRun)) + " ms"
559
570
  newResult.elementsCount = result.traceResults.elements.length;
560
571
  console.table(newResult)
561
572
 
@@ -579,6 +590,14 @@ const inputs = {
579
590
  const subnetworkName = v(f.attributes,"subnetworkName")
580
591
  console.log(`Exporting subnetwork ${subnetworkName}` );
581
592
  const subnetworkResult = await un.exportSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
593
+
594
+ //if undefined exit
595
+ if (!subnetworkResult.url)
596
+ {
597
+ console.log("Export subnetwork failed " + JSON.stringify(subnetworkResult))
598
+ continue;
599
+ }
600
+
582
601
  //fetch the json and write it to disk
583
602
  const subContent = await fetch(subnetworkResult.url);
584
603
  const jsonExport = await subContent.text();
@@ -889,15 +908,16 @@ const inputs = {
889
908
  allMessages = allMessages.concat(jsonRes.logMessages.filter(m => m.message.indexOf("EndCursor;") > -1))
890
909
  }
891
910
  console.log ("Filtering messages...")
911
+
892
912
  allMessages = allMessages
893
913
  .map( m=> {
894
914
  m.dataAccessElapsed = parseFloat(m.message.split(";")[1].split(" ")[1])
895
- m.ExecuteQueryElapsed = parseFloat(m.message.split(";")[2].split(" ")[1])
896
- m.totalTimeElapsed = m.dataAccessElapsed + m.ExecuteQueryElapsed
915
+ m.executeQueryElapsed = parseFloat(m.message.split(";")[2].split(" ")[1])
916
+ m.totalExecutionElapsed = m.dataAccessElapsed + m.executeQueryElapsed
897
917
  m.elapsed = parseFloat(m.elapsed); return m;
898
918
 
899
919
  })
900
- .sort( (m1,m2) => m2.totalTimeElapsed - m1.totalTimeElapsed)
920
+ .sort( (m1,m2) => m2.totalExecutionElapsed - m1.totalExecutionElapsed)
901
921
  .slice(0, 10) ;//first 10
902
922
 
903
923
 
@@ -907,11 +927,12 @@ const inputs = {
907
927
  {
908
928
 
909
929
  const x = m.message.split(";")
930
+ x.shift()
910
931
  console.log(`id: ${i++}`)
911
932
  console.log(`\tAt: ${new Date(m.time)} (${m.time})`)
912
933
  console.log(`\tUser: ${m.user}`)
913
- console.log(`\tElapsed: ${m.elapsed*1000} ms`)
914
- console.log(`\ttotalTimeElapsed: ${m.totalTimeElapsed} ms`)
934
+ console.log(`\tTotal Time: ${numberWithCommas(Math.round(m.elapsed*1000))} ms (Total time the cursor was opened)`)
935
+ console.log(`\tQuery Time: ${numberWithCommas(m.totalExecutionElapsed)} ms (includes search + data access nextRow)`)
915
936
  console.log(`\tQuery:`)
916
937
  x.forEach(a => console.log(`\t${a}`))
917
938
  console.log(`\n`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "un-cli",
3
- "version": "0.0.66",
3
+ "version": "0.0.69",
4
4
  "description": "Command line interface for working with ArcGIS Utility Network Extension",
5
5
  "main": "index.mjs",
6
6
  "bin": {
@@ -275,7 +275,7 @@ export class UtilityNetwork {
275
275
 
276
276
  }
277
277
 
278
- queryDistinct(layerId, field, where) {
278
+ queryDistinct(layerId, field, where, orderby) {
279
279
 
280
280
  let queryJson = {
281
281
  f: "json",
@@ -283,7 +283,9 @@ export class UtilityNetwork {
283
283
  outFields: field,
284
284
  where: where,
285
285
  gdbVersion:this.gdbVersion,
286
- returnDistinctValues: true
286
+ returnDistinctValues: true,
287
+ orderByFields: orderby,
288
+
287
289
  }
288
290
 
289
291
  queryJson.layerId = layerId