@weborigami/async-tree 0.3.3-jse.2 → 0.3.3-jse.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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@weborigami/async-tree",
3
- "version": "0.3.3-jse.2",
3
+ "version": "0.3.3-jse.3",
4
4
  "description": "Asynchronous tree drivers based on standard JavaScript classes",
5
5
  "type": "module",
6
6
  "main": "./main.js",
7
7
  "browser": "./browser.js",
8
8
  "types": "./index.ts",
9
9
  "dependencies": {
10
- "@weborigami/types": "0.3.3-jse.2"
10
+ "@weborigami/types": "0.3.3-jse.3"
11
11
  },
12
12
  "devDependencies": {
13
13
  "@types/node": "22.13.13",
package/src/Tree.d.ts CHANGED
@@ -21,4 +21,4 @@ export function toFunction(tree: Treelike): Function;
21
21
  export function traverse(tree: Treelike, ...keys: any[]): Promise<any>;
22
22
  export function traverseOrThrow(tree: Treelike, ...keys: any[]): Promise<any>;
23
23
  export function traversePath(tree: Treelike, path: string): Promise<any>;
24
- export function values(AsyncTree: AsyncTree): Promise<IterableIterator<any>>;
24
+ export function values(tree: Treelike): Promise<IterableIterator<any>>;
package/src/Tree.js CHANGED
@@ -26,8 +26,6 @@ import {
26
26
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
27
27
  */
28
28
 
29
- const treeModule = this;
30
-
31
29
  /**
32
30
  * Apply the key/values pairs from the source tree to the target tree.
33
31
  *
@@ -362,8 +360,8 @@ export async function remove(tree, key) {
362
360
  */
363
361
  export function root(tree) {
364
362
  let current = from(tree);
365
- while (current.parent) {
366
- current = current.parent;
363
+ while (current.parent || current[symbols.parent]) {
364
+ current = current.parent || current[symbols.parent];
367
365
  }
368
366
  return current;
369
367
  }
@@ -416,7 +414,7 @@ export async function traverseOrThrow(treelike, ...keys) {
416
414
 
417
415
  // If traversal operation was called with a `this` context, use that as the
418
416
  // target for function calls.
419
- const target = this === treeModule ? undefined : this;
417
+ const target = this;
420
418
 
421
419
  // Process all the keys.
422
420
  const remainingKeys = keys.slice();
@@ -473,9 +471,10 @@ export async function traversePath(tree, path) {
473
471
  /**
474
472
  * Return the values in the specific node of the tree.
475
473
  *
476
- * @param {AsyncTree} tree
474
+ * @param {Treelike} treelike
477
475
  */
478
- export async function values(tree) {
476
+ export async function values(treelike) {
477
+ const tree = from(treelike);
479
478
  const keys = Array.from(await tree.keys());
480
479
  const promises = keys.map(async (key) => tree.get(key));
481
480
  return Promise.all(promises);
@@ -85,7 +85,12 @@ export default class FileTree {
85
85
  value = Uint8Array.from(buffer);
86
86
  }
87
87
 
88
- setParent(value, this);
88
+ const parent =
89
+ key === ".."
90
+ ? // Special case: ".." parent is the grandparent (if it exists)
91
+ this.parent?.parent
92
+ : this;
93
+ setParent(value, parent);
89
94
  return value;
90
95
  }
91
96
 
@@ -16,7 +16,17 @@ import * as trailingSlash from "../trailingSlash.js";
16
16
  * @returns {AsyncTree & { description: string, trees: AsyncTree[]}}
17
17
  */
18
18
  export default function merge(...sources) {
19
- const trees = sources.map((treelike) => Tree.from(treelike));
19
+ const trees = sources
20
+ .filter((source) => source)
21
+ .map((treelike) => Tree.from(treelike));
22
+
23
+ if (trees.length === 0) {
24
+ throw new TypeError("merge: all trees are null or undefined");
25
+ } else if (trees.length === 1) {
26
+ // Only one tree, no need to merge
27
+ return trees[0];
28
+ }
29
+
20
30
  return {
21
31
  description: "merge",
22
32