webpipe-js 2.0.32 → 2.0.34
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 +136 -4
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +136 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -512,14 +512,22 @@ var Parser = class {
|
|
|
512
512
|
this.expect("|>");
|
|
513
513
|
this.skipInlineSpaces();
|
|
514
514
|
const name = this.parseIdentifier();
|
|
515
|
-
this.
|
|
515
|
+
const args = this.parseInlineArgs();
|
|
516
516
|
this.skipInlineSpaces();
|
|
517
|
-
|
|
517
|
+
let config = "";
|
|
518
|
+
let configType = "quoted";
|
|
519
|
+
if (this.cur() === ":") {
|
|
520
|
+
this.pos++;
|
|
521
|
+
this.skipInlineSpaces();
|
|
522
|
+
const res = this.parseStepConfig();
|
|
523
|
+
config = res.config;
|
|
524
|
+
configType = res.configType;
|
|
525
|
+
}
|
|
518
526
|
const condition = this.parseStepCondition();
|
|
519
527
|
const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
|
|
520
528
|
this.skipWhitespaceOnly();
|
|
521
529
|
const end = this.pos;
|
|
522
|
-
return { kind: "Regular", name, config, configType, condition, parsedJoinTargets, start, end };
|
|
530
|
+
return { kind: "Regular", name, args, config, configType, condition, parsedJoinTargets, start, end };
|
|
523
531
|
}
|
|
524
532
|
/**
|
|
525
533
|
* Parse optional step condition (tag expression after the config)
|
|
@@ -573,6 +581,129 @@ var Parser = class {
|
|
|
573
581
|
}
|
|
574
582
|
return names;
|
|
575
583
|
}
|
|
584
|
+
/**
|
|
585
|
+
* Split argument content by commas while respecting nesting depth and strings
|
|
586
|
+
* Example: `"url", {a:1, b:2}` -> [`"url"`, `{a:1, b:2}`]
|
|
587
|
+
*/
|
|
588
|
+
splitBalancedArgs(content) {
|
|
589
|
+
const args = [];
|
|
590
|
+
let current = "";
|
|
591
|
+
let depth = 0;
|
|
592
|
+
let inString = false;
|
|
593
|
+
let stringChar = "";
|
|
594
|
+
let escapeNext = false;
|
|
595
|
+
for (let i = 0; i < content.length; i++) {
|
|
596
|
+
const ch = content[i];
|
|
597
|
+
if (escapeNext) {
|
|
598
|
+
current += ch;
|
|
599
|
+
escapeNext = false;
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
if (ch === "\\" && inString) {
|
|
603
|
+
current += ch;
|
|
604
|
+
escapeNext = true;
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if ((ch === '"' || ch === "`") && !inString) {
|
|
608
|
+
inString = true;
|
|
609
|
+
stringChar = ch;
|
|
610
|
+
current += ch;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (ch === stringChar && inString) {
|
|
614
|
+
inString = false;
|
|
615
|
+
stringChar = "";
|
|
616
|
+
current += ch;
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
if (inString) {
|
|
620
|
+
current += ch;
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
624
|
+
depth++;
|
|
625
|
+
current += ch;
|
|
626
|
+
} else if (ch === ")" || ch === "]" || ch === "}") {
|
|
627
|
+
depth--;
|
|
628
|
+
current += ch;
|
|
629
|
+
} else if (ch === "," && depth === 0) {
|
|
630
|
+
args.push(current.trim());
|
|
631
|
+
current = "";
|
|
632
|
+
} else {
|
|
633
|
+
current += ch;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if (current.trim().length > 0) {
|
|
637
|
+
args.push(current.trim());
|
|
638
|
+
}
|
|
639
|
+
return args;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Parse inline arguments: middleware(arg1, arg2) or middleware[arg1, arg2]
|
|
643
|
+
* Returns the array of argument strings and advances position past the closing bracket
|
|
644
|
+
*/
|
|
645
|
+
parseInlineArgs() {
|
|
646
|
+
const trimmedStart = this.pos;
|
|
647
|
+
this.skipInlineSpaces();
|
|
648
|
+
const ch = this.cur();
|
|
649
|
+
if (ch !== "(" && ch !== "[") {
|
|
650
|
+
this.pos = trimmedStart;
|
|
651
|
+
return [];
|
|
652
|
+
}
|
|
653
|
+
const openChar = ch;
|
|
654
|
+
const closeChar = openChar === "(" ? ")" : "]";
|
|
655
|
+
this.pos++;
|
|
656
|
+
let depth = 1;
|
|
657
|
+
let inString = false;
|
|
658
|
+
let stringChar = "";
|
|
659
|
+
let escapeNext = false;
|
|
660
|
+
const contentStart = this.pos;
|
|
661
|
+
while (!this.eof() && depth > 0) {
|
|
662
|
+
const c = this.cur();
|
|
663
|
+
if (escapeNext) {
|
|
664
|
+
this.pos++;
|
|
665
|
+
escapeNext = false;
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
if (c === "\\" && inString) {
|
|
669
|
+
this.pos++;
|
|
670
|
+
escapeNext = true;
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
if ((c === '"' || c === "`") && !inString) {
|
|
674
|
+
inString = true;
|
|
675
|
+
stringChar = c;
|
|
676
|
+
this.pos++;
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
if (c === stringChar && inString) {
|
|
680
|
+
inString = false;
|
|
681
|
+
stringChar = "";
|
|
682
|
+
this.pos++;
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
if (!inString) {
|
|
686
|
+
if (c === openChar) {
|
|
687
|
+
depth++;
|
|
688
|
+
} else if (c === closeChar) {
|
|
689
|
+
depth--;
|
|
690
|
+
if (depth === 0) {
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
this.pos++;
|
|
696
|
+
}
|
|
697
|
+
if (depth !== 0) {
|
|
698
|
+
throw new ParseFailure(`unclosed ${openChar}`, contentStart);
|
|
699
|
+
}
|
|
700
|
+
const argsContent = this.text.slice(contentStart, this.pos);
|
|
701
|
+
this.pos++;
|
|
702
|
+
if (argsContent.trim().length === 0) {
|
|
703
|
+
return [];
|
|
704
|
+
}
|
|
705
|
+
return this.splitBalancedArgs(argsContent);
|
|
706
|
+
}
|
|
576
707
|
parseResultStep() {
|
|
577
708
|
this.skipWhitespaceOnly();
|
|
578
709
|
const start = this.pos;
|
|
@@ -1641,9 +1772,10 @@ function formatConfigValue(value) {
|
|
|
1641
1772
|
}
|
|
1642
1773
|
function formatPipelineStep(step, indent = " ") {
|
|
1643
1774
|
if (step.kind === "Regular") {
|
|
1775
|
+
const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
|
|
1644
1776
|
const configPart = formatStepConfig(step.config, step.configType);
|
|
1645
1777
|
const conditionPart = step.condition ? " " + formatTagExpr(step.condition) : "";
|
|
1646
|
-
return `${indent}|> ${step.name}: ${configPart}${conditionPart}`;
|
|
1778
|
+
return `${indent}|> ${step.name}${argsPart}: ${configPart}${conditionPart}`;
|
|
1647
1779
|
} else if (step.kind === "Result") {
|
|
1648
1780
|
const lines = [`${indent}|> result`];
|
|
1649
1781
|
step.branches.forEach((branch) => {
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -460,14 +460,22 @@ var Parser = class {
|
|
|
460
460
|
this.expect("|>");
|
|
461
461
|
this.skipInlineSpaces();
|
|
462
462
|
const name = this.parseIdentifier();
|
|
463
|
-
this.
|
|
463
|
+
const args = this.parseInlineArgs();
|
|
464
464
|
this.skipInlineSpaces();
|
|
465
|
-
|
|
465
|
+
let config = "";
|
|
466
|
+
let configType = "quoted";
|
|
467
|
+
if (this.cur() === ":") {
|
|
468
|
+
this.pos++;
|
|
469
|
+
this.skipInlineSpaces();
|
|
470
|
+
const res = this.parseStepConfig();
|
|
471
|
+
config = res.config;
|
|
472
|
+
configType = res.configType;
|
|
473
|
+
}
|
|
466
474
|
const condition = this.parseStepCondition();
|
|
467
475
|
const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
|
|
468
476
|
this.skipWhitespaceOnly();
|
|
469
477
|
const end = this.pos;
|
|
470
|
-
return { kind: "Regular", name, config, configType, condition, parsedJoinTargets, start, end };
|
|
478
|
+
return { kind: "Regular", name, args, config, configType, condition, parsedJoinTargets, start, end };
|
|
471
479
|
}
|
|
472
480
|
/**
|
|
473
481
|
* Parse optional step condition (tag expression after the config)
|
|
@@ -521,6 +529,129 @@ var Parser = class {
|
|
|
521
529
|
}
|
|
522
530
|
return names;
|
|
523
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* Split argument content by commas while respecting nesting depth and strings
|
|
534
|
+
* Example: `"url", {a:1, b:2}` -> [`"url"`, `{a:1, b:2}`]
|
|
535
|
+
*/
|
|
536
|
+
splitBalancedArgs(content) {
|
|
537
|
+
const args = [];
|
|
538
|
+
let current = "";
|
|
539
|
+
let depth = 0;
|
|
540
|
+
let inString = false;
|
|
541
|
+
let stringChar = "";
|
|
542
|
+
let escapeNext = false;
|
|
543
|
+
for (let i = 0; i < content.length; i++) {
|
|
544
|
+
const ch = content[i];
|
|
545
|
+
if (escapeNext) {
|
|
546
|
+
current += ch;
|
|
547
|
+
escapeNext = false;
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (ch === "\\" && inString) {
|
|
551
|
+
current += ch;
|
|
552
|
+
escapeNext = true;
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
if ((ch === '"' || ch === "`") && !inString) {
|
|
556
|
+
inString = true;
|
|
557
|
+
stringChar = ch;
|
|
558
|
+
current += ch;
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
if (ch === stringChar && inString) {
|
|
562
|
+
inString = false;
|
|
563
|
+
stringChar = "";
|
|
564
|
+
current += ch;
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
if (inString) {
|
|
568
|
+
current += ch;
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
572
|
+
depth++;
|
|
573
|
+
current += ch;
|
|
574
|
+
} else if (ch === ")" || ch === "]" || ch === "}") {
|
|
575
|
+
depth--;
|
|
576
|
+
current += ch;
|
|
577
|
+
} else if (ch === "," && depth === 0) {
|
|
578
|
+
args.push(current.trim());
|
|
579
|
+
current = "";
|
|
580
|
+
} else {
|
|
581
|
+
current += ch;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (current.trim().length > 0) {
|
|
585
|
+
args.push(current.trim());
|
|
586
|
+
}
|
|
587
|
+
return args;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Parse inline arguments: middleware(arg1, arg2) or middleware[arg1, arg2]
|
|
591
|
+
* Returns the array of argument strings and advances position past the closing bracket
|
|
592
|
+
*/
|
|
593
|
+
parseInlineArgs() {
|
|
594
|
+
const trimmedStart = this.pos;
|
|
595
|
+
this.skipInlineSpaces();
|
|
596
|
+
const ch = this.cur();
|
|
597
|
+
if (ch !== "(" && ch !== "[") {
|
|
598
|
+
this.pos = trimmedStart;
|
|
599
|
+
return [];
|
|
600
|
+
}
|
|
601
|
+
const openChar = ch;
|
|
602
|
+
const closeChar = openChar === "(" ? ")" : "]";
|
|
603
|
+
this.pos++;
|
|
604
|
+
let depth = 1;
|
|
605
|
+
let inString = false;
|
|
606
|
+
let stringChar = "";
|
|
607
|
+
let escapeNext = false;
|
|
608
|
+
const contentStart = this.pos;
|
|
609
|
+
while (!this.eof() && depth > 0) {
|
|
610
|
+
const c = this.cur();
|
|
611
|
+
if (escapeNext) {
|
|
612
|
+
this.pos++;
|
|
613
|
+
escapeNext = false;
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
if (c === "\\" && inString) {
|
|
617
|
+
this.pos++;
|
|
618
|
+
escapeNext = true;
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
if ((c === '"' || c === "`") && !inString) {
|
|
622
|
+
inString = true;
|
|
623
|
+
stringChar = c;
|
|
624
|
+
this.pos++;
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
if (c === stringChar && inString) {
|
|
628
|
+
inString = false;
|
|
629
|
+
stringChar = "";
|
|
630
|
+
this.pos++;
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
if (!inString) {
|
|
634
|
+
if (c === openChar) {
|
|
635
|
+
depth++;
|
|
636
|
+
} else if (c === closeChar) {
|
|
637
|
+
depth--;
|
|
638
|
+
if (depth === 0) {
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
this.pos++;
|
|
644
|
+
}
|
|
645
|
+
if (depth !== 0) {
|
|
646
|
+
throw new ParseFailure(`unclosed ${openChar}`, contentStart);
|
|
647
|
+
}
|
|
648
|
+
const argsContent = this.text.slice(contentStart, this.pos);
|
|
649
|
+
this.pos++;
|
|
650
|
+
if (argsContent.trim().length === 0) {
|
|
651
|
+
return [];
|
|
652
|
+
}
|
|
653
|
+
return this.splitBalancedArgs(argsContent);
|
|
654
|
+
}
|
|
524
655
|
parseResultStep() {
|
|
525
656
|
this.skipWhitespaceOnly();
|
|
526
657
|
const start = this.pos;
|
|
@@ -1589,9 +1720,10 @@ function formatConfigValue(value) {
|
|
|
1589
1720
|
}
|
|
1590
1721
|
function formatPipelineStep(step, indent = " ") {
|
|
1591
1722
|
if (step.kind === "Regular") {
|
|
1723
|
+
const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
|
|
1592
1724
|
const configPart = formatStepConfig(step.config, step.configType);
|
|
1593
1725
|
const conditionPart = step.condition ? " " + formatTagExpr(step.condition) : "";
|
|
1594
|
-
return `${indent}|> ${step.name}: ${configPart}${conditionPart}`;
|
|
1726
|
+
return `${indent}|> ${step.name}${argsPart}: ${configPart}${conditionPart}`;
|
|
1595
1727
|
} else if (step.kind === "Result") {
|
|
1596
1728
|
const lines = [`${indent}|> result`];
|
|
1597
1729
|
step.branches.forEach((branch) => {
|