webpipe-js 2.0.81 → 2.0.97

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
@@ -552,35 +552,10 @@ var Parser = class {
552
552
  parsePipelineStep() {
553
553
  const result = this.tryParse(() => this.parseResultStep());
554
554
  if (result) return result;
555
- const ifStep = this.tryParse(() => this.parseIfStep());
556
- if (ifStep) return ifStep;
557
555
  const dispatchStep = this.tryParse(() => this.parseDispatchStep());
558
556
  if (dispatchStep) return dispatchStep;
559
- const foreachStep = this.tryParse(() => this.parseForeachStep());
560
- if (foreachStep) return foreachStep;
561
557
  return this.parseRegularStep();
562
558
  }
563
- parseForeachStep() {
564
- this.skipWhitespaceOnly();
565
- const start = this.pos;
566
- this.expect("|>");
567
- this.skipInlineSpaces();
568
- this.expect("foreach");
569
- if (this.cur() !== " " && this.cur() !== " ") {
570
- throw new ParseFailure("space after foreach", this.pos);
571
- }
572
- this.skipInlineSpaces();
573
- const selector = this.consumeWhile((c) => c !== "\n" && c !== "#").trim();
574
- if (selector.length === 0) {
575
- throw new ParseFailure("foreach selector", this.pos);
576
- }
577
- this.skipSpaces();
578
- const pipeline = this.parseIfPipeline("end");
579
- this.skipSpaces();
580
- this.expect("end");
581
- const end = this.pos;
582
- return { kind: "Foreach", selector, pipeline, start, end };
583
- }
584
559
  parseRegularStep() {
585
560
  this.skipWhitespaceOnly();
586
561
  const start = this.pos;
@@ -830,32 +805,6 @@ var Parser = class {
830
805
  const end = this.pos;
831
806
  return { branchType, statusCode, pipeline, start, end };
832
807
  }
833
- parseIfStep() {
834
- this.skipWhitespaceOnly();
835
- const start = this.pos;
836
- this.expect("|>");
837
- this.skipInlineSpaces();
838
- this.expect("if");
839
- this.skipSpaces();
840
- const condition = this.parseIfPipeline("then:");
841
- this.skipSpaces();
842
- this.expect("then:");
843
- this.skipWhitespaceOnly();
844
- const thenBranch = this.parseIfPipeline("else:", "end");
845
- this.skipWhitespaceOnly();
846
- const elseBranch = this.tryParse(() => {
847
- this.expect("else:");
848
- this.skipWhitespaceOnly();
849
- return this.parseIfPipeline("end");
850
- });
851
- this.skipWhitespaceOnly();
852
- this.tryParse(() => {
853
- this.expect("end");
854
- return true;
855
- });
856
- const end = this.pos;
857
- return { kind: "If", condition, thenBranch, elseBranch: elseBranch || void 0, start, end };
858
- }
859
808
  parseDispatchStep() {
860
809
  this.skipWhitespaceOnly();
861
810
  const start = this.pos;
@@ -1071,18 +1020,6 @@ var Parser = class {
1071
1020
  if (inline && inline.steps.length > 0) {
1072
1021
  return { kind: "Inline", pipeline: inline, start: inline.start, end: inline.end };
1073
1022
  }
1074
- const named = this.tryParse(() => {
1075
- this.skipWhitespaceOnly();
1076
- const start = this.pos;
1077
- this.expect("|>");
1078
- this.skipInlineSpaces();
1079
- this.expect("pipeline:");
1080
- this.skipInlineSpaces();
1081
- const name = this.parseIdentifier();
1082
- const end = this.pos;
1083
- return { kind: "Named", name, start, end };
1084
- });
1085
- if (named) return named;
1086
1023
  throw new Error("pipeline-ref");
1087
1024
  }
1088
1025
  parseVariable() {
@@ -2118,61 +2055,6 @@ function formatPipelineStep(step, indent = " ", isLastStep = false) {
2118
2055
  });
2119
2056
  });
2120
2057
  return lines.join("\n");
2121
- } else if (step.kind === "If") {
2122
- const lines = [`${indent}|> if`];
2123
- const conditionItems = [];
2124
- step.condition.steps.forEach((s) => {
2125
- conditionItems.push({ type: "step", item: s, position: s.start });
2126
- });
2127
- step.condition.comments.forEach((c) => {
2128
- conditionItems.push({ type: "comment", item: c, position: c.start || 0 });
2129
- });
2130
- conditionItems.sort((a, b) => a.position - b.position);
2131
- conditionItems.forEach((entry) => {
2132
- if (entry.type === "step") {
2133
- lines.push(formatPipelineStep(entry.item, indent + " "));
2134
- } else {
2135
- lines.push(`${indent} ${printComment(entry.item)}`);
2136
- }
2137
- });
2138
- lines.push(`${indent} then:`);
2139
- const thenItems = [];
2140
- step.thenBranch.steps.forEach((s) => {
2141
- thenItems.push({ type: "step", item: s, position: s.start });
2142
- });
2143
- step.thenBranch.comments.forEach((c) => {
2144
- thenItems.push({ type: "comment", item: c, position: c.start || 0 });
2145
- });
2146
- thenItems.sort((a, b) => a.position - b.position);
2147
- thenItems.forEach((entry) => {
2148
- if (entry.type === "step") {
2149
- lines.push(formatPipelineStep(entry.item, indent + " "));
2150
- } else {
2151
- lines.push(`${indent} ${printComment(entry.item)}`);
2152
- }
2153
- });
2154
- if (step.elseBranch) {
2155
- lines.push(`${indent} else:`);
2156
- const elseItems = [];
2157
- step.elseBranch.steps.forEach((s) => {
2158
- elseItems.push({ type: "step", item: s, position: s.start });
2159
- });
2160
- step.elseBranch.comments.forEach((c) => {
2161
- elseItems.push({ type: "comment", item: c, position: c.start || 0 });
2162
- });
2163
- elseItems.sort((a, b) => a.position - b.position);
2164
- elseItems.forEach((entry) => {
2165
- if (entry.type === "step") {
2166
- lines.push(formatPipelineStep(entry.item, indent + " "));
2167
- } else {
2168
- lines.push(`${indent} ${printComment(entry.item)}`);
2169
- }
2170
- });
2171
- }
2172
- if (!isLastStep) {
2173
- lines.push(`${indent}end`);
2174
- }
2175
- return lines.join("\n");
2176
2058
  } else if (step.kind === "Dispatch") {
2177
2059
  const lines = [`${indent}|> dispatch`];
2178
2060
  step.branches.forEach((branch) => {
@@ -2188,14 +2070,8 @@ function formatPipelineStep(step, indent = " ", isLastStep = false) {
2188
2070
  });
2189
2071
  }
2190
2072
  return lines.join("\n");
2191
- } else {
2192
- const lines = [`${indent}|> foreach ${step.selector}`];
2193
- step.pipeline.steps.forEach((innerStep) => {
2194
- lines.push(formatPipelineStep(innerStep, indent + " "));
2195
- });
2196
- lines.push(`${indent}end`);
2197
- return lines.join("\n");
2198
2073
  }
