webpipe-js 0.1.4 → 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 +100 -37
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +86 -36
- 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,59 +590,96 @@ var ParseFailure = class extends Error {
|
|
|
577
590
|
this.at = at;
|
|
578
591
|
}
|
|
579
592
|
};
|
|
593
|
+
function printRoute(route) {
|
|
594
|
+
const lines = [];
|
|
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}`);
|
|
606
|
+
});
|
|
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));
|
|
615
|
+
});
|
|
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));
|
|
656
|
+
lines.push("");
|
|
657
|
+
});
|
|
658
|
+
return lines.join("\n").replace(/\n\n$/, "\n");
|
|
659
|
+
}
|
|
580
660
|
function prettyPrint(program) {
|
|
581
661
|
const lines = [];
|
|
582
662
|
program.routes.forEach((route) => {
|
|
583
|
-
lines.push(
|
|
584
|
-
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
585
|
-
pipelineLines.forEach((line) => lines.push(line));
|
|
663
|
+
lines.push(printRoute(route));
|
|
586
664
|
lines.push("");
|
|
587
665
|
});
|
|
588
666
|
program.describes.forEach((describe) => {
|
|
589
|
-
lines.push(
|
|
590
|
-
describe.mocks.forEach((mock) => {
|
|
591
|
-
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
592
|
-
});
|
|
667
|
+
lines.push(printDescribe(describe));
|
|
593
668
|
lines.push("");
|
|
594
|
-
describe.tests.forEach((test) => {
|
|
595
|
-
lines.push(` it "${test.name}"`);
|
|
596
|
-
test.mocks.forEach((mock) => {
|
|
597
|
-
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
598
|
-
});
|
|
599
|
-
lines.push(` when ${formatWhen(test.when)}`);
|
|
600
|
-
if (test.input) {
|
|
601
|
-
lines.push(` with input \`${test.input}\``);
|
|
602
|
-
}
|
|
603
|
-
test.conditions.forEach((condition) => {
|
|
604
|
-
const condType = condition.conditionType.toLowerCase();
|
|
605
|
-
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
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}`);
|
|
608
|
-
});
|
|
609
|
-
lines.push("");
|
|
610
|
-
});
|
|
611
669
|
});
|
|
612
670
|
if (program.configs.length > 0) {
|
|
613
671
|
lines.push("## Config");
|
|
614
672
|
program.configs.forEach((config) => {
|
|
615
|
-
lines.push(
|
|
616
|
-
config.properties.forEach((prop) => {
|
|
617
|
-
const value = formatConfigValue(prop.value);
|
|
618
|
-
lines.push(` ${prop.key}: ${value}`);
|
|
619
|
-
});
|
|
620
|
-
lines.push("}");
|
|
673
|
+
lines.push(printConfig(config));
|
|
621
674
|
lines.push("");
|
|
622
675
|
});
|
|
623
676
|
}
|
|
624
677
|
program.pipelines.forEach((pipeline) => {
|
|
625
|
-
lines.push(
|
|
626
|
-
pipeline.pipeline.steps.forEach((step) => {
|
|
627
|
-
lines.push(formatPipelineStep(step));
|
|
628
|
-
});
|
|
678
|
+
lines.push(printPipeline(pipeline));
|
|
629
679
|
lines.push("");
|
|
630
680
|
});
|
|
631
681
|
program.variables.forEach((variable) => {
|
|
632
|
-
lines.push(
|
|
682
|
+
lines.push(printVariable(variable));
|
|
633
683
|
});
|
|
634
684
|
if (program.variables.length > 0) lines.push("");
|
|
635
685
|
return lines.join("\n").trim();
|
|
@@ -693,9 +743,22 @@ function formatWhen(when) {
|
|
|
693
743
|
}
|
|
694
744
|
// Annotate the CommonJS export names for ESM import in node:
|
|
695
745
|
0 && (module.exports = {
|
|
746
|
+
formatConfigValue,
|
|
747
|
+
formatPipelineRef,
|
|
748
|
+
formatPipelineStep,
|
|
749
|
+
formatStepConfig,
|
|
750
|
+
formatWhen,
|
|
696
751
|
getPipelineRanges,
|
|
697
752
|
getVariableRanges,
|
|
698
753
|
parseProgram,
|
|
699
754
|
parseProgramWithDiagnostics,
|
|
700
|
-
prettyPrint
|
|
755
|
+
prettyPrint,
|
|
756
|
+
printCondition,
|
|
757
|
+
printConfig,
|
|
758
|
+
printDescribe,
|
|
759
|
+
printMock,
|
|
760
|
+
printPipeline,
|
|
761
|
+
printRoute,
|
|
762
|
+
printTest,
|
|
763
|
+
printVariable
|
|
701
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,59 +547,96 @@ var ParseFailure = class extends Error {
|
|
|
547
547
|
this.at = at;
|
|
548
548
|
}
|
|
549
549
|
};
|
|
550
|
+
function printRoute(route) {
|
|
551
|
+
const lines = [];
|
|
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}`);
|
|
563
|
+
});
|
|
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));
|
|
572
|
+
});
|
|
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));
|
|
613
|
+
lines.push("");
|
|
614
|
+
});
|
|
615
|
+
return lines.join("\n").replace(/\n\n$/, "\n");
|
|
616
|
+
}
|
|
550
617
|
function prettyPrint(program) {
|
|
551
618
|
const lines = [];
|
|
552
619
|
program.routes.forEach((route) => {
|
|
553
|
-
lines.push(
|
|
554
|
-
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
555
|
-
pipelineLines.forEach((line) => lines.push(line));
|
|
620
|
+
lines.push(printRoute(route));
|
|
556
621
|
lines.push("");
|
|
557
622
|
});
|
|
558
623
|
program.describes.forEach((describe) => {
|
|
559
|
-
lines.push(
|
|
560
|
-
describe.mocks.forEach((mock) => {
|
|
561
|
-
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
562
|
-
});
|
|
624
|
+
lines.push(printDescribe(describe));
|
|
563
625
|
lines.push("");
|
|
564
|
-
describe.tests.forEach((test) => {
|
|
565
|
-
lines.push(` it "${test.name}"`);
|
|
566
|
-
test.mocks.forEach((mock) => {
|
|
567
|
-
lines.push(` with mock ${mock.target} returning \`${mock.returnValue}\``);
|
|
568
|
-
});
|
|
569
|
-
lines.push(` when ${formatWhen(test.when)}`);
|
|
570
|
-
if (test.input) {
|
|
571
|
-
lines.push(` with input \`${test.input}\``);
|
|
572
|
-
}
|
|
573
|
-
test.conditions.forEach((condition) => {
|
|
574
|
-
const condType = condition.conditionType.toLowerCase();
|
|
575
|
-
const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
|
|
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}`);
|
|
578
|
-
});
|
|
579
|
-
lines.push("");
|
|
580
|
-
});
|
|
581
626
|
});
|
|
582
627
|
if (program.configs.length > 0) {
|
|
583
628
|
lines.push("## Config");
|
|
584
629
|
program.configs.forEach((config) => {
|
|
585
|
-
lines.push(
|
|
586
|
-
config.properties.forEach((prop) => {
|
|
587
|
-
const value = formatConfigValue(prop.value);
|
|
588
|
-
lines.push(` ${prop.key}: ${value}`);
|
|
589
|
-
});
|
|
590
|
-
lines.push("}");
|
|
630
|
+
lines.push(printConfig(config));
|
|
591
631
|
lines.push("");
|
|
592
632
|
});
|
|
593
633
|
}
|
|
594
634
|
program.pipelines.forEach((pipeline) => {
|
|
595
|
-
lines.push(
|
|
596
|
-
pipeline.pipeline.steps.forEach((step) => {
|
|
597
|
-
lines.push(formatPipelineStep(step));
|
|
598
|
-
});
|
|
635
|
+
lines.push(printPipeline(pipeline));
|
|
599
636
|
lines.push("");
|
|
600
637
|
});
|
|
601
638
|
program.variables.forEach((variable) => {
|
|
602
|
-
lines.push(
|
|
639
|
+
lines.push(printVariable(variable));
|
|
603
640
|
});
|
|
604
641
|
if (program.variables.length > 0) lines.push("");
|
|
605
642
|
return lines.join("\n").trim();
|
|
@@ -662,9 +699,22 @@ function formatWhen(when) {
|
|
|
662
699
|
}
|
|
663
700
|
}
|
|
664
701
|
export {
|
|
702
|
+
formatConfigValue,
|
|
703
|
+
formatPipelineRef,
|
|
704
|
+
formatPipelineStep,
|
|
705
|
+
formatStepConfig,
|
|
706
|
+
formatWhen,
|
|
665
707
|
getPipelineRanges,
|
|
666
708
|
getVariableRanges,
|
|
667
709
|
parseProgram,
|
|
668
710
|
parseProgramWithDiagnostics,
|
|
669
|
-
prettyPrint
|
|
711
|
+
prettyPrint,
|
|
712
|
+
printCondition,
|
|
713
|
+
printConfig,
|
|
714
|
+
printDescribe,
|
|
715
|
+
printMock,
|
|
716
|
+
printPipeline,
|
|
717
|
+
printRoute,
|
|
718
|
+
printTest,
|
|
719
|
+
printVariable
|
|
670
720
|
};
|