@weborigami/async-tree 0.2.5 → 0.2.7

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Jan Miksovsky and other contributors
3
+ Copyright (c) 2025 Jan Miksovsky and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/async-tree",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Asynchronous tree drivers based on standard JavaScript classes",
5
5
  "type": "module",
6
6
  "main": "./main.js",
@@ -11,7 +11,7 @@
11
11
  "typescript": "5.7.2"
12
12
  },
13
13
  "dependencies": {
14
- "@weborigami/types": "0.2.5"
14
+ "@weborigami/types": "0.2.7"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "node --test --test-reporter=spec",
@@ -1,6 +1,6 @@
1
1
  import * as trailingSlash from "../trailingSlash.js";
2
2
 
3
- const treeToCaches = new WeakMap();
3
+ const treeToCaches = new Map();
4
4
 
5
5
  /**
6
6
  * Given a key function, return a new key function and inverse key function that
@@ -111,12 +111,10 @@ function searchKeyMap(keyMap, key) {
111
111
  let match;
112
112
  if (keyMap.has(key)) {
113
113
  match = keyMap.get(key);
114
- } else if (!trailingSlash.has(key)) {
115
- // Check key without trailing slash
116
- const withSlash = trailingSlash.add(key);
117
- if (keyMap.has(withSlash)) {
118
- match = keyMap.get(withSlash);
119
- }
114
+ } else {
115
+ // Check alternative with/without slash
116
+ const alternativeKey = trailingSlash.toggle(key, !trailingSlash.has(key));
117
+ match = keyMap.get(alternativeKey);
120
118
  }
121
119
  return match
122
120
  ? trailingSlash.toggle(match, trailingSlash.has(key))
@@ -20,14 +20,16 @@ export default async function concatTreeValues(treelike) {
20
20
  for await (const value of deepValuesIterator(treelike, { expand: true })) {
21
21
  let string;
22
22
  if (value === null) {
23
- console.warn("Warning: Origami template encountered a null value");
24
23
  string = "null";
25
24
  } else if (value === undefined) {
26
- console.warn("Warning: Origami template encountered an undefined value");
27
25
  string = "undefined";
28
26
  } else {
29
27
  string = toString(value);
30
28
  }
29
+ if (value === null || value === undefined) {
30
+ const message = `Warning: Origami template encountered a ${string} value. To locate where this happened, build your project and search your build output for the text "${string}".`;
31
+ console.warn(message);
32
+ }
31
33
  strings.push(string);
32
34
  }
33
35
  return strings.join("");
@@ -13,6 +13,6 @@ export function keysFromPath(path: string): string[];
13
13
  export const naturalOrder: (a: string, b: string) => number;
14
14
  export function pathFromKeys(keys: string[]): string;
15
15
  export function pipeline(start: any, ...functions: Function[]): Promise<any>;
16
- export function setParent(child: any, parent: AsyncTree): void;
16
+ export function setParent(child: any, parent: AsyncTree|null): void;
17
17
  export function toPlainValue(object: any): Promise<any>;
18
18
  export function toString(object: any): string;
package/src/utilities.js CHANGED
@@ -5,6 +5,8 @@ import * as trailingSlash from "./trailingSlash.js";
5
5
  const textDecoder = new TextDecoder();
6
6
  const TypedArray = Object.getPrototypeOf(Uint8Array);
7
7
 
8
+ /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
9
+
8
10
  /**
9
11
  * Return the value as an object. If the value is already an object it will be
10
12
  * returned as is. If the value is a primitive, it will be wrapped in an object:
@@ -219,8 +221,12 @@ export const naturalOrder = new Intl.Collator(undefined, {
219
221
  * @param {string[]} keys
220
222
  */
221
223
  export function pathFromKeys(keys) {
222
- const normalized = keys.map((key) => trailingSlash.remove(key));
223
- return normalized.join("/");
224
+ // Ensure there's a slash between all keys. If the last key has a trailing
225
+ // slash, leave it there.
226
+ const normalized = keys.map((key, index) =>
227
+ index < keys.length - 1 ? trailingSlash.add(key) : key
228
+ );
229
+ return normalized.join("");
224
230
  }
225
231
 
226
232
  /**
@@ -240,7 +246,7 @@ export async function pipeline(start, ...fns) {
240
246
  * set the `symbols.parent` property.
241
247
  *
242
248
  * @param {*} child
243
- * @param {*} parent
249
+ * @param {AsyncTree|null} parent
244
250
  */
245
251
  export function setParent(child, parent) {
246
252
  if (Tree.isAsyncTree(child)) {
@@ -59,6 +59,7 @@ describe("utilities", () => {
59
59
  assert.equal(utilities.pathFromKeys([]), "");
60
60
  assert.equal(utilities.pathFromKeys(["a", "b", "c"]), "a/b/c");
61
61
  assert.equal(utilities.pathFromKeys(["a/", "b/", "c"]), "a/b/c");
62
+ assert.equal(utilities.pathFromKeys(["a/", "b/", "c/"]), "a/b/c/");
62
63
  });
63
64
 
64
65
  test("pipeline applies a series of functions to a value", async () => {