2074
+ throw new Error(`Unsupported pipeline step: ${step.kind}`);
2199
2075
  }
2200
2076
  function formatStepConfig(config, configType) {
2201
2077
  switch (configType) {
@@ -2235,35 +2111,31 @@ function formatTagExpr(expr) {
2235
2111
  }
2236
2112
  }
2237
2113
  function formatPipelineRef(ref) {
2238
- if (ref.kind === "Named") {
2239
- return [` |> pipeline: ${ref.name}`];
2240
- } else {
2241
- const lines = [];
2242
- const items = [];
2243
- ref.pipeline.steps.forEach((step) => {
2244
- items.push({ type: "step", item: step, position: step.start });
2245
- });
2246
- ref.pipeline.comments.forEach((comment) => {
2247
- items.push({ type: "comment", item: comment, position: comment.start || 0 });
2248
- });
2249
- items.sort((a, b) => a.position - b.position);
2250
- let lastStepIndex = -1;
2251
- for (let i = items.length - 1; i >= 0; i--) {
2252
- if (items[i].type === "step") {
2253
- lastStepIndex = i;
2254
- break;
2255
- }
2114
+ const lines = [];
2115
+ const items = [];
2116
+ ref.pipeline.steps.forEach((step) => {
2117
+ items.push({ type: "step", item: step, position: step.start });
2118
+ });
2119
+ ref.pipeline.comments.forEach((comment) => {
2120
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
2121
+ });
2122
+ items.sort((a, b) => a.position - b.position);
2123
+ let lastStepIndex = -1;
2124
+ for (let i = items.length - 1; i >= 0; i--) {
2125
+ if (items[i].type === "step") {
2126
+ lastStepIndex = i;
2127
+ break;
2256
2128
  }
2257
- items.forEach((entry, index) => {
2258
- if (entry.type === "step") {
2259
- const isLastStep = index === lastStepIndex;
2260
- lines.push(formatPipelineStep(entry.item, " ", isLastStep));
2261
- } else {
2262
- lines.push(` ${printComment(entry.item)}`);
2263
- }
2264
- });
2265
- return lines;
2266
2129
  }
2130
+ items.forEach((entry, index) => {
2131
+ if (entry.type === "step") {
2132
+ const isLastStep = index === lastStepIndex;
2133
+ lines.push(formatPipelineStep(entry.item, " ", isLastStep));
2134
+ } else {
2135
+ lines.push(` ${printComment(entry.item)}`);
2136
+ }
2137
+ });
2138
+ return lines;
2267
2139
  }
2268
2140
  function formatWhen(when) {
2269
2141
  switch (when.kind) {
package/dist/index.d.cts CHANGED
@@ -116,11 +116,6 @@ type PipelineRef = {
116
116
  pipeline: Pipeline;
117
117
  start: number;
118
118
  end: number;
119
- } | {
120
- kind: 'Named';
121
- name: string;
122
- start: number;
123
- end: number;
124
119
  };
125
120
  interface Pipeline {
126
121
  steps: PipelineStep[];
@@ -185,25 +180,12 @@ type PipelineStep = {
185
180
  branches: ResultBranch[];
186
181
  start: number;
187
182
  end: number;
188
- } | {
189
- kind: 'If';
190
- condition: Pipeline;
191
- thenBranch: Pipeline;
192
- elseBranch?: Pipeline;
193
- start: number;
194
- end: number;
195
183
  } | {
196
184
  kind: 'Dispatch';
197
185
  branches: DispatchBranch[];
198
186
  default?: Pipeline;
199
187
  start: number;
200
188
  end: number;
201
- } | {
202
- kind: 'Foreach';
203
- selector: string;
204
- pipeline: Pipeline;
205
- start: number;
206
- end: number;
207
189
  };
208
190
  interface DispatchBranch {
209
191
  condition: TagExpr;
package/dist/index.d.ts CHANGED
@@ -116,11 +116,6 @@ type PipelineRef = {
116
116
  pipeline: Pipeline;
117
117
  start: number;
118
118
  end: number;
119
- } | {
120
- kind: 'Named';
121
- name: string;
122
- start: number;
123
- end: number;
124
119
  };
125
120
  interface Pipeline {
126
121
  steps: PipelineStep[];
@@ -185,25 +180,12 @@ type PipelineStep = {
185
180
  branches: ResultBranch[];
186
181
  start: number;
187
182
  end: number;
188
- } | {
189
- kind: 'If';
190
- condition: Pipeline;
191
- thenBranch: Pipeline;
192
- elseBranch?: Pipeline;
193
- start: number;
194
- end: number;
195
183
  } | {
196
184
  kind: 'Dispatch';
197
185
  branches: DispatchBranch[];
198
186
  default?: Pipeline;
199
187
  start: number;
200
188
  end: number;
201
- } | {
202
- kind: 'Foreach';
203
- selector: string;
204
- pipeline: Pipeline;
205
- start: number;
206
- end: number;
207
189
  };
208
190
  interface DispatchBranch {
209
191
  condition: TagExpr;
package/dist/index.mjs CHANGED
@@ -498,35 +498,10 @@ var Parser = class {
498
498
  parsePipelineStep() {
499
499
  const result = this.tryParse(() => this.parseResultStep());
500
500
  if (result) return result;
501
- const ifStep = this.tryParse(() => this.parseIfStep());
502
- if (ifStep) return ifStep;
503
501
  const dispatchStep = this.tryParse(() => this.parseDispatchStep());
504
502
  if (dispatchStep) return dispatchStep;
505
- const foreachStep = this.tryParse(() => this.parseForeachStep());
506
- if (foreachStep) return foreachStep;
507
503
  return this.parseRegularStep();
508
504
  }
509
- parseForeachStep() {
510
- this.skipWhitespaceOnly();
511
- const start = this.pos;
512
- this.expect("|>");
513
- this.skipInlineSpaces();
514
- this.expect("foreach");
515
- if (this.cur() !== " " && this.cur() !== " ") {
516
- throw new ParseFailure("space after foreach", this.pos);
517
- }
518
- this.skipInlineSpaces();
519
- const selector = this.consumeWhile((c) => c !== "\n" && c !== "#").trim();
520
- if (selector.length === 0) {
521
- throw new ParseFailure("foreach selector", this.pos);
522
- }
523
- this.skipSpaces();
524
- const pipeline = this.parseIfPipeline("end");
525
- this.skipSpaces();
526
- this.expect("end");
527
- const end = this.pos;
528
- return { kind: "Foreach", selector, pipeline, start, end };
529
- }
530
505
  parseRegularStep() {
531
506
  this.skipWhitespaceOnly();
532
507
  const start = this.pos;
@@ -776,32 +751,6 @@ var Parser = class {
776
751
  const end = this.pos;
777
752
  return { branchType, statusCode, pipeline, start, end };
778
753
  }
779
- parseIfStep() {
780
- this.skipWhitespaceOnly();
781
- const start = this.pos;
782
- this.expect("|>");
783
- this.skipInlineSpaces();
784
- this.expect("if");
785
- this.skipSpaces();
786
- const condition = this.parseIfPipeline("then:");
787
- this.skipSpaces();
788
- this.expect("then:");
789
- this.skipWhitespaceOnly();
790
- const thenBranch = this.parseIfPipeline("else:", "end");
791
- this.skipWhitespaceOnly();
792
- const elseBranch = this.tryParse(() => {
793
- this.expect("else:");
794
- this.skipWhitespaceOnly();
795
- return this.parseIfPipeline("end");
796
- });
797
- this.skipWhitespaceOnly();
798
- this.tryParse(() => {
799
- this.expect("end");
800
- return true;
801
- });
802
- const end = this.pos;
803
- return { kind: "If", condition, thenBranch, elseBranch: elseBranch || void 0, start, end };
804
- }
805
754
  parseDispatchStep() {
806
755
  this.skipWhitespaceOnly();
807
756
  const start = this.pos;
@@ -1017,18 +966,6 @@ var Parser = class {
1017
966
  if (inline && inline.steps.length > 0) {
1018
967
  return { kind: "Inline", pipeline: inline, start: inline.start, end: inline.end };
1019
968
  }
1020
- const named = this.tryParse(() => {
1021
- this.skipWhitespaceOnly();
1022
- const start = this.pos;
1023
- this.expect("|>");
1024
- this.skipInlineSpaces();
1025
- this.expect("pipeline:");
1026
- this.skipInlineSpaces();
1027
- const name = this.parseIdentifier();
1028
- const end = this.pos;
1029
- return { kind: "Named", name, start, end };
1030
- });
1031
- if (named) return named;
1032
969
  throw new Error("pipeline-ref");
1033
970
  }
1034
971
  parseVariable() {
@@ -2064,61 +2001,6 @@ function formatPipelineStep(step, indent = " ", isLastStep = false) {
2064
2001
  });
2065
2002
  });
2066
2003
  return lines.join("\n");
2067
- } else if (step.kind === "If") {
2068
- const lines = [`${indent}|> if`];
2069
- const conditionItems = [];
2070
- step.condition.steps.forEach((s) => {
2071
- conditionItems.push({ type: "step", item: s, position: s.start });
2072
- });
2073
- step.condition.comments.forEach((c) => {
2074
- conditionItems.push({ type: "comment", item: c, position: c.start || 0 });
2075
- });
2076
- conditionItems.sort((a, b) => a.position - b.position);
2077
- conditionItems.forEach((entry) => {
2078
- if (entry.type === "step") {
2079
- lines.push(formatPipelineStep(entry.item, indent + " "));
2080
- } else {
2081
- lines.push(`${indent} ${printComment(entry.item)}`);
2082
- }
2083
- });
2084
- lines.push(`${indent} then:`);
2085
- const thenItems = [];
2086
- step.thenBranch.steps.forEach((s) => {
2087
- thenItems.push({ type: "step", item: s, position: s.start });
2088
- });
2089
- step.thenBranch.comments.forEach((c) => {
2090
- thenItems.push({ type: "comment", item: c, position: c.start || 0 });
2091
- });
2092
- thenItems.sort((a, b) => a.position - b.position);
2093
- thenItems.forEach((entry) => {
2094
- if (entry.type === "step") {
2095
- lines.push(formatPipelineStep(entry.item, indent + " "));
2096
- } else {
2097
- lines.push(`${indent} ${printComment(entry.item)}`);
2098
- }
2099
- });
2100
- if (step.elseBranch) {
2101
- lines.push(`${indent} else:`);
2102
- const elseItems = [];
2103
- step.elseBranch.steps.forEach((s) => {
2104
- elseItems.push({ type: "step", item: s, position: s.start });
2105
- });
2106
- step.elseBranch.comments.forEach((c) => {
2107
- elseItems.push({ type: "comment", item: c, position: c.start || 0 });
2108
- });
2109
- elseItems.sort((a, b) => a.position - b.position);
2110
- elseItems.forEach((entry) => {
2111
- if (entry.type === "step") {
2112
- lines.push(formatPipelineStep(entry.item, indent + " "));
2113
- } else {
2114
- lines.push(`${indent} ${printComment(entry.item)}`);
2115
- }
2116
- });
2117
- }
2118
- if (!isLastStep) {
2119
- lines.push(`${indent}end`);
2120
- }
2121
- return lines.join("\n");
2122
2004
  } else if (step.kind === "Dispatch") {
2123
2005
  const lines = [`${indent}|> dispatch`];
2124
2006
  step.branches.forEach((branch) => {
@@ -2134,14 +2016,8 @@ function formatPipelineStep(step, indent = " ", isLastStep = false) {
2134
2016
  });
2135
2017
  }
2136
2018
  return lines.join("\n");
2137
- } else {
2138
- const lines = [`${indent}|> foreach ${step.selector}`];
2139
- step.pipeline.steps.forEach((innerStep) => {
2140
- lines.push(formatPipelineStep(innerStep, indent + " "));
2141
- });
2142
- lines.push(`${indent}end`);
2143
- return lines.join("\n");
2144
2019
  }
2020
+ throw new Error(`Unsupported pipeline step: ${step.kind}`);
2145
2021
  }
2146
2022
  function formatStepConfig(config, configType) {
2147
2023
  switch (configType) {
@@ -2181,35 +2057,31 @@ function formatTagExpr(expr) {
2181
2057
  }
2182
2058
  }
2183
2059
  function formatPipelineRef(ref) {
2184
- if (ref.kind === "Named") {
2185
- return [` |> pipeline: ${ref.name}`];
2186
- } else {
2187
- const lines = [];
2188
- const items = [];
2189
- ref.pipeline.steps.forEach((step) => {
2190
- items.push({ type: "step", item: step, position: step.start });
2191
- });
2192
- ref.pipeline.comments.forEach((comment) => {
2193
- items.push({ type: "comment", item: comment, position: comment.start || 0 });
2194
- });
2195
- items.sort((a, b) => a.position - b.position);
2196
- let lastStepIndex = -1;
2197
- for (let i = items.length - 1; i >= 0; i--) {
2198
- if (items[i].type === "step") {
2199
- lastStepIndex = i;
2200
- break;
2201
- }
2060
+ const lines = [];
2061
+ const items = [];
2062
+ ref.pipeline.steps.forEach((step) => {
2063
+ items.push({ type: "step", item: step, position: step.start });
2064
+ });
2065
+ ref.pipeline.comments.forEach((comment) => {
2066
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
2067
+ });
2068
+ items.sort((a, b) => a.position - b.position);
2069
+ let lastStepIndex = -1;
2070
+ for (let i = items.length - 1; i >= 0; i--) {
2071
+ if (items[i].type === "step") {
2072
+ lastStepIndex = i;
2073
+ break;
2202
2074
  }
2203
- items.forEach((entry, index) => {
2204
- if (entry.type === "step") {
2205
- const isLastStep = index === lastStepIndex;
2206
- lines.push(formatPipelineStep(entry.item, " ", isLastStep));
2207
- } else {
2208
- lines.push(` ${printComment(entry.item)}`);
2209
- }
2210
- });
2211
- return lines;
2212
2075
  }
2076
+ items.forEach((entry, index) => {
2077
+ if (entry.type === "step") {
2078
+ const isLastStep = index === lastStepIndex;
2079
+ lines.push(formatPipelineStep(entry.item, " ", isLastStep));
2080
+ } else {
2081
+ lines.push(` ${printComment(entry.item)}`);
2082
+ }
2083
+ });
2084
+ return lines;
2213
2085
  }
2214
2086
  function formatWhen(when) {
2215
2087
  switch (when.kind) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.81",
3
+ "version": "2.0.97",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",