webpipe-js 0.1.2 → 0.1.4
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/dist/index.cjs +27 -47
- package/dist/index.mjs +27 -36
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -39,7 +29,6 @@ __export(index_exports, {
|
|
|
39
29
|
module.exports = __toCommonJS(index_exports);
|
|
40
30
|
|
|
41
31
|
// src/parser.ts
|
|
42
|
-
var import_meta = {};
|
|
43
32
|
var Parser = class {
|
|
44
33
|
constructor(text) {
|
|
45
34
|
this.pos = 0;
|
|
@@ -590,26 +579,6 @@ var ParseFailure = class extends Error {
|
|
|
590
579
|
};
|
|
591
580
|
function prettyPrint(program) {
|
|
592
581
|
const lines = [];
|
|
593
|
-
program.configs.forEach((config) => {
|
|
594
|
-
lines.push(`config ${config.name} {`);
|
|
595
|
-
config.properties.forEach((prop) => {
|
|
596
|
-
const value = formatConfigValue(prop.value);
|
|
597
|
-
lines.push(` ${prop.key}: ${value}`);
|
|
598
|
-
});
|
|
599
|
-
lines.push("}");
|
|
600
|
-
lines.push("");
|
|
601
|
-
});
|
|
602
|
-
program.variables.forEach((variable) => {
|
|
603
|
-
lines.push(`${variable.varType} ${variable.name} = \`${variable.value}\``);
|
|
604
|
-
});
|
|
605
|
-
if (program.variables.length > 0) lines.push("");
|
|
606
|
-
program.pipelines.forEach((pipeline) => {
|
|
607
|
-
lines.push(`pipeline ${pipeline.name} =`);
|
|
608
|
-
pipeline.pipeline.steps.forEach((step) => {
|
|
609
|
-
lines.push(formatPipelineStep(step));
|
|
610
|
-
});
|
|
611
|
-
lines.push("");
|
|
612
|
-
});
|
|
613
582
|
program.routes.forEach((route) => {
|
|
614
583
|
lines.push(`${route.method} ${route.path}`);
|
|
615
584
|
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
@@ -634,11 +603,35 @@ function prettyPrint(program) {
|
|
|
634
603
|
test.conditions.forEach((condition) => {
|
|
635
604
|
const condType = condition.conditionType.toLowerCase();
|
|
636
605
|
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
637
|
-
|
|
606
|
+
const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
|
|
607
|
+
lines.push(` ${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`);
|
|
638
608
|
});
|
|
639
609
|
lines.push("");
|
|
640
610
|
});
|
|
641
611
|
});
|
|
612
|
+
if (program.configs.length > 0) {
|
|
613
|
+
lines.push("## Config");
|
|
614
|
+
program.configs.forEach((config) => {
|
|
615
|
+
lines.push(`config ${config.name} {`);
|
|
616
|
+
config.properties.forEach((prop) => {
|
|
617
|
+
const value = formatConfigValue(prop.value);
|
|
618
|
+
lines.push(` ${prop.key}: ${value}`);
|
|
619
|
+
});
|
|
620
|
+
lines.push("}");
|
|
621
|
+
lines.push("");
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
program.pipelines.forEach((pipeline) => {
|
|
625
|
+
lines.push(`pipeline ${pipeline.name} =`);
|
|
626
|
+
pipeline.pipeline.steps.forEach((step) => {
|
|
627
|
+
lines.push(formatPipelineStep(step));
|
|
628
|
+
});
|
|
629
|
+
lines.push("");
|
|
630
|
+
});
|
|
631
|
+
program.variables.forEach((variable) => {
|
|
632
|
+
lines.push(`${variable.varType} ${variable.name} = \`${variable.value}\``);
|
|
633
|
+
});
|
|
634
|
+
if (program.variables.length > 0) lines.push("");
|
|
642
635
|
return lines.join("\n").trim();
|
|
643
636
|
}
|
|
644
637
|
function formatConfigValue(value) {
|
|
@@ -669,9 +662,9 @@ function formatPipelineStep(step, indent = " ") {
|
|
|
669
662
|
}
|
|
670
663
|
}
|
|
671
664
|
function formatStepConfig(config) {
|
|
672
|
-
if (config.includes("
|
|
665
|
+
if (config.includes("\n") || config.includes("{") || config.includes("[") || config.includes(".") || config.includes("(")) {
|
|
673
666
|
return `\`${config}\``;
|
|
674
|
-
} else if (config.includes(" ")
|
|
667
|
+
} else if (config.includes(" ")) {
|
|
675
668
|
return `"${config}"`;
|
|
676
669
|
} else {
|
|
677
670
|
return config;
|
|
@@ -698,19 +691,6 @@ function formatWhen(when) {
|
|
|
698
691
|
return `executing variable ${when.varType} ${when.name}`;
|
|
699
692
|
}
|
|
700
693
|
}
|
|
701
|
-
if (import_meta.url === `file://${process.argv[1]}`) {
|
|
702
|
-
(async () => {
|
|
703
|
-
const fs = await import("fs/promises");
|
|
704
|
-
const path = process.argv[2];
|
|
705
|
-
if (!path) {
|
|
706
|
-
console.error("Usage: node dist/index.mjs <file.wp>");
|
|
707
|
-
process.exit(1);
|
|
708
|
-
}
|
|
709
|
-
const src = await fs.readFile(path, "utf8");
|
|
710
|
-
const program = parseProgram(src);
|
|
711
|
-
console.log(JSON.stringify(program, null, 2));
|
|
712
|
-
})();
|
|
713
|
-
}
|
|
714
694
|
// Annotate the CommonJS export names for ESM import in node:
|
|
715
695
|
0 && (module.exports = {
|
|
716
696
|
getPipelineRanges,
|
package/dist/index.mjs
CHANGED
|
@@ -549,26 +549,6 @@ var ParseFailure = class extends Error {
|
|
|
549
549
|
};
|
|
550
550
|
function prettyPrint(program) {
|
|
551
551
|
const lines = [];
|
|
552
|
-
program.configs.forEach((config) => {
|
|
553
|
-
lines.push(`config ${config.name} {`);
|
|
554
|
-
config.properties.forEach((prop) => {
|
|
555
|
-
const value = formatConfigValue(prop.value);
|
|
556
|
-
lines.push(` ${prop.key}: ${value}`);
|
|
557
|
-
});
|
|
558
|
-
lines.push("}");
|
|
559
|
-
lines.push("");
|
|
560
|
-
});
|
|
561
|
-
program.variables.forEach((variable) => {
|
|
562
|
-
lines.push(`${variable.varType} ${variable.name} = \`${variable.value}\``);
|
|
563
|
-
});
|
|
564
|
-
if (program.variables.length > 0) lines.push("");
|
|
565
|
-
program.pipelines.forEach((pipeline) => {
|
|
566
|
-
lines.push(`pipeline ${pipeline.name} =`);
|
|
567
|
-
pipeline.pipeline.steps.forEach((step) => {
|
|
568
|
-
lines.push(formatPipelineStep(step));
|
|
569
|
-
});
|
|
570
|
-
lines.push("");
|
|
571
|
-
});
|
|
572
552
|
program.routes.forEach((route) => {
|
|
573
553
|
lines.push(`${route.method} ${route.path}`);
|
|
574
554
|
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
@@ -593,11 +573,35 @@ function prettyPrint(program) {
|
|
|
593
573
|
test.conditions.forEach((condition) => {
|
|
594
574
|
const condType = condition.conditionType.toLowerCase();
|
|
595
575
|
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
596
|
-
|
|
576
|
+
const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
|
|
577
|
+
lines.push(` ${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`);
|
|
597
578
|
});
|
|
598
579
|
lines.push("");
|
|
599
580
|
});
|
|
600
581
|
});
|
|
582
|
+
if (program.configs.length > 0) {
|
|
583
|
+
lines.push("## Config");
|
|
584
|
+
program.configs.forEach((config) => {
|
|
585
|
+
lines.push(`config ${config.name} {`);
|
|
586
|
+
config.properties.forEach((prop) => {
|
|
587
|
+
const value = formatConfigValue(prop.value);
|
|
588
|
+
lines.push(` ${prop.key}: ${value}`);
|
|
589
|
+
});
|
|
590
|
+
lines.push("}");
|
|
591
|
+
lines.push("");
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
program.pipelines.forEach((pipeline) => {
|
|
595
|
+
lines.push(`pipeline ${pipeline.name} =`);
|
|
596
|
+
pipeline.pipeline.steps.forEach((step) => {
|
|
597
|
+
lines.push(formatPipelineStep(step));
|
|
598
|
+
});
|
|
599
|
+
lines.push("");
|
|
600
|
+
});
|
|
601
|
+
program.variables.forEach((variable) => {
|
|
602
|
+
lines.push(`${variable.varType} ${variable.name} = \`${variable.value}\``);
|
|
603
|
+
});
|
|
604
|
+
if (program.variables.length > 0) lines.push("");
|
|
601
605
|
return lines.join("\n").trim();
|
|
602
606
|
}
|
|
603
607
|
function formatConfigValue(value) {
|
|
@@ -628,9 +632,9 @@ function formatPipelineStep(step, indent = " ") {
|
|
|
628
632
|
}
|
|
629
633
|
}
|
|
630
634
|
function formatStepConfig(config) {
|
|
631
|
-
if (config.includes("
|
|
635
|
+
if (config.includes("\n") || config.includes("{") || config.includes("[") || config.includes(".") || config.includes("(")) {
|
|
632
636
|
return `\`${config}\``;
|
|
633
|
-
} else if (config.includes(" ")
|
|
637
|
+
} else if (config.includes(" ")) {
|
|
634
638
|
return `"${config}"`;
|
|
635
639
|
} else {
|
|
636
640
|
return config;
|
|
@@ -657,19 +661,6 @@ function formatWhen(when) {
|
|
|
657
661
|
return `executing variable ${when.varType} ${when.name}`;
|
|
658
662
|
}
|
|
659
663
|
}
|
|
660
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
661
|
-
(async () => {
|
|
662
|
-
const fs = await import("fs/promises");
|
|
663
|
-
const path = process.argv[2];
|
|
664
|
-
if (!path) {
|
|
665
|
-
console.error("Usage: node dist/index.mjs <file.wp>");
|
|
666
|
-
process.exit(1);
|
|
667
|
-
}
|
|
668
|
-
const src = await fs.readFile(path, "utf8");
|
|
669
|
-
const program = parseProgram(src);
|
|
670
|
-
console.log(JSON.stringify(program, null, 2));
|
|
671
|
-
})();
|
|
672
|
-
}
|
|
673
664
|
export {
|
|
674
665
|
getPipelineRanges,
|
|
675
666
|
getVariableRanges,
|