webpipe-js 0.1.1 → 0.1.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/dist/index.cjs +113 -25
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +111 -13
- 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
|
|
@@ -33,12 +23,12 @@ __export(index_exports, {
|
|
|
33
23
|
getPipelineRanges: () => getPipelineRanges,
|
|
34
24
|
getVariableRanges: () => getVariableRanges,
|
|
35
25
|
parseProgram: () => parseProgram,
|
|
36
|
-
parseProgramWithDiagnostics: () => parseProgramWithDiagnostics
|
|
26
|
+
parseProgramWithDiagnostics: () => parseProgramWithDiagnostics,
|
|
27
|
+
prettyPrint: () => prettyPrint
|
|
37
28
|
});
|
|
38
29
|
module.exports = __toCommonJS(index_exports);
|
|
39
30
|
|
|
40
31
|
// src/parser.ts
|
|
41
|
-
var import_meta = {};
|
|
42
32
|
var Parser = class {
|
|
43
33
|
constructor(text) {
|
|
44
34
|
this.pos = 0;
|
|
@@ -587,23 +577,121 @@ var ParseFailure = class extends Error {
|
|
|
587
577
|
this.at = at;
|
|
588
578
|
}
|
|
589
579
|
};
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
580
|
+
function prettyPrint(program) {
|
|
581
|
+
const lines = [];
|
|
582
|
+
program.configs.forEach((config) => {
|
|
583
|
+
lines.push(`config ${config.name} {`);
|
|
584
|
+
config.properties.forEach((prop) => {
|
|
585
|
+
const value = formatConfigValue(prop.value);
|
|
586
|
+
lines.push(` ${prop.key}: ${value}`);
|
|
587
|
+
});
|
|
588
|
+
lines.push("}");
|
|
589
|
+
lines.push("");
|
|
590
|
+
});
|
|
591
|
+
program.variables.forEach((variable) => {
|
|
592
|
+
lines.push(`${variable.varType} ${variable.name} = \`${variable.value}\``);
|
|
593
|
+
});
|
|
594
|
+
if (program.variables.length > 0) lines.push("");
|
|
595
|
+
program.pipelines.forEach((pipeline) => {
|
|
596
|
+
lines.push(`pipeline ${pipeline.name} =`);
|
|
597
|
+
pipeline.pipeline.steps.forEach((step) => {
|
|
598
|
+
lines.push(formatPipelineStep(step));
|
|
599
|
+
});
|
|
600
|
+
lines.push("");
|
|
601
|
+
});
|
|
602
|
+
program.routes.forEach((route) => {
|
|
603
|
+
lines.push(`${route.method} ${route.path}`);
|
|
604
|
+
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
605
|
+
pipelineLines.forEach((line) => lines.push(line));
|
|
606
|
+
lines.push("");
|
|
607
|
+
});
|
|
608
|
+
program.describes.forEach((describe) => {
|
|
609
|
+
lines.push(`describe "${describe.name}"`);
|
|
610
|
+
describe.mocks.forEach((mock) => {
|
|
611
|
+
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
612
|
+
});
|
|
613
|
+
lines.push("");
|
|
614
|
+
describe.tests.forEach((test) => {
|
|
615
|
+
lines.push(` it "${test.name}"`);
|
|
616
|
+
test.mocks.forEach((mock) => {
|
|
617
|
+
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
618
|
+
});
|
|
619
|
+
lines.push(` when ${formatWhen(test.when)}`);
|
|
620
|
+
if (test.input) {
|
|
621
|
+
lines.push(` with input \`${test.input}\``);
|
|
622
|
+
}
|
|
623
|
+
test.conditions.forEach((condition) => {
|
|
624
|
+
const condType = condition.conditionType.toLowerCase();
|
|
625
|
+
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
626
|
+
lines.push(` ${condType} ${condition.field}${jqPart} ${condition.comparison} ${condition.value}`);
|
|
627
|
+
});
|
|
628
|
+
lines.push("");
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
return lines.join("\n").trim();
|
|
632
|
+
}
|
|
633
|
+
function formatConfigValue(value) {
|
|
634
|
+
switch (value.kind) {
|
|
635
|
+
case "String":
|
|
636
|
+
return `"${value.value}"`;
|
|
637
|
+
case "EnvVar":
|
|
638
|
+
return value.default ? `$${value.var} || "${value.default}"` : `$${value.var}`;
|
|
639
|
+
case "Boolean":
|
|
640
|
+
return value.value.toString();
|
|
641
|
+
case "Number":
|
|
642
|
+
return value.value.toString();
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function formatPipelineStep(step, indent = " ") {
|
|
646
|
+
if (step.kind === "Regular") {
|
|
647
|
+
return `${indent}|> ${step.name}: ${formatStepConfig(step.config)}`;
|
|
648
|
+
} else {
|
|
649
|
+
const lines = [`${indent}|> result`];
|
|
650
|
+
step.branches.forEach((branch) => {
|
|
651
|
+
const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
|
|
652
|
+
lines.push(`${indent} ${branchName}(${branch.statusCode}):`);
|
|
653
|
+
branch.pipeline.steps.forEach((branchStep) => {
|
|
654
|
+
lines.push(formatPipelineStep(branchStep, indent + " "));
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
return lines.join("\n");
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
function formatStepConfig(config) {
|
|
661
|
+
if (config.includes("`")) {
|
|
662
|
+
return `\`${config}\``;
|
|
663
|
+
} else if (config.includes(" ") || config.includes("\n")) {
|
|
664
|
+
return `"${config}"`;
|
|
665
|
+
} else {
|
|
666
|
+
return config;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
function formatPipelineRef(ref) {
|
|
670
|
+
if (ref.kind === "Named") {
|
|
671
|
+
return [` |> pipeline: ${ref.name}`];
|
|
672
|
+
} else {
|
|
673
|
+
const lines = [];
|
|
674
|
+
ref.pipeline.steps.forEach((step) => {
|
|
675
|
+
lines.push(formatPipelineStep(step));
|
|
676
|
+
});
|
|
677
|
+
return lines;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
function formatWhen(when) {
|
|
681
|
+
switch (when.kind) {
|
|
682
|
+
case "CallingRoute":
|
|
683
|
+
return `calling ${when.method} ${when.path}`;
|
|
684
|
+
case "ExecutingPipeline":
|
|
685
|
+
return `executing pipeline ${when.name}`;
|
|
686
|
+
case "ExecutingVariable":
|
|
687
|
+
return `executing variable ${when.varType} ${when.name}`;
|
|
688
|
+
}
|
|
602
689
|
}
|
|
603
690
|
// Annotate the CommonJS export names for ESM import in node:
|
|
604
691
|
0 && (module.exports = {
|
|
605
692
|
getPipelineRanges,
|
|
606
693
|
getVariableRanges,
|
|
607
694
|
parseProgram,
|
|
608
|
-
parseProgramWithDiagnostics
|
|
695
|
+
parseProgramWithDiagnostics,
|
|
696
|
+
prettyPrint
|
|
609
697
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -127,5 +127,6 @@ declare function getVariableRanges(text: string): Map<string, {
|
|
|
127
127
|
start: number;
|
|
128
128
|
end: number;
|
|
129
129
|
}>;
|
|
130
|
+
declare function prettyPrint(program: Program): string;
|
|
130
131
|
|
|
131
|
-
export { type Condition, type Config, type ConfigProperty, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics };
|
|
132
|
+
export { type Condition, type Config, type ConfigProperty, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint };
|
package/dist/index.d.ts
CHANGED
|
@@ -127,5 +127,6 @@ declare function getVariableRanges(text: string): Map<string, {
|
|
|
127
127
|
start: number;
|
|
128
128
|
end: number;
|
|
129
129
|
}>;
|
|
130
|
+
declare function prettyPrint(program: Program): string;
|
|
130
131
|
|
|
131
|
-
export { type Condition, type Config, type ConfigProperty, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics };
|
|
132
|
+
export { type Condition, type Config, type ConfigProperty, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint };
|
package/dist/index.mjs
CHANGED
|
@@ -547,22 +547,120 @@ var ParseFailure = class extends Error {
|
|
|
547
547
|
this.at = at;
|
|
548
548
|
}
|
|
549
549
|
};
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
550
|
+
function prettyPrint(program) {
|
|
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
|
+
program.routes.forEach((route) => {
|
|
573
|
+
lines.push(`${route.method} ${route.path}`);
|
|
574
|
+
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
575
|
+
pipelineLines.forEach((line) => lines.push(line));
|
|
576
|
+
lines.push("");
|
|
577
|
+
});
|
|
578
|
+
program.describes.forEach((describe) => {
|
|
579
|
+
lines.push(`describe "${describe.name}"`);
|
|
580
|
+
describe.mocks.forEach((mock) => {
|
|
581
|
+
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
582
|
+
});
|
|
583
|
+
lines.push("");
|
|
584
|
+
describe.tests.forEach((test) => {
|
|
585
|
+
lines.push(` it "${test.name}"`);
|
|
586
|
+
test.mocks.forEach((mock) => {
|
|
587
|
+
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
588
|
+
});
|
|
589
|
+
lines.push(` when ${formatWhen(test.when)}`);
|
|
590
|
+
if (test.input) {
|
|
591
|
+
lines.push(` with input \`${test.input}\``);
|
|
592
|
+
}
|
|
593
|
+
test.conditions.forEach((condition) => {
|
|
594
|
+
const condType = condition.conditionType.toLowerCase();
|
|
595
|
+
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
596
|
+
lines.push(` ${condType} ${condition.field}${jqPart} ${condition.comparison} ${condition.value}`);
|
|
597
|
+
});
|
|
598
|
+
lines.push("");
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
return lines.join("\n").trim();
|
|
602
|
+
}
|
|
603
|
+
function formatConfigValue(value) {
|
|
604
|
+
switch (value.kind) {
|
|
605
|
+
case "String":
|
|
606
|
+
return `"${value.value}"`;
|
|
607
|
+
case "EnvVar":
|
|
608
|
+
return value.default ? `$${value.var} || "${value.default}"` : `$${value.var}`;
|
|
609
|
+
case "Boolean":
|
|
610
|
+
return value.value.toString();
|
|
611
|
+
case "Number":
|
|
612
|
+
return value.value.toString();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function formatPipelineStep(step, indent = " ") {
|
|
616
|
+
if (step.kind === "Regular") {
|
|
617
|
+
return `${indent}|> ${step.name}: ${formatStepConfig(step.config)}`;
|
|
618
|
+
} else {
|
|
619
|
+
const lines = [`${indent}|> result`];
|
|
620
|
+
step.branches.forEach((branch) => {
|
|
621
|
+
const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
|
|
622
|
+
lines.push(`${indent} ${branchName}(${branch.statusCode}):`);
|
|
623
|
+
branch.pipeline.steps.forEach((branchStep) => {
|
|
624
|
+
lines.push(formatPipelineStep(branchStep, indent + " "));
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
return lines.join("\n");
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function formatStepConfig(config) {
|
|
631
|
+
if (config.includes("`")) {
|
|
632
|
+
return `\`${config}\``;
|
|
633
|
+
} else if (config.includes(" ") || config.includes("\n")) {
|
|
634
|
+
return `"${config}"`;
|
|
635
|
+
} else {
|
|
636
|
+
return config;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function formatPipelineRef(ref) {
|
|
640
|
+
if (ref.kind === "Named") {
|
|
641
|
+
return [` |> pipeline: ${ref.name}`];
|
|
642
|
+
} else {
|
|
643
|
+
const lines = [];
|
|
644
|
+
ref.pipeline.steps.forEach((step) => {
|
|
645
|
+
lines.push(formatPipelineStep(step));
|
|
646
|
+
});
|
|
647
|
+
return lines;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
function formatWhen(when) {
|
|
651
|
+
switch (when.kind) {
|
|
652
|
+
case "CallingRoute":
|
|
653
|
+
return `calling ${when.method} ${when.path}`;
|
|
654
|
+
case "ExecutingPipeline":
|
|
655
|
+
return `executing pipeline ${when.name}`;
|
|
656
|
+
case "ExecutingVariable":
|
|
657
|
+
return `executing variable ${when.varType} ${when.name}`;
|
|
658
|
+
}
|
|
562
659
|
}
|
|
563
660
|
export {
|
|
564
661
|
getPipelineRanges,
|
|
565
662
|
getVariableRanges,
|
|
566
663
|
parseProgram,
|
|
567
|
-
parseProgramWithDiagnostics
|
|
664
|
+
parseProgramWithDiagnostics,
|
|
665
|
+
prettyPrint
|
|
568
666
|
};
|