webpipe-js 0.1.3 → 0.1.5
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 +109 -42
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +95 -41
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,11 +20,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
formatConfigValue: () => formatConfigValue,
|
|
24
|
+
formatPipelineRef: () => formatPipelineRef,
|
|
25
|
+
formatPipelineStep: () => formatPipelineStep,
|
|
26
|
+
formatStepConfig: () => formatStepConfig,
|
|
27
|
+
formatWhen: () => formatWhen,
|
|
23
28
|
getPipelineRanges: () => getPipelineRanges,
|
|
24
29
|
getVariableRanges: () => getVariableRanges,
|
|
25
30
|
parseProgram: () => parseProgram,
|
|
26
31
|
parseProgramWithDiagnostics: () => parseProgramWithDiagnostics,
|
|
27
|
-
prettyPrint: () => prettyPrint
|
|
32
|
+
prettyPrint: () => prettyPrint,
|
|
33
|
+
printCondition: () => printCondition,
|
|
34
|
+
printConfig: () => printConfig,
|
|
35
|
+
printDescribe: () => printDescribe,
|
|
36
|
+
printMock: () => printMock,
|
|
37
|
+
printPipeline: () => printPipeline,
|
|
38
|
+
printRoute: () => printRoute,
|
|
39
|
+
printTest: () => printTest,
|
|
40
|
+
printVariable: () => printVariable
|
|
28
41
|
});
|
|
29
42
|
module.exports = __toCommonJS(index_exports);
|
|
30
43
|
|
|
@@ -577,57 +590,98 @@ var ParseFailure = class extends Error {
|
|
|
577
590
|
this.at = at;
|
|
578
591
|
}
|
|
579
592
|
};
|
|
580
|
-
function
|
|
593
|
+
function printRoute(route) {
|
|
581
594
|
const lines = [];
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
595
|
+
lines.push(`${route.method} ${route.path}`);
|
|
596
|
+
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
597
|
+
pipelineLines.forEach((line) => lines.push(line));
|
|
598
|
+
return lines.join("\n");
|
|
599
|
+
}
|
|
600
|
+
function printConfig(config) {
|
|
601
|
+
const lines = [];
|
|
602
|
+
lines.push(`config ${config.name} {`);
|
|
603
|
+
config.properties.forEach((prop) => {
|
|
604
|
+
const value = formatConfigValue(prop.value);
|
|
605
|
+
lines.push(` ${prop.key}: ${value}`);
|
|
590
606
|
});
|
|
591
|
-
|
|
592
|
-
|
|
607
|
+
lines.push("}");
|
|
608
|
+
return lines.join("\n");
|
|
609
|
+
}
|
|
610
|
+
function printPipeline(pipeline) {
|
|
611
|
+
const lines = [];
|
|
612
|
+
lines.push(`pipeline ${pipeline.name} =`);
|
|
613
|
+
pipeline.pipeline.steps.forEach((step) => {
|
|
614
|
+
lines.push(formatPipelineStep(step));
|
|
593
615
|
});
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
616
|
+
return lines.join("\n");
|
|
617
|
+
}
|
|
618
|
+
function printVariable(variable) {
|
|
619
|
+
return `${variable.varType} ${variable.name} = \`${variable.value}\``;
|
|
620
|
+
}
|
|
621
|
+
function printMock(mock, indent = " ") {
|
|
622
|
+
return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
|
|
623
|
+
}
|
|
624
|
+
function printCondition(condition, indent = " ") {
|
|
625
|
+
const condType = condition.conditionType.toLowerCase();
|
|
626
|
+
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
627
|
+
const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
|
|
628
|
+
return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
|
|
629
|
+
}
|
|
630
|
+
function printTest(test) {
|
|
631
|
+
const lines = [];
|
|
632
|
+
lines.push(` it "${test.name}"`);
|
|
633
|
+
test.mocks.forEach((mock) => {
|
|
634
|
+
lines.push(printMock(mock, " "));
|
|
635
|
+
});
|
|
636
|
+
lines.push(` when ${formatWhen(test.when)}`);
|
|
637
|
+
if (test.input) {
|
|
638
|
+
lines.push(` with input \`${test.input}\``);
|
|
639
|
+
}
|
|
640
|
+
test.conditions.forEach((condition) => {
|
|
641
|
+
lines.push(printCondition(condition));
|
|
642
|
+
});
|
|
643
|
+
return lines.join("\n");
|
|
644
|
+
}
|
|
645
|
+
function printDescribe(describe) {
|
|
646
|
+
const lines = [];
|
|
647
|
+
lines.push(`describe "${describe.name}"`);
|
|
648
|
+
describe.mocks.forEach((mock) => {
|
|
649
|
+
lines.push(printMock(mock));
|
|
650
|
+
});
|
|
651
|
+
if (describe.mocks.length > 0) {
|
|
652
|
+
lines.push("");
|
|
653
|
+
}
|
|
654
|
+
describe.tests.forEach((test) => {
|
|
655
|
+
lines.push(printTest(test));
|
|
600
656
|
lines.push("");
|
|
601
657
|
});
|
|
658
|
+
return lines.join("\n").replace(/\n\n$/, "\n");
|
|
659
|
+
}
|
|
660
|
+
function prettyPrint(program) {
|
|
661
|
+
const lines = [];
|
|
602
662
|
program.routes.forEach((route) => {
|
|
603
|
-
lines.push(
|
|
604
|
-
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
605
|
-
pipelineLines.forEach((line) => lines.push(line));
|
|
663
|
+
lines.push(printRoute(route));
|
|
606
664
|
lines.push("");
|
|
607
665
|
});
|
|
608
666
|
program.describes.forEach((describe) => {
|
|
609
|
-
lines.push(
|
|
610
|
-
describe.mocks.forEach((mock) => {
|
|
611
|
-
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
612
|
-
});
|
|
667
|
+
lines.push(printDescribe(describe));
|
|
613
668
|
lines.push("");
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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
|
-
});
|
|
669
|
+
});
|
|
670
|
+
if (program.configs.length > 0) {
|
|
671
|
+
lines.push("## Config");
|
|
672
|
+
program.configs.forEach((config) => {
|
|
673
|
+
lines.push(printConfig(config));
|
|
628
674
|
lines.push("");
|
|
629
675
|
});
|
|
676
|
+
}
|
|
677
|
+
program.pipelines.forEach((pipeline) => {
|
|
678
|
+
lines.push(printPipeline(pipeline));
|
|
679
|
+
lines.push("");
|
|
680
|
+
});
|
|
681
|
+
program.variables.forEach((variable) => {
|
|
682
|
+
lines.push(printVariable(variable));
|
|
630
683
|
});
|
|
684
|
+
if (program.variables.length > 0) lines.push("");
|
|
631
685
|
return lines.join("\n").trim();
|
|
632
686
|
}
|
|
633
687
|
function formatConfigValue(value) {
|
|
@@ -658,9 +712,9 @@ function formatPipelineStep(step, indent = " ") {
|
|
|
658
712
|
}
|
|
659
713
|
}
|
|
660
714
|
function formatStepConfig(config) {
|
|
661
|
-
if (config.includes("
|
|
715
|
+
if (config.includes("\n") || config.includes("{") || config.includes("[") || config.includes(".") || config.includes("(")) {
|
|
662
716
|
return `\`${config}\``;
|
|
663
|
-
} else if (config.includes(" ")
|
|
717
|
+
} else if (config.includes(" ")) {
|
|
664
718
|
return `"${config}"`;
|
|
665
719
|
} else {
|
|
666
720
|
return config;
|
|
@@ -689,9 +743,22 @@ function formatWhen(when) {
|
|
|
689
743
|
}
|
|
690
744
|
// Annotate the CommonJS export names for ESM import in node:
|
|
691
745
|
0 && (module.exports = {
|
|
746
|
+
formatConfigValue,
|
|
747
|
+
formatPipelineRef,
|
|
748
|
+
formatPipelineStep,
|
|
749
|
+
formatStepConfig,
|
|
750
|
+
formatWhen,
|
|
692
751
|
getPipelineRanges,
|
|
693
752
|
getVariableRanges,
|
|
694
753
|
parseProgram,
|
|
695
754
|
parseProgramWithDiagnostics,
|
|
696
|
-
prettyPrint
|
|
755
|
+
prettyPrint,
|
|
756
|
+
printCondition,
|
|
757
|
+
printConfig,
|
|
758
|
+
printDescribe,
|
|
759
|
+
printMock,
|
|
760
|
+
printPipeline,
|
|
761
|
+
printRoute,
|
|
762
|
+
printTest,
|
|
763
|
+
printVariable
|
|
697
764
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -127,6 +127,19 @@ declare function getVariableRanges(text: string): Map<string, {
|
|
|
127
127
|
start: number;
|
|
128
128
|
end: number;
|
|
129
129
|
}>;
|
|
130
|
+
declare function printRoute(route: Route): string;
|
|
131
|
+
declare function printConfig(config: Config): string;
|
|
132
|
+
declare function printPipeline(pipeline: NamedPipeline): string;
|
|
133
|
+
declare function printVariable(variable: Variable): string;
|
|
134
|
+
declare function printMock(mock: Mock, indent?: string): string;
|
|
135
|
+
declare function printCondition(condition: Condition, indent?: string): string;
|
|
136
|
+
declare function printTest(test: It): string;
|
|
137
|
+
declare function printDescribe(describe: Describe): string;
|
|
130
138
|
declare function prettyPrint(program: Program): string;
|
|
139
|
+
declare function formatConfigValue(value: ConfigValue): string;
|
|
140
|
+
declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
|
|
141
|
+
declare function formatStepConfig(config: string): string;
|
|
142
|
+
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
143
|
+
declare function formatWhen(when: When): string;
|
|
131
144
|
|
|
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 };
|
|
145
|
+
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, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
|
package/dist/index.d.ts
CHANGED
|
@@ -127,6 +127,19 @@ declare function getVariableRanges(text: string): Map<string, {
|
|
|
127
127
|
start: number;
|
|
128
128
|
end: number;
|
|
129
129
|
}>;
|
|
130
|
+
declare function printRoute(route: Route): string;
|
|
131
|
+
declare function printConfig(config: Config): string;
|
|
132
|
+
declare function printPipeline(pipeline: NamedPipeline): string;
|
|
133
|
+
declare function printVariable(variable: Variable): string;
|
|
134
|
+
declare function printMock(mock: Mock, indent?: string): string;
|
|
135
|
+
declare function printCondition(condition: Condition, indent?: string): string;
|
|
136
|
+
declare function printTest(test: It): string;
|
|
137
|
+
declare function printDescribe(describe: Describe): string;
|
|
130
138
|
declare function prettyPrint(program: Program): string;
|
|
139
|
+
declare function formatConfigValue(value: ConfigValue): string;
|
|
140
|
+
declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
|
|
141
|
+
declare function formatStepConfig(config: string): string;
|
|
142
|
+
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
143
|
+
declare function formatWhen(when: When): string;
|
|
131
144
|
|
|
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 };
|
|
145
|
+
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, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
|
package/dist/index.mjs
CHANGED
|
@@ -547,57 +547,98 @@ var ParseFailure = class extends Error {
|
|
|
547
547
|
this.at = at;
|
|
548
548
|
}
|
|
549
549
|
};
|
|
550
|
-
function
|
|
550
|
+
function printRoute(route) {
|
|
551
551
|
const lines = [];
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
552
|
+
lines.push(`${route.method} ${route.path}`);
|
|
553
|
+
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
554
|
+
pipelineLines.forEach((line) => lines.push(line));
|
|
555
|
+
return lines.join("\n");
|
|
556
|
+
}
|
|
557
|
+
function printConfig(config) {
|
|
558
|
+
const lines = [];
|
|
559
|
+
lines.push(`config ${config.name} {`);
|
|
560
|
+
config.properties.forEach((prop) => {
|
|
561
|
+
const value = formatConfigValue(prop.value);
|
|
562
|
+
lines.push(` ${prop.key}: ${value}`);
|
|
560
563
|
});
|
|
561
|
-
|
|
562
|
-
|
|
564
|
+
lines.push("}");
|
|
565
|
+
return lines.join("\n");
|
|
566
|
+
}
|
|
567
|
+
function printPipeline(pipeline) {
|
|
568
|
+
const lines = [];
|
|
569
|
+
lines.push(`pipeline ${pipeline.name} =`);
|
|
570
|
+
pipeline.pipeline.steps.forEach((step) => {
|
|
571
|
+
lines.push(formatPipelineStep(step));
|
|
563
572
|
});
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
573
|
+
return lines.join("\n");
|
|
574
|
+
}
|
|
575
|
+
function printVariable(variable) {
|
|
576
|
+
return `${variable.varType} ${variable.name} = \`${variable.value}\``;
|
|
577
|
+
}
|
|
578
|
+
function printMock(mock, indent = " ") {
|
|
579
|
+
return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
|
|
580
|
+
}
|
|
581
|
+
function printCondition(condition, indent = " ") {
|
|
582
|
+
const condType = condition.conditionType.toLowerCase();
|
|
583
|
+
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
584
|
+
const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
|
|
585
|
+
return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
|
|
586
|
+
}
|
|
587
|
+
function printTest(test) {
|
|
588
|
+
const lines = [];
|
|
589
|
+
lines.push(` it "${test.name}"`);
|
|
590
|
+
test.mocks.forEach((mock) => {
|
|
591
|
+
lines.push(printMock(mock, " "));
|
|
592
|
+
});
|
|
593
|
+
lines.push(` when ${formatWhen(test.when)}`);
|
|
594
|
+
if (test.input) {
|
|
595
|
+
lines.push(` with input \`${test.input}\``);
|
|
596
|
+
}
|
|
597
|
+
test.conditions.forEach((condition) => {
|
|
598
|
+
lines.push(printCondition(condition));
|
|
599
|
+
});
|
|
600
|
+
return lines.join("\n");
|
|
601
|
+
}
|
|
602
|
+
function printDescribe(describe) {
|
|
603
|
+
const lines = [];
|
|
604
|
+
lines.push(`describe "${describe.name}"`);
|
|
605
|
+
describe.mocks.forEach((mock) => {
|
|
606
|
+
lines.push(printMock(mock));
|
|
607
|
+
});
|
|
608
|
+
if (describe.mocks.length > 0) {
|
|
609
|
+
lines.push("");
|
|
610
|
+
}
|
|
611
|
+
describe.tests.forEach((test) => {
|
|
612
|
+
lines.push(printTest(test));
|
|
570
613
|
lines.push("");
|
|
571
614
|
});
|
|
615
|
+
return lines.join("\n").replace(/\n\n$/, "\n");
|
|
616
|
+
}
|
|
617
|
+
function prettyPrint(program) {
|
|
618
|
+
const lines = [];
|
|
572
619
|
program.routes.forEach((route) => {
|
|
573
|
-
lines.push(
|
|
574
|
-
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
575
|
-
pipelineLines.forEach((line) => lines.push(line));
|
|
620
|
+
lines.push(printRoute(route));
|
|
576
621
|
lines.push("");
|
|
577
622
|
});
|
|
578
623
|
program.describes.forEach((describe) => {
|
|
579
|
-
lines.push(
|
|
580
|
-
describe.mocks.forEach((mock) => {
|
|
581
|
-
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
582
|
-
});
|
|
624
|
+
lines.push(printDescribe(describe));
|
|
583
625
|
lines.push("");
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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
|
-
});
|
|
626
|
+
});
|
|
627
|
+
if (program.configs.length > 0) {
|
|
628
|
+
lines.push("## Config");
|
|
629
|
+
program.configs.forEach((config) => {
|
|
630
|
+
lines.push(printConfig(config));
|
|
598
631
|
lines.push("");
|
|
599
632
|
});
|
|
633
|
+
}
|
|
634
|
+
program.pipelines.forEach((pipeline) => {
|
|
635
|
+
lines.push(printPipeline(pipeline));
|
|
636
|
+
lines.push("");
|
|
637
|
+
});
|
|
638
|
+
program.variables.forEach((variable) => {
|
|
639
|
+
lines.push(printVariable(variable));
|
|
600
640
|
});
|
|
641
|
+
if (program.variables.length > 0) lines.push("");
|
|
601
642
|
return lines.join("\n").trim();
|
|
602
643
|
}
|
|
603
644
|
function formatConfigValue(value) {
|
|
@@ -628,9 +669,9 @@ function formatPipelineStep(step, indent = " ") {
|
|
|
628
669
|
}
|
|
629
670
|
}
|
|
630
671
|
function formatStepConfig(config) {
|
|
631
|
-
if (config.includes("
|
|
672
|
+
if (config.includes("\n") || config.includes("{") || config.includes("[") || config.includes(".") || config.includes("(")) {
|
|
632
673
|
return `\`${config}\``;
|
|
633
|
-
} else if (config.includes(" ")
|
|
674
|
+
} else if (config.includes(" ")) {
|
|
634
675
|
return `"${config}"`;
|
|
635
676
|
} else {
|
|
636
677
|
return config;
|
|
@@ -658,9 +699,22 @@ function formatWhen(when) {
|
|
|
658
699
|
}
|
|
659
700
|
}
|
|
660
701
|
export {
|
|
702
|
+
formatConfigValue,
|
|
703
|
+
formatPipelineRef,
|
|
704
|
+
formatPipelineStep,
|
|
705
|
+
formatStepConfig,
|
|
706
|
+
formatWhen,
|
|
661
707
|
getPipelineRanges,
|
|
662
708
|
getVariableRanges,
|
|
663
709
|
parseProgram,
|
|
664
710
|
parseProgramWithDiagnostics,
|
|
665
|
-
prettyPrint
|
|
711
|
+
prettyPrint,
|
|
712
|
+
printCondition,
|
|
713
|
+
printConfig,
|
|
714
|
+
printDescribe,
|
|
715
|
+
printMock,
|
|
716
|
+
printPipeline,
|
|
717
|
+
printRoute,
|
|
718
|
+
printTest,
|
|
719
|
+
printVariable
|
|
666
720
|
};
|