webpipe-js 2.0.2 → 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) {
@@ -569,9 +608,7 @@ var Parser = class {
569
608
  return { varType, name, value, inlineComment: inlineComment || void 0 };
570
609
  }
571
610
  parseGraphQLSchema() {
572
- this.expect("graphql");
573
- this.skipInlineSpaces();
574
- this.expect("schema");
611
+ this.expect("graphqlSchema");
575
612
  this.skipInlineSpaces();
576
613
  this.expect("=");
577
614
  const inlineComment = this.parseInlineComment();
@@ -1013,7 +1050,7 @@ function formatPipelineStep(step, indent = " ") {
1013
1050
  const configPart = formatStepConfig(step.config, step.configType);
1014
1051
  const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
1015
1052
  return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
1016
- } else {
1053
+ } else if (step.kind === "Result") {
1017
1054
  const lines = [`${indent}|> result`];
1018
1055
  step.branches.forEach((branch) => {
1019
1056
  const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
@@ -1023,6 +1060,22 @@ function formatPipelineStep(step, indent = " ") {
1023
1060
  });
1024
1061
  });
1025
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");
1026
1079
  }
1027
1080
  }
1028
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) {
@@ -520,9 +559,7 @@ var Parser = class {
520
559
  return { varType, name, value, inlineComment: inlineComment || void 0 };
521
560
  }
522
561
  parseGraphQLSchema() {
523
- this.expect("graphql");
524
- this.skipInlineSpaces();
525
- this.expect("schema");
562
+ this.expect("graphqlSchema");
526
563
  this.skipInlineSpaces();
527
564
  this.expect("=");
528
565
  const inlineComment = this.parseInlineComment();
@@ -964,7 +1001,7 @@ function formatPipelineStep(step, indent = " ") {
964
1001
  const configPart = formatStepConfig(step.config, step.configType);
965
1002
  const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
966
1003
  return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
967
- } else {
1004
+ } else if (step.kind === "Result") {
968
1005
  const lines = [`${indent}|> result`];
969
1006
  step.branches.forEach((branch) => {
970
1007
  const branchName = branch.branchType.kind === "Ok" ? "ok" : branch.branchType.kind === "Default" ? "default" : branch.branchType.name;
@@ -974,6 +1011,22 @@ function formatPipelineStep(step, indent = " ") {
974
1011
  });
975
1012
  });
976
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");
977
1030
  }
978
1031
  }
979
1032
  function formatStepConfig(config, configType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",