webpipe-js 2.0.3 → 2.0.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 CHANGED
@@ -457,6 +457,8 @@ var Parser = class {
457
457
  parsePipelineStep() {
458
458
  const result = this.tryParse(() => this.parseResultStep());
459
459
  if (result) return result;
460
+ const ifStep = this.tryParse(() => this.parseIfStep());
461
+ if (ifStep) return ifStep;
460
462
  return this.parseRegularStep();
461
463
  }
462
464
  parseRegularStep() {
@@ -508,6 +510,50 @@ var Parser = class {
508
510
  const pipeline = this.parsePipeline();
509
511
  return { branchType, statusCode, pipeline };
510
512
  }
513
+ parseIfStep() {
514
+ this.skipWhitespaceOnly();
515
+ this.expect("|>");
516
+ this.skipInlineSpaces();
517
+ this.expect("if");
518
+ this.skipSpaces();
519
+ const condition = this.parseIfPipeline("then:");
520
+ this.skipSpaces();
521
+ this.expect("then:");
522
+ this.skipSpaces();
523
+ const thenBranch = this.parseIfPipeline("else:", "end");
524
+ this.skipSpaces();
525
+ const elseBranch = this.tryParse(() => {
526
+ this.expect("else:");
527
+ this.skipSpaces();
528
+ return this.parseIfPipeline("end");
529
+ });
530
+ this.skipSpaces();
531
+ this.tryParse(() => {
532
+ this.expect("end");
533
+ return true;
534
+ });
535
+ return { kind: "If", condition, thenBranch, elseBranch: elseBranch || void 0 };
536
+ }
537
+ parseIfPipeline(...stopKeywords) {
538
+ const steps = [];
539
+ while (true) {
540
+ const save = this.pos;
541
+ this.skipWhitespaceOnly();
542
+ for (const keyword of stopKeywords) {
543
+ if (this.text.startsWith(keyword, this.pos)) {
544
+ this.pos = save;
545
+ return { steps };
546
+ }
547
+ }
548
+ if (!this.text.startsWith("|>", this.pos)) {
549
+ this.pos = save;
550
+ break;
551
+ }
552
+ const step = this.parsePipelineStep();
553
+ steps.push(step);
554
+ }
555
+ return { steps };
556
+ }
511
557
  parsePipeline() {
512
558
  const steps = [];
513
559
  while (true) {
@@ -1011,7 +1057,7 @@ function formatPipelineStep(step, indent = " ") {
1011
1057
  const configPart = formatStepConfig(step.config, step.configType);
1012
1058
  const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
1013
1059
  return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
1014
- } else {
1060
+ } else if (step.kind === "Result") {
1015
1061
  const lines = [`${indent}|> result`];
1016
1062
  step.branches.forEach((branch) => {
1017
1063
  const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
@@ -1021,6 +1067,22 @@ function formatPipelineStep(step, indent = " ") {
1021
1067
  });
1022
1068
  });
1023
1069
  return lines.join("\n");
1070
+ } else {
1071
+ const lines = [`${indent}|> if`];
1072
+ step.condition.steps.forEach((condStep) => {
1073
+ lines.push(formatPipelineStep(condStep, indent + " "));
1074
+ });
1075
+ lines.push(`${indent} then:`);
1076
+ step.thenBranch.steps.forEach((thenStep) => {
1077
+ lines.push(formatPipelineStep(thenStep, indent + " "));
1078
+ });
1079
+ if (step.elseBranch) {
1080
+ lines.push(`${indent} else:`);
1081
+ step.elseBranch.steps.forEach((elseStep) => {
1082
+ lines.push(formatPipelineStep(elseStep, indent + " "));
1083
+ });
1084
+ }
1085
+ return lines.join("\n");
1024
1086
  }
1025
1087
  }
1026
1088
  function formatStepConfig(config, configType) {
package/dist/index.d.cts CHANGED
@@ -102,6 +102,11 @@ type PipelineStep = {
102
102
  } | {
103
103
  kind: 'Result';
104
104
  branches: ResultBranch[];
105
+ } | {
106
+ kind: 'If';
107
+ condition: Pipeline;
108
+ thenBranch: Pipeline;
109
+ elseBranch?: Pipeline;
105
110
  };
106
111
  interface ResultBranch {
107
112
  branchType: ResultBranchType;
package/dist/index.d.ts CHANGED
@@ -102,6 +102,11 @@ type PipelineStep = {
102
102
  } | {
103
103
  kind: 'Result';
104
104
  branches: ResultBranch[];
105
+ } | {
106
+ kind: 'If';
107
+ condition: Pipeline;
108
+ thenBranch: Pipeline;
109
+ elseBranch?: Pipeline;
105
110
  };
106
111
  interface ResultBranch {
107
112
  branchType: ResultBranchType;
package/dist/index.mjs CHANGED
@@ -408,6 +408,8 @@ var Parser = class {
408
408
  parsePipelineStep() {
409
409
  const result = this.tryParse(() => this.parseResultStep());
410
410
  if (result) return result;
411
+ const ifStep = this.tryParse(() => this.parseIfStep());
412
+ if (ifStep) return ifStep;
411
413
  return this.parseRegularStep();
412
414
  }
413
415
  parseRegularStep() {
@@ -459,6 +461,50 @@ var Parser = class {
459
461
  const pipeline = this.parsePipeline();
460
462
  return { branchType, statusCode, pipeline };
461
463
  }
464
+ parseIfStep() {
465
+ this.skipWhitespaceOnly();
466
+ this.expect("|>");
467
+ this.skipInlineSpaces();
468
+ this.expect("if");
469
+ this.skipSpaces();
470
+ const condition = this.parseIfPipeline("then:");
471
+ this.skipSpaces();
472
+ this.expect("then:");
473
+ this.skipSpaces();
474
+ const thenBranch = this.parseIfPipeline("else:", "end");
475
+ this.skipSpaces();
476
+ const elseBranch = this.tryParse(() => {
477
+ this.expect("else:");
478
+ this.skipSpaces();
479
+ return this.parseIfPipeline("end");
480
+ });
481
+ this.skipSpaces();
482
+ this.tryParse(() => {
483
+ this.expect("end");
484
+ return true;
485
+ });
486
+ return { kind: "If", condition, thenBranch, elseBranch: elseBranch || void 0 };
487
+ }
488
+ parseIfPipeline(...stopKeywords) {
489
+ const steps = [];
490
+ while (true) {
491
+ const save = this.pos;
492
+ this.skipWhitespaceOnly();
493
+ for (const keyword of stopKeywords) {
494
+ if (this.text.startsWith(keyword, this.pos)) {
495
+ this.pos = save;
496
+ return { steps };
497
+ }
498
+ }
499
+ if (!this.text.startsWith("|>", this.pos)) {
500
+ this.pos = save;
501
+ break;
502
+ }
503
+ const step = this.parsePipelineStep();
504
+ steps.push(step);
505
+ }
506
+ return { steps };
507
+ }
462
508
  parsePipeline() {
463
509
  const steps = [];
464
510
  while (true) {
@@ -962,7 +1008,7 @@ function formatPipelineStep(step, indent = " ") {
962
1008
  const configPart = formatStepConfig(step.config, step.configType);
963
1009
  const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
964
1010
  return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
965
- } else {
1011
+ } else if (step.kind === "Result") {
966
1012
  const lines = [`${indent}|> result`];
967
1013
  step.branches.forEach((branch) => {
968
1014
  const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
@@ -972,6 +1018,22 @@ function formatPipelineStep(step, indent = " ") {
972
1018
  });
973
1019
  });
974
1020
  return lines.join("\n");
1021
+ } else {
1022
+ const lines = [`${indent}|> if`];
1023
+ step.condition.steps.forEach((condStep) => {
1024
+ lines.push(formatPipelineStep(condStep, indent + " "));
1025
+ });
1026
+ lines.push(`${indent} then:`);
1027
+ step.thenBranch.steps.forEach((thenStep) => {
1028
+ lines.push(formatPipelineStep(thenStep, indent + " "));
1029
+ });
1030
+ if (step.elseBranch) {
1031
+ lines.push(`${indent} else:`);
1032
+ step.elseBranch.steps.forEach((elseStep) => {
1033
+ lines.push(formatPipelineStep(elseStep, indent + " "));
1034
+ });
1035
+ }
1036
+ return lines.join("\n");
975
1037
  }
976
1038
  }
977
1039
  function formatStepConfig(config, configType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",