@weborigami/async-tree 0.2.2 → 0.2.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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jan Miksovsky and other contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/async-tree",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.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
|
"devDependencies": {
|
|
10
|
-
"@types/node": "22.
|
|
11
|
-
"typescript": "5.
|
|
10
|
+
"@types/node": "22.10.2",
|
|
11
|
+
"typescript": "5.7.2"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/types": "0.2.
|
|
14
|
+
"@weborigami/types": "0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "node --test --test-reporter=spec",
|
|
@@ -66,6 +66,11 @@ export default class ObjectTree {
|
|
|
66
66
|
* Enumerate the object's keys.
|
|
67
67
|
*/
|
|
68
68
|
async keys() {
|
|
69
|
+
// Defer to symbols.keys if defined
|
|
70
|
+
if (typeof this.object[symbols.keys] === "function") {
|
|
71
|
+
return this.object[symbols.keys]();
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
// Walk up the prototype chain to realm's Object.prototype.
|
|
70
75
|
let obj = this.object;
|
|
71
76
|
const objectPrototype = getRealmObjectPrototype(obj);
|
package/src/symbols.js
CHANGED
package/test/browser/assert.js
CHANGED
|
@@ -44,11 +44,11 @@ assert.deepEqual = (actual, expected) => {
|
|
|
44
44
|
throw new Error(`Expected ${expected} but got ${actual}`);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
assert.rejects = async (
|
|
47
|
+
assert.rejects = async (fn) => {
|
|
48
48
|
try {
|
|
49
|
-
await
|
|
50
|
-
throw new Error("Expected promise to reject but it resolved");
|
|
49
|
+
await fn();
|
|
51
50
|
} catch (error) {
|
|
52
51
|
return;
|
|
53
52
|
}
|
|
53
|
+
throw new Error("Expected promise to reject but it resolved");
|
|
54
54
|
};
|
package/test/browser/index.html
CHANGED
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
</script>
|
|
14
14
|
<!-- Omit FileTree.test.js, which is Node.js only -->
|
|
15
15
|
<!-- Omit SiteTree.test.js, which requires mocks -->
|
|
16
|
-
<script type="module" src="../BrowserFileTree.test.js"></script>
|
|
17
|
-
<script type="module" src="../DeferredTree.test.js"></script>
|
|
18
|
-
<script type="module" src="../FunctionTree.test.js"></script>
|
|
19
|
-
<script type="module" src="../MapTree.test.js"></script>
|
|
20
|
-
<script type="module" src="../ObjectTree.test.js"></script>
|
|
21
|
-
<script type="module" src="../SetTree.test.js"></script>
|
|
22
16
|
<script type="module" src="../Tree.test.js"></script>
|
|
17
|
+
<script type="module" src="../drivers/BrowserFileTree.test.js"></script>
|
|
18
|
+
<script type="module" src="../drivers/DeferredTree.test.js"></script>
|
|
19
|
+
<script type="module" src="../drivers/FunctionTree.test.js"></script>
|
|
20
|
+
<script type="module" src="../drivers/MapTree.test.js"></script>
|
|
21
|
+
<script type="module" src="../drivers/ObjectTree.test.js"></script>
|
|
22
|
+
<script type="module" src="../drivers/SetTree.test.js"></script>
|
|
23
23
|
<script type="module" src="../operations/cache.test.js"></script>
|
|
24
24
|
<script type="module" src="../operations/merge.test.js"></script>
|
|
25
25
|
<script type="module" src="../operations/deepMerge.test.js"></script>
|
|
26
|
-
<script type="module" src="../
|
|
26
|
+
<script type="module" src="../operations/cachedKeyFunctions.test.js"></script>
|
|
27
27
|
<script
|
|
28
28
|
type="module"
|
|
29
|
-
src="../
|
|
29
|
+
src="../operations/keyFunctionsForExtensions.test.js"
|
|
30
30
|
></script>
|
|
31
|
-
<script type="module" src="../
|
|
31
|
+
<script type="module" src="../operations/map.test.js"></script>
|
|
32
32
|
<script type="module" src="../utilities.test.js"></script>
|
|
33
33
|
</head>
|
|
34
34
|
<body></body>
|
|
@@ -145,7 +145,12 @@ async function createFixture() {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
async function strings(tree) {
|
|
148
|
-
return Tree.plain(
|
|
148
|
+
return Tree.plain(
|
|
149
|
+
Tree.map(tree, {
|
|
150
|
+
deep: true,
|
|
151
|
+
value: (value) => text(value),
|
|
152
|
+
})
|
|
153
|
+
);
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
function text(arrayBuffer) {
|
|
@@ -145,6 +145,13 @@ describe("ObjectTree", () => {
|
|
|
145
145
|
const method = await tree.get("toString");
|
|
146
146
|
assert.equal(method(), "123");
|
|
147
147
|
});
|
|
148
|
+
|
|
149
|
+
test("defers to symbols.keys for keys if defined", async () => {
|
|
150
|
+
const tree = new ObjectTree({
|
|
151
|
+
[symbols.keys]: () => ["a", "b", "c"],
|
|
152
|
+
});
|
|
153
|
+
assert.deepEqual(Array.from(await tree.keys()), ["a", "b", "c"]);
|
|
154
|
+
});
|
|
148
155
|
});
|
|
149
156
|
|
|
150
157
|
function createFixture() {
|