webpipe-js 2.0.7 → 2.0.9

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
@@ -330,7 +330,7 @@ var Parser = class {
330
330
  return content;
331
331
  }
332
332
  parseMethod() {
333
- const methods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
333
+ const methods = ["GET", "POST", "PUT", "DELETE"];
334
334
  for (const m of methods) {
335
335
  if (this.text.startsWith(m, this.pos)) {
336
336
  this.pos += m.length;
@@ -459,8 +459,44 @@ var Parser = class {
459
459
  if (result) return result;
460
460
  const ifStep = this.tryParse(() => this.parseIfStep());
461
461
  if (ifStep) return ifStep;
462
+ const dispatchStep = this.tryParse(() => this.parseDispatchStep());
463
+ if (dispatchStep) return dispatchStep;
462
464
  return this.parseRegularStep();
463
465
  }
466
+ parseDispatchStep() {
467
+ this.skipWhitespaceOnly();
468
+ this.expect("|>");
469
+ this.skipInlineSpaces();
470
+ this.expect("dispatch");
471
+ this.skipSpaces();
472
+ const cases = [];
473
+ while (true) {
474
+ const dispatchCase = this.tryParse(() => this.parseDispatchCase());
475
+ if (!dispatchCase) break;
476
+ cases.push(dispatchCase);
477
+ }
478
+ const defaultBranch = this.tryParse(() => this.parseDispatchDefault());
479
+ return { kind: "Dispatch", cases, default: defaultBranch || void 0 };
480
+ }
481
+ parseDispatchCase() {
482
+ this.skipSpaces();
483
+ this.expect("case");
484
+ this.skipInlineSpaces();
485
+ const condition = this.parseTag();
486
+ this.skipInlineSpaces();
487
+ this.expect(":");
488
+ this.skipSpaces();
489
+ const pipeline = this.parsePipeline();
490
+ return { condition, pipeline };
491
+ }
492
+ parseDispatchDefault() {
493
+ this.skipSpaces();
494
+ this.expect("default");
495
+ this.skipInlineSpaces();
496
+ this.expect(":");
497
+ this.skipSpaces();
498
+ return this.parsePipeline();
499
+ }
464
500
  parseRegularStep() {
465
501
  this.skipWhitespaceOnly();
466
502
  this.expect("|>");
@@ -470,8 +506,31 @@ var Parser = class {
470
506
  this.skipInlineSpaces();
471
507
  const { config, configType } = this.parseStepConfig();
472
508
  const tags = this.parseTags();
509
+ const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
473
510
  this.skipWhitespaceOnly();
474
- return { kind: "Regular", name, config, configType, tags };
511
+ return { kind: "Regular", name, config, configType, tags, parsedJoinTargets };
512
+ }
513
+ /**
514
+ * Pre-parse join config into task names at parse time.
515
+ * This avoids repeated parsing in the hot path during execution.
516
+ */
517
+ parseJoinTaskNames(config) {
518
+ const trimmed = config.trim();
519
+ if (trimmed.startsWith("[")) {
520
+ try {
521
+ const names2 = JSON.parse(trimmed);
522
+ if (Array.isArray(names2) && names2.every((n) => typeof n === "string")) {
523
+ return names2;
524
+ }
525
+ } catch {
526
+ return void 0;
527
+ }
528
+ }
529
+ const names = trimmed.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
530
+ if (names.length === 0) {
531
+ return void 0;
532
+ }
533
+ return names;
475
534
  }
476
535
  parseResultStep() {
477
536
  this.skipWhitespaceOnly();
@@ -1067,6 +1126,21 @@ function formatPipelineStep(step, indent = " ") {
1067
1126
  });
1068
1127
  });
1069
1128
  return lines.join("\n");
1129
+ } else if (step.kind === "Dispatch") {
1130
+ const lines = [`${indent}|> dispatch`];
1131
+ step.cases.forEach((dispatchCase) => {
1132
+ lines.push(`${indent} case ${formatTag(dispatchCase.condition)}:`);
1133
+ dispatchCase.pipeline.steps.forEach((caseStep) => {
1134
+ lines.push(formatPipelineStep(caseStep, indent + " "));
1135
+ });
1136
+ });
1137
+ if (step.default) {
1138
+ lines.push(`${indent} default:`);
1139
+ step.default.steps.forEach((defaultStep) => {
1140
+ lines.push(formatPipelineStep(defaultStep, indent + " "));
1141
+ });
1142
+ }
1143
+ return lines.join("\n");
1070
1144
  } else {
1071
1145
  const lines = [`${indent}|> if`];
1072
1146
  step.condition.steps.forEach((condStep) => {
package/dist/index.d.cts CHANGED
@@ -99,6 +99,7 @@ type PipelineStep = {
99
99
  config: string;
100
100
  configType: ConfigType;
101
101
  tags: Tag[];
102
+ parsedJoinTargets?: string[];
102
103
  } | {
103
104
  kind: 'Result';
104
105
  branches: ResultBranch[];
@@ -107,7 +108,15 @@ type PipelineStep = {
107
108
  condition: Pipeline;
108
109
  thenBranch: Pipeline;
109
110
  elseBranch?: Pipeline;
111
+ } | {
112
+ kind: 'Dispatch';
113
+ cases: DispatchCase[];
114
+ default?: Pipeline;
110
115
  };
116
+ interface DispatchCase {
117
+ condition: Tag;
118
+ pipeline: Pipeline;
119
+ }
111
120
  interface ResultBranch {
112
121
  branchType: ResultBranchType;
113
122
  statusCode: number;
@@ -199,4 +208,4 @@ declare function formatTag(tag: Tag): string;
199
208
  declare function formatPipelineRef(ref: PipelineRef): string[];
200
209
  declare function formatWhen(when: When): string;
201
210
 
202
- export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type GraphQLSchema, type It, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
211
+ export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchCase, type GraphQLSchema, type It, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
package/dist/index.d.ts CHANGED
@@ -99,6 +99,7 @@ type PipelineStep = {
99
99
  config: string;
100
100
  configType: ConfigType;
101
101
  tags: Tag[];
102
+ parsedJoinTargets?: string[];
102
103
  } | {
103
104
  kind: 'Result';
104
105
  branches: ResultBranch[];
@@ -107,7 +108,15 @@ type PipelineStep = {
107
108
  condition: Pipeline;
108
109
  thenBranch: Pipeline;
109
110
  elseBranch?: Pipeline;
111
+ } | {
112
+ kind: 'Dispatch';
113
+ cases: DispatchCase[];
114
+ default?: Pipeline;
110
115
  };
116
+ interface DispatchCase {
117
+ condition: Tag;
118
+ pipeline: Pipeline;
119
+ }
111
120
  interface ResultBranch {
112
121
  branchType: ResultBranchType;
113
122
  statusCode: number;
@@ -199,4 +208,4 @@ declare function formatTag(tag: Tag): string;
199
208
  declare function formatPipelineRef(ref: PipelineRef): string[];
200
209
  declare function formatWhen(when: When): string;
201
210
 
202
- export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type GraphQLSchema, type It, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
211
+ export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchCase, type GraphQLSchema, type It, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printVariable };
package/dist/index.mjs CHANGED
@@ -281,7 +281,7 @@ var Parser = class {
281
281
  return content;
282
282
  }
283
283
  parseMethod() {
284
- const methods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
284
+ const methods = ["GET", "POST", "PUT", "DELETE"];
285
285
  for (const m of methods) {
286
286
  if (this.text.startsWith(m, this.pos)) {
287
287
  this.pos += m.length;
@@ -410,8 +410,44 @@ var Parser = class {
410
410
  if (result) return result;
411
411
  const ifStep = this.tryParse(() => this.parseIfStep());
412
412
  if (ifStep) return ifStep;
413
+ const dispatchStep = this.tryParse(() => this.parseDispatchStep());
414
+ if (dispatchStep) return dispatchStep;
413
415
  return this.parseRegularStep();
414
416
  }
417
+ parseDispatchStep() {
418
+ this.skipWhitespaceOnly();
419
+ this.expect("|>");
420
+ this.skipInlineSpaces();
421
+ this.expect("dispatch");
422
+ this.skipSpaces();
423
+ const cases = [];
424
+ while (true) {
425
+ const dispatchCase = this.tryParse(() => this.parseDispatchCase());
426
+ if (!dispatchCase) break;
427
+ cases.push(dispatchCase);
428
+ }
429
+ const defaultBranch = this.tryParse(() => this.parseDispatchDefault());
430
+ return { kind: "Dispatch", cases, default: defaultBranch || void 0 };
431
+ }
432
+ parseDispatchCase() {
433
+ this.skipSpaces();
434
+ this.expect("case");
435
+ this.skipInlineSpaces();
436
+ const condition = this.parseTag();
437
+ this.skipInlineSpaces();
438
+ this.expect(":");
439
+ this.skipSpaces();
440
+ const pipeline = this.parsePipeline();
441
+ return { condition, pipeline };
442
+ }
443
+ parseDispatchDefault() {
444
+ this.skipSpaces();
445
+ this.expect("default");
446
+ this.skipInlineSpaces();
447
+ this.expect(":");
448
+ this.skipSpaces();
449
+ return this.parsePipeline();
450
+ }
415
451
  parseRegularStep() {
416
452
  this.skipWhitespaceOnly();
417
453
  this.expect("|>");
@@ -421,8 +457,31 @@ var Parser = class {
421
457
  this.skipInlineSpaces();
422
458
  const { config, configType } = this.parseStepConfig();
423
459
  const tags = this.parseTags();
460
+ const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
424
461
  this.skipWhitespaceOnly();
425
- return { kind: "Regular", name, config, configType, tags };
462
+ return { kind: "Regular", name, config, configType, tags, parsedJoinTargets };
463
+ }
464
+ /**
465
+ * Pre-parse join config into task names at parse time.
466
+ * This avoids repeated parsing in the hot path during execution.
467
+ */
468
+ parseJoinTaskNames(config) {
469
+ const trimmed = config.trim();
470
+ if (trimmed.startsWith("[")) {
471
+ try {
472
+ const names2 = JSON.parse(trimmed);
473
+ if (Array.isArray(names2) && names2.every((n) => typeof n === "string")) {
474
+ return names2;
475
+ }
476
+ } catch {
477
+ return void 0;
478
+ }
479
+ }
480
+ const names = trimmed.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
481
+ if (names.length === 0) {
482
+ return void 0;
483
+ }
484
+ return names;
426
485
  }
427
486
  parseResultStep() {
428
487
  this.skipWhitespaceOnly();
@@ -1018,6 +1077,21 @@ function formatPipelineStep(step, indent = " ") {
1018
1077
  });
1019
1078
  });
1020
1079
  return lines.join("\n");
1080
+ } else if (step.kind === "Dispatch") {
1081
+ const lines = [`${indent}|> dispatch`];
1082
+ step.cases.forEach((dispatchCase) => {
1083
+ lines.push(`${indent} case ${formatTag(dispatchCase.condition)}:`);
1084
+ dispatchCase.pipeline.steps.forEach((caseStep) => {
1085
+ lines.push(formatPipelineStep(caseStep, indent + " "));
1086
+ });
1087
+ });
1088
+ if (step.default) {
1089
+ lines.push(`${indent} default:`);
1090
+ step.default.steps.forEach((defaultStep) => {
1091
+ lines.push(formatPipelineStep(defaultStep, indent + " "));
1092
+ });
1093
+ }
1094
+ return lines.join("\n");
1021
1095
  } else {
1022
1096
  const lines = [`${indent}|> if`];
1023
1097
  step.condition.steps.forEach((condStep) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",