@onehat/data 1.17.3 → 1.17.5

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.
@@ -1214,6 +1214,10 @@ describe('Repository Base', function() {
1214
1214
  child = await id4.getLastChild();
1215
1215
  expect(child).to.be.null;
1216
1216
 
1217
+ // getPath
1218
+ const path = id4.getPath();
1219
+ expect(path).to.be.eq('1/2/4');
1220
+
1217
1221
  destoryRepository(repository);
1218
1222
  })();
1219
1223
  });
package/cypress.config.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { defineConfig } from "cypress";
2
2
  import webpackPreprocessor from "@cypress/webpack-preprocessor";
3
- import Webpack from "webpack";
4
3
 
5
4
  export default defineConfig({
6
5
  e2e: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.17.3",
3
+ "version": "1.17.5",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -40,7 +40,7 @@
40
40
  "accounting-js": "^1.1.1",
41
41
  "axios": "^1.4.0",
42
42
  "chrono-node": "^2.6.3",
43
- "fast-xml-parser": "^4.2.2",
43
+ "fast-xml-parser": "^4.2.4",
44
44
  "he": "^1.2.0",
45
45
  "js-base64": "^3.7.5",
46
46
  "lodash": "^4.17.21",
@@ -55,7 +55,7 @@
55
55
  "@babel/core": "^7.22.1",
56
56
  "@babel/node": "^7.22.1",
57
57
  "@babel/plugin-transform-class-properties": "^7.22.3",
58
- "@babel/plugin-transform-runtime": "^7.19.6",
58
+ "@babel/plugin-transform-runtime": "^7.22.4",
59
59
  "@babel/preset-env": "^7.22.4",
60
60
  "@babel/register": "^7.21.0",
61
61
  "@babel/runtime": "^7.22.3",
@@ -1773,6 +1773,29 @@ class Entity extends EventEmitter {
1773
1773
  return child;
1774
1774
  }
1775
1775
 
1776
+ /**
1777
+ * Gets the path to this node.
1778
+ * @return {string} path
1779
+ */
1780
+ getPath = () => {
1781
+ this.ensureTree();
1782
+ if (this.isDestroyed) {
1783
+ throw Error('this.getPath is no longer valid. TreeNode has been destroyed.');
1784
+ }
1785
+
1786
+ const parentIds = [];
1787
+ let parent = this;
1788
+ while(parent.hasParent) { // stops at root
1789
+ parentIds.push(parent.id);
1790
+ parent = parent.parent;
1791
+ }
1792
+ if (parent.id !== this.id) {
1793
+ parentIds.push(parent.id); // add root id
1794
+ }
1795
+
1796
+ return parentIds.reverse().join('/');
1797
+ }
1798
+
1776
1799
  /**
1777
1800
  * Helper to make sure this Repository is a tree
1778
1801
  * @private
@@ -559,10 +559,6 @@ class AjaxRepository extends Repository {
559
559
  url = this.api.add,
560
560
  data = entity.getSubmitValues();
561
561
 
562
- if (entity.isRemotePhantomMode) {
563
- data.isRemotePhantom = true;
564
- }
565
-
566
562
  return this._send(method, url, data)
567
563
  .then(result => {
568
564
  if (this.debugMode) {
@@ -610,9 +606,6 @@ class AjaxRepository extends Repository {
610
606
  data = {
611
607
  entities: _.map(entities, entity => {
612
608
  const values = entity.submitValues;
613
- if (entity.isRemotePhantomMode) {
614
- values.isRemotePhantom = true;
615
- }
616
609
  entity.isSaving = true;
617
610
  return values;
618
611
  }),
@@ -672,10 +665,6 @@ class AjaxRepository extends Repository {
672
665
  url = this.api.edit,
673
666
  data = entity.getSubmitValues();
674
667
 
675
- if (entity.isRemotePhantomMode) {
676
- data.isRemotePhantom = false;
677
- }
678
-
679
668
  return this._send(method, url, data)
680
669
  .then(result => {
681
670
  if (this.debugMode) {
@@ -723,9 +712,6 @@ class AjaxRepository extends Repository {
723
712
  data = {
724
713
  entities: _.map(entities, entity => {
725
714
  const values = entity.submitValues;
726
- if (entity.isRemotePhantomMode) {
727
- values.isRemotePhantom = false;
728
- }
729
715
  entity.isSaving = true;
730
716
  return values;
731
717
  }),
@@ -971,7 +957,7 @@ class AjaxRepository extends Repository {
971
957
  if (!promises.length) {
972
958
  return;
973
959
  }
974
- return this.axios.all(promises)
960
+ return Promise.all(promises)
975
961
  .then(this.axios.spread((...batchOperationResults) => {
976
962
  // All requests are now complete
977
963
 
@@ -414,12 +414,16 @@ class OneBuildRepository extends AjaxRepository {
414
414
  /**
415
415
  * Gets the root nodes of this tree.
416
416
  */
417
- getRootNodes = async (getChildren = false, depth) => {
417
+ getRootNodes = async (getChildren = false, depth, getChildParams) => {
418
418
  this.ensureTree();
419
419
  if (this.isDestroyed) {
420
420
  this.throwError('this.setRootNode is no longer valid. Repository has been destroyed.');
421
421
  return;
422
422
  }
423
+ if (!this.isOnline) {
424
+ this.throwError('Offline');
425
+ return;
426
+ }
423
427
 
424
428
  // Clear all entities, if any exist
425
429
  _.each(this.entities, (entity) => {
@@ -427,11 +431,84 @@ class OneBuildRepository extends AjaxRepository {
427
431
  });
428
432
  this.entities = [];
429
433
 
430
- // TODO: Load root nodes (and possibly their children)
434
+
435
+ const data = {
436
+ url: this.name + '/getRootNodes',
437
+ data: qs.stringify({
438
+ getChildren,
439
+ depth,
440
+ conditions: getChildParams ? getChildParams() : null
441
+ }),
442
+ method: 'POST',
443
+ baseURL: this.api.baseURL,
444
+ };
431
445
 
446
+ if (this.debugMode) {
447
+ console.log('getRootNodes', data);
448
+ }
432
449
 
450
+ return this.axios(data)
451
+ .then((result) => {
452
+ if (this.debugMode) {
453
+ console.log('getRootNodes response', result);
454
+ }
455
+
456
+ const response = result.data;
457
+ if (!response.success) {
458
+ this.throwError(response.data);
459
+ return;
460
+ }
461
+
462
+ // TODO: Load up the repository with these root nodes
463
+
464
+
465
+
466
+ });
433
467
  }
434
468
 
469
+ /**
470
+ * Searches all nodes for the supplied text.
471
+ * This basically takes the search query and returns whatever the server sends
472
+ */
473
+ searchTree = async (q) => {
474
+ this.ensureTree();
475
+ if (this.isDestroyed) {
476
+ this.throwError('this.searchTree is no longer valid. Repository has been destroyed.');
477
+ return;
478
+ }
479
+ if (!this.isOnline) {
480
+ this.throwError('Offline');
481
+ return;
482
+ }
483
+
484
+ const data = {
485
+ url: this.name + '/searchTree',
486
+ data: qs.stringify({
487
+ q,
488
+ }),
489
+ method: 'POST',
490
+ baseURL: this.api.baseURL,
491
+ };
492
+
493
+ if (this.debugMode) {
494
+ console.log('searchTree', data);
495
+ }
496
+
497
+ return this.axios(data)
498
+ .then((result) => {
499
+ if (this.debugMode) {
500
+ console.log('searchTree response', result);
501
+ }
502
+
503
+ const response = result.data;
504
+ if (!response.success) {
505
+ this.throwError(response.data);
506
+ return;
507
+ }
508
+
509
+ return response.data;
510
+ });
511
+ }
435
512
  /**
436
513
  * Loads the children of the supplied treeNode
437
514
  */