@weborigami/async-tree 0.0.43 → 0.0.44
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 +2 -2
- package/src/ObjectTree.js +5 -0
- package/src/SetTree.js +1 -1
- package/src/Tree.js +3 -3
- package/src/transforms/map.js +1 -1
- package/src/transforms/regExpKeys.js +1 -1
- package/src/transforms/sort.js +1 -1
- package/test/BrowserFileTree.test.js +5 -4
- package/test/FileTree.test.js +5 -4
- package/test/FunctionTree.test.js +5 -4
- package/test/MapTree.test.js +1 -1
- package/test/ObjectTree.test.js +12 -4
- package/test/SetTree.test.js +1 -1
- package/test/SiteTree.test.js +5 -1
- package/test/Tree.test.js +15 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/async-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
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.3.3"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/types": "0.0.
|
|
14
|
+
"@weborigami/types": "0.0.44"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "node --test --test-reporter=spec",
|
package/src/ObjectTree.js
CHANGED
|
@@ -41,6 +41,11 @@ export default class ObjectTree {
|
|
|
41
41
|
value.parent = this;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
if (typeof value === "function" && !Object.hasOwn(this.object, key)) {
|
|
45
|
+
// Value is an inherited method; bind it to the object.
|
|
46
|
+
value = value.bind(this.object);
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
return value;
|
|
45
50
|
}
|
|
46
51
|
|
package/src/SetTree.js
CHANGED
package/src/Tree.js
CHANGED
|
@@ -74,7 +74,7 @@ export async function clear(tree) {
|
|
|
74
74
|
* @param {AsyncTree} tree
|
|
75
75
|
*/
|
|
76
76
|
export async function entries(tree) {
|
|
77
|
-
const keys =
|
|
77
|
+
const keys = Array.from(await tree.keys());
|
|
78
78
|
const promises = keys.map(async (key) => [key, await tree.get(key)]);
|
|
79
79
|
return Promise.all(promises);
|
|
80
80
|
}
|
|
@@ -87,7 +87,7 @@ export async function entries(tree) {
|
|
|
87
87
|
* @param {Function} callbackFn
|
|
88
88
|
*/
|
|
89
89
|
export async function forEach(tree, callbackFn) {
|
|
90
|
-
const keys =
|
|
90
|
+
const keys = Array.from(await tree.keys());
|
|
91
91
|
const promises = keys.map(async (key) => {
|
|
92
92
|
const value = await tree.get(key);
|
|
93
93
|
return callbackFn(value, key);
|
|
@@ -430,7 +430,7 @@ class TraverseError extends ReferenceError {
|
|
|
430
430
|
* @param {AsyncTree} tree
|
|
431
431
|
*/
|
|
432
432
|
export async function values(tree) {
|
|
433
|
-
const keys =
|
|
433
|
+
const keys = Array.from(await tree.keys());
|
|
434
434
|
const promises = keys.map(async (key) => tree.get(key));
|
|
435
435
|
return Promise.all(promises);
|
|
436
436
|
}
|
package/src/transforms/map.js
CHANGED
|
@@ -100,7 +100,7 @@ export default function createMapTransform(options) {
|
|
|
100
100
|
if (keyMap) {
|
|
101
101
|
transformed.keys = async () => {
|
|
102
102
|
// Apply the keyMap to source keys for leaf values (not subtrees).
|
|
103
|
-
const sourceKeys =
|
|
103
|
+
const sourceKeys = Array.from(await tree.keys());
|
|
104
104
|
const mapped = await Promise.all(
|
|
105
105
|
sourceKeys.map(async (sourceKey) => {
|
|
106
106
|
let resultKey;
|
package/src/transforms/sort.js
CHANGED
|
@@ -13,7 +13,7 @@ export default function createSortTransform(compareFn) {
|
|
|
13
13
|
return function sortTransform(tree) {
|
|
14
14
|
const transform = Object.create(tree);
|
|
15
15
|
transform.keys = async () => {
|
|
16
|
-
const keys =
|
|
16
|
+
const keys = Array.from(await tree.keys());
|
|
17
17
|
keys.sort(compareFn);
|
|
18
18
|
return keys;
|
|
19
19
|
};
|
|
@@ -9,10 +9,11 @@ if (isBrowser) {
|
|
|
9
9
|
describe("BrowserFileTree", async () => {
|
|
10
10
|
test("can get the keys of the tree", async () => {
|
|
11
11
|
const fixture = await createFixture();
|
|
12
|
-
assert.deepEqual(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
assert.deepEqual(Array.from(await fixture.keys()), [
|
|
13
|
+
"Alice.md",
|
|
14
|
+
"Bob.md",
|
|
15
|
+
"Carol.md",
|
|
16
|
+
]);
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
test("can get the value for a key", async () => {
|
package/test/FileTree.test.js
CHANGED
|
@@ -12,10 +12,11 @@ const tempDirectory = path.join(dirname, "fixtures/temp");
|
|
|
12
12
|
describe("FileTree", async () => {
|
|
13
13
|
test("can get the keys of the tree", async () => {
|
|
14
14
|
const fixture = createFixture("fixtures/markdown");
|
|
15
|
-
assert.deepEqual(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
assert.deepEqual(Array.from(await fixture.keys()), [
|
|
16
|
+
"Alice.md",
|
|
17
|
+
"Bob.md",
|
|
18
|
+
"Carol.md",
|
|
19
|
+
]);
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
test("can get the value for a key", async () => {
|
|
@@ -5,10 +5,11 @@ import FunctionTree from "../src/FunctionTree.js";
|
|
|
5
5
|
describe("FunctionTree", async () => {
|
|
6
6
|
test("can get the keys of the tree", async () => {
|
|
7
7
|
const fixture = createFixture();
|
|
8
|
-
assert.deepEqual(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
assert.deepEqual(Array.from(await fixture.keys()), [
|
|
9
|
+
"Alice.md",
|
|
10
|
+
"Bob.md",
|
|
11
|
+
"Carol.md",
|
|
12
|
+
]);
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
test("can get the value for a key", async () => {
|
package/test/MapTree.test.js
CHANGED
|
@@ -5,7 +5,7 @@ import MapTree from "../src/MapTree.js";
|
|
|
5
5
|
describe("MapTree", () => {
|
|
6
6
|
test("can get the keys of the tree", async () => {
|
|
7
7
|
const fixture = createFixture();
|
|
8
|
-
assert.deepEqual(
|
|
8
|
+
assert.deepEqual(Array.from(await fixture.keys()), ["a", "b", "c"]);
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
test("can get the value for a key", async () => {
|
package/test/ObjectTree.test.js
CHANGED
|
@@ -6,10 +6,11 @@ import * as Tree from "../src/Tree.js";
|
|
|
6
6
|
describe("ObjectTree", () => {
|
|
7
7
|
test("can get the keys of the tree", async () => {
|
|
8
8
|
const fixture = createFixture();
|
|
9
|
-
assert.deepEqual(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
assert.deepEqual(Array.from(await fixture.keys()), [
|
|
10
|
+
"Alice.md",
|
|
11
|
+
"Bob.md",
|
|
12
|
+
"Carol.md",
|
|
13
|
+
]);
|
|
13
14
|
});
|
|
14
15
|
|
|
15
16
|
test("can get the value for a key", async () => {
|
|
@@ -115,6 +116,13 @@ describe("ObjectTree", () => {
|
|
|
115
116
|
});
|
|
116
117
|
assert.equal(await tree.get("subtree"), subtree);
|
|
117
118
|
});
|
|
119
|
+
|
|
120
|
+
test("method on an object is bound to the object", async () => {
|
|
121
|
+
const n = new Number(123);
|
|
122
|
+
const tree = new ObjectTree(n);
|
|
123
|
+
const method = await tree.get("toString");
|
|
124
|
+
assert.equal(method(), "123");
|
|
125
|
+
});
|
|
118
126
|
});
|
|
119
127
|
|
|
120
128
|
function createFixture() {
|
package/test/SetTree.test.js
CHANGED
|
@@ -7,7 +7,7 @@ describe("SetTree", () => {
|
|
|
7
7
|
test("can get the keys of the tree", async () => {
|
|
8
8
|
const set = new Set(["a", "b", "c"]);
|
|
9
9
|
const fixture = new SetTree(set);
|
|
10
|
-
assert.deepEqual(
|
|
10
|
+
assert.deepEqual(Array.from(await fixture.keys()), [0, 1, 2]);
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
test("can get the value for a key", async () => {
|
package/test/SiteTree.test.js
CHANGED
|
@@ -43,7 +43,11 @@ describe("SiteTree", () => {
|
|
|
43
43
|
const fixture = new SiteTree(mockHost);
|
|
44
44
|
const about = fixture.resolve("about");
|
|
45
45
|
const keys = await about.keys();
|
|
46
|
-
assert.deepEqual(
|
|
46
|
+
assert.deepEqual(Array.from(keys), [
|
|
47
|
+
"Alice.html",
|
|
48
|
+
"Bob.html",
|
|
49
|
+
"Carol.html",
|
|
50
|
+
]);
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
test("can get the value for a key", async () => {
|
package/test/Tree.test.js
CHANGED
|
@@ -55,19 +55,16 @@ describe("Tree", () => {
|
|
|
55
55
|
test("clear() removes all values", async () => {
|
|
56
56
|
const fixture = createFixture();
|
|
57
57
|
await Tree.clear(fixture);
|
|
58
|
-
assert.deepEqual(
|
|
58
|
+
assert.deepEqual(Array.from(await Tree.entries(fixture)), []);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
test("entries() returns the [key, value] pairs", async () => {
|
|
62
62
|
const fixture = createFixture();
|
|
63
|
-
assert.deepEqual(
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
["Carol.md", "Hello, **Carol**."],
|
|
69
|
-
]
|
|
70
|
-
);
|
|
63
|
+
assert.deepEqual(Array.from(await Tree.entries(fixture)), [
|
|
64
|
+
["Alice.md", "Hello, **Alice**."],
|
|
65
|
+
["Bob.md", "Hello, **Bob**."],
|
|
66
|
+
["Carol.md", "Hello, **Carol**."],
|
|
67
|
+
]);
|
|
71
68
|
});
|
|
72
69
|
|
|
73
70
|
test("forEach() invokes a callback for each entry", async () => {
|
|
@@ -246,13 +243,10 @@ describe("Tree", () => {
|
|
|
246
243
|
test("remove method removes a value", async () => {
|
|
247
244
|
const fixture = createFixture();
|
|
248
245
|
await Tree.remove(fixture, "Alice.md");
|
|
249
|
-
assert.deepEqual(
|
|
250
|
-
[
|
|
251
|
-
[
|
|
252
|
-
|
|
253
|
-
["Carol.md", "Hello, **Carol**."],
|
|
254
|
-
]
|
|
255
|
-
);
|
|
246
|
+
assert.deepEqual(Array.from(await Tree.entries(fixture)), [
|
|
247
|
+
["Bob.md", "Hello, **Bob**."],
|
|
248
|
+
["Carol.md", "Hello, **Carol**."],
|
|
249
|
+
]);
|
|
256
250
|
});
|
|
257
251
|
|
|
258
252
|
test("toFunction returns a function that invokes a tree's get() method", async () => {
|
|
@@ -337,10 +331,11 @@ describe("Tree", () => {
|
|
|
337
331
|
|
|
338
332
|
test("values() returns the store's values", async () => {
|
|
339
333
|
const fixture = createFixture();
|
|
340
|
-
assert.deepEqual(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
334
|
+
assert.deepEqual(Array.from(await Tree.values(fixture)), [
|
|
335
|
+
"Hello, **Alice**.",
|
|
336
|
+
"Hello, **Bob**.",
|
|
337
|
+
"Hello, **Carol**.",
|
|
338
|
+
]);
|
|
344
339
|
});
|
|
345
340
|
});
|
|
346
341
|
|