@fynjs/run 1.0.0

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/lib/xqitem.js ADDED
@@ -0,0 +1,70 @@
1
+ import genXqId from "./gen-xqid.js";
2
+ import assert from "assert";
3
+
4
+ class XQItem {
5
+ constructor(options) {
6
+ this.id = genXqId();
7
+ this.argv = [];
8
+ this.resolved = [];
9
+ this.children = [];
10
+ this.level = options.level || 0;
11
+ this.ns = options.ns || "";
12
+ let value = options.value;
13
+
14
+ if (typeof options.name === "string") {
15
+ this.argv = options.name
16
+ .trim()
17
+ .split(" ")
18
+ .filter(x => x);
19
+ this.name = this.argv[0];
20
+ if (this.name !== options.name && !value) {
21
+ value = options.name;
22
+ }
23
+ }
24
+
25
+ assert(this.name, "xqitem must have a name");
26
+
27
+ if (value) {
28
+ this.setResolve(value);
29
+ }
30
+
31
+ this.type = options.type;
32
+ if (options.parent) {
33
+ this.parentId = options.parent.id;
34
+ this.isFinally = options.parent.isFinally;
35
+ }
36
+ this.anon = options.anon;
37
+ }
38
+
39
+ lookup(tasks) {
40
+ const found = tasks.lookup(this.name);
41
+ this.setResolve({ top: true, item: found.item });
42
+ return found;
43
+ }
44
+
45
+ value() {
46
+ return this.resolved.length === 0 ? this.name : this.resolved[this.resolved.length - 1];
47
+ }
48
+
49
+ setResolve(value) {
50
+ this.resolved.push(value);
51
+ }
52
+
53
+ setNamespace(ns) {
54
+ this.ns = ns;
55
+ }
56
+
57
+ addChild(x) {
58
+ this.children.push(x);
59
+ }
60
+
61
+ get isFinally() {
62
+ return this._isFinally;
63
+ }
64
+
65
+ set isFinally(f) {
66
+ this._isFinally = f;
67
+ }
68
+ }
69
+
70
+ export default XQItem;