webpipe-js 2.0.3 → 2.0.4

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,43 @@ 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:");
524
+ this.skipSpaces();
525
+ const elseBranch = this.tryParse(() => {
526
+ this.expect("else:");
527
+ this.skipSpaces();
528
+ return this.parsePipeline();
529
+ });
530
+ return { kind: "If", condition, thenBranch, elseBranch: elseBranch || void 0 };
531
+ }
532
+ parseIfPipeline(stopKeyword) {
533
+ const steps = [];
534
+ while (true) {
535
+ const save = this.pos;
536
+ this.skipWhitespaceOnly();
537
+ if (this.text.startsWith(stopKeyword, this.pos)) {
538
+ this.pos = save;
539
+ break;
540
+ }
541
+ if (!this.text.startsWith("|>", this.pos)) {
542
+ this.pos = save;
543
+ break;
544
+ }
545
+ const step = this.parsePipelineStep();
546
+ steps.push(step);
547
+ }
548
+ return { steps };
549
+ }
511
550
  parsePipeline() {
512
551
  const steps = [];
513
552
  while (true) {
@@ -1011,7 +1050,7 @@ function formatPipelineStep(step, indent = " ") {
1011
1050
  const configPart = formatStepConfig(step.config, step.configType);
1012
1051
  const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
1013
1052
  return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
1014
- } else {
1053
+ } else if (step.kind === "Result") {
1015
1054
  const lines = [`${indent}|> result`];
1016
1055
  step.branches.forEach((branch) => {
1017
1056
  const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
@@ -1021,6 +1060,22 @@ function formatPipelineStep(step, indent = " ") {
1021
1060
  });
1022
1061
  });
1023
1062
  return lines.join("\n");
1063
+ } else {
1064
+ const lines = [`${indent}|> if`];
1065
+ step.condition.steps.forEach((condStep) => {
1066
+ lines.push(formatPipelineStep(condStep, indent + " "));
1067
+ });
1068
+ lines.push(`${indent} then:`);
1069
+ step.thenBranch.steps.forEach((thenStep) => {
1070
+ lines.push(formatPipelineStep(thenStep, indent + " "));
1071
+ });
1072
+ if (step.elseBranch) {
1073
+ lines.push(`${indent} else:`);
1074
+ step.elseBranch.steps.forEach((elseStep) => {
1075
+ lines.push(formatPipelineStep(elseStep, indent + " "));
1076
+ });
1077
+ }
1078
+ return lines.join("\n");
1024
1079
  }
1025
1080
  }
1026
1081
  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,43 @@ 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:");
475
+ this.skipSpaces();
476
+ const elseBranch = this.tryParse(() => {
477
+ this.expect("else:");
478
+ this.skipSpaces();
479
+ return this.parsePipeline();
480
+ });
481
+ return { kind: "If", condition, thenBranch, elseBranch: elseBranch || void 0 };
482
+ }
483
+ parseIfPipeline(stopKeyword) {
484
+ const steps = [];
485
+ while (true) {
486
+ const save = this.pos;
487
+ this.skipWhitespaceOnly();
488
+ if (this.text.startsWith(stopKeyword, this.pos)) {
489
+ this.pos = save;
490
+ break;
491
+ }
492
+ if (!this.text.startsWith("|>", this.pos)) {
493
+ this.pos = save;
494
+ break;
495
+ }
496
+ const step = this.parsePipelineStep();
497
+ steps.push(step);
498
+ }
499
+ return { steps };
500
+ }
462
501
  parsePipeline() {
463
502
  const steps = [];
464
503
  while (true) {
@@ -962,7 +1001,7 @@ function formatPipelineStep(step, indent = " ") {
962
1001
  const configPart = formatStepConfig(step.config, step.configType);
963
1002
  const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
964
1003
  return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
965
- } else {
1004
+ } else if (step.kind === "Result") {
966
1005
  const lines = [`${indent}|> result`];
967
1006
  step.branches.forEach((branch) => {
968
1007
  const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
@@ -972,6 +1011,22 @@ function formatPipelineStep(step, indent = " ") {
972
1011
  });
973
1012
  });
974
1013
  return lines.join("\n");
1014
+ } else {
1015
+ const lines = [`${indent}|> if`];
1016
+ step.condition.steps.forEach((condStep) => {
1017
+ lines.push(formatPipelineStep(condStep, indent + " "));
1018
+ });
1019
+ lines.push(`${indent} then:`);
1020
+ step.thenBranch.steps.forEach((thenStep) => {
1021
+ lines.push(formatPipelineStep(thenStep, indent + " "));
1022
+ });
1023
+ if (step.elseBranch) {
1024
+ lines.push(`${indent} else:`);
1025
+ step.elseBranch.steps.forEach((elseStep) => {
1026
+ lines.push(formatPipelineStep(elseStep, indent + " "));
1027
+ });
1028
+ }
1029
+ return lines.join("\n");
975
1030
  }
976
1031
  }
977
1032
  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.4",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",