webpipe-js 0.1.6 → 0.1.8

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
@@ -240,11 +240,11 @@ var Parser = class {
240
240
  }
241
241
  parseStepConfig() {
242
242
  const bt = this.tryParse(() => this.parseBacktickString());
243
- if (bt !== null) return bt;
243
+ if (bt !== null) return { config: bt, configType: "backtick" };
244
244
  const dq = this.tryParse(() => this.parseQuotedString());
245
- if (dq !== null) return dq;
245
+ if (dq !== null) return { config: dq, configType: "quoted" };
246
246
  const id = this.tryParse(() => this.parseIdentifier());
247
- if (id !== null) return id;
247
+ if (id !== null) return { config: id, configType: "identifier" };
248
248
  throw new ParseFailure("step-config", this.pos);
249
249
  }
250
250
  parseConfigValue() {
@@ -316,9 +316,9 @@ var Parser = class {
316
316
  const name = this.parseIdentifier();
317
317
  this.expect(":");
318
318
  this.skipInlineSpaces();
319
- const config = this.parseStepConfig();
319
+ const { config, configType } = this.parseStepConfig();
320
320
  this.skipSpaces();
321
- return { kind: "Regular", name, config };
321
+ return { kind: "Regular", name, config, configType };
322
322
  }
323
323
  parseResultStep() {
324
324
  this.skipSpaces();
@@ -659,14 +659,6 @@ function printDescribe(describe) {
659
659
  }
660
660
  function prettyPrint(program) {
661
661
  const lines = [];
662
- program.routes.forEach((route) => {
663
- lines.push(printRoute(route));
664
- lines.push("");
665
- });
666
- program.describes.forEach((describe) => {
667
- lines.push(printDescribe(describe));
668
- lines.push("");
669
- });
670
662
  if (program.configs.length > 0) {
671
663
  lines.push("## Config");
672
664
  program.configs.forEach((config) => {
@@ -674,6 +666,10 @@ function prettyPrint(program) {
674
666
  lines.push("");
675
667
  });
676
668
  }
669
+ program.routes.forEach((route) => {
670
+ lines.push(printRoute(route));
671
+ lines.push("");
672
+ });
677
673
  program.pipelines.forEach((pipeline) => {
678
674
  lines.push(printPipeline(pipeline));
679
675
  lines.push("");
@@ -682,6 +678,10 @@ function prettyPrint(program) {
682
678
  lines.push(printVariable(variable));
683
679
  });
684
680
  if (program.variables.length > 0) lines.push("");
681
+ program.describes.forEach((describe) => {
682
+ lines.push(printDescribe(describe));
683
+ lines.push("");
684
+ });
685
685
  return lines.join("\n").trim();
686
686
  }
687
687
  function formatConfigValue(value) {
@@ -698,7 +698,7 @@ function formatConfigValue(value) {
698
698
  }
699
699
  function formatPipelineStep(step, indent = " ") {
700
700
  if (step.kind === "Regular") {
701
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config)}`;
701
+ return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
702
702
  } else {
703
703
  const lines = [`${indent}|> result`];
704
704
  step.branches.forEach((branch) => {
@@ -711,33 +711,16 @@ function formatPipelineStep(step, indent = " ") {
711
711
  return lines.join("\n");
712
712
  }
713
713
  }
714
- function formatStepConfig(config) {
715
- if (config.includes("\n") || config.includes("{") || config.includes("[") || config.includes(".") || config.includes("(")) {
716
- return `\`${config}\``;
717
- } else if (config.includes(" ")) {
718
- return `"${config}"`;
719
- } else if (isAuthStringValue(config)) {
720
- return `"${config}"`;
721
- } else {
722
- return config;
714
+ function formatStepConfig(config, configType) {
715
+ switch (configType) {
716
+ case "backtick":
717
+ return `\`${config}\``;
718
+ case "quoted":
719
+ return `"${config}"`;
720
+ case "identifier":
721
+ return config;
723
722
  }
724
723
  }
725
- function isAuthStringValue(config) {
726
- const authValues = [
727
- "login",
728
- "logout",
729
- "register",
730
- "required",
731
- "optional"
732
- ];
733
- if (authValues.includes(config)) {
734
- return true;
735
- }
736
- if (config.startsWith("type:")) {
737
- return true;
738
- }
739
- return false;
740
- }
741
724
  function formatPipelineRef(ref) {
742
725
  if (ref.kind === "Named") {
743
726
  return [` |> pipeline: ${ref.name}`];
package/dist/index.d.cts CHANGED
@@ -51,10 +51,12 @@ type PipelineRef = {
51
51
  interface Pipeline {
52
52
  steps: PipelineStep[];
53
53
  }
54
+ type ConfigType = 'backtick' | 'quoted' | 'identifier';
54
55
  type PipelineStep = {
55
56
  kind: 'Regular';
56
57
  name: string;
57
58
  config: string;
59
+ configType: ConfigType;
58
60
  } | {
59
61
  kind: 'Result';
60
62
  branches: ResultBranch[];
@@ -138,8 +140,8 @@ declare function printDescribe(describe: Describe): string;
138
140
  declare function prettyPrint(program: Program): string;
139
141
  declare function formatConfigValue(value: ConfigValue): string;
140
142
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
141
- declare function formatStepConfig(config: string): string;
143
+ declare function formatStepConfig(config: string, configType: ConfigType): string;
142
144
  declare function formatPipelineRef(ref: PipelineRef): string[];
143
145
  declare function formatWhen(when: When): string;
144
146
 
145
- export { type Condition, type Config, type ConfigProperty, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
147
+ export { type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
package/dist/index.d.ts CHANGED
@@ -51,10 +51,12 @@ type PipelineRef = {
51
51
  interface Pipeline {
52
52
  steps: PipelineStep[];
53
53
  }
54
+ type ConfigType = 'backtick' | 'quoted' | 'identifier';
54
55
  type PipelineStep = {
55
56
  kind: 'Regular';
56
57
  name: string;
57
58
  config: string;
59
+ configType: ConfigType;
58
60
  } | {
59
61
  kind: 'Result';
60
62
  branches: ResultBranch[];
@@ -138,8 +140,8 @@ declare function printDescribe(describe: Describe): string;
138
140
  declare function prettyPrint(program: Program): string;
139
141
  declare function formatConfigValue(value: ConfigValue): string;
140
142
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
141
- declare function formatStepConfig(config: string): string;
143
+ declare function formatStepConfig(config: string, configType: ConfigType): string;
142
144
  declare function formatPipelineRef(ref: PipelineRef): string[];
143
145
  declare function formatWhen(when: When): string;
144
146
 
145
- export { type Condition, type Config, type ConfigProperty, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
147
+ export { type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
package/dist/index.mjs CHANGED
@@ -197,11 +197,11 @@ var Parser = class {
197
197
  }
198
198
  parseStepConfig() {
199
199
  const bt = this.tryParse(() => this.parseBacktickString());
200
- if (bt !== null) return bt;
200
+ if (bt !== null) return { config: bt, configType: "backtick" };
201
201
  const dq = this.tryParse(() => this.parseQuotedString());
202
- if (dq !== null) return dq;
202
+ if (dq !== null) return { config: dq, configType: "quoted" };
203
203
  const id = this.tryParse(() => this.parseIdentifier());
204
- if (id !== null) return id;
204
+ if (id !== null) return { config: id, configType: "identifier" };
205
205
  throw new ParseFailure("step-config", this.pos);
206
206
  }
207
207
  parseConfigValue() {
@@ -273,9 +273,9 @@ var Parser = class {
273
273
  const name = this.parseIdentifier();
274
274
  this.expect(":");
275
275
  this.skipInlineSpaces();
276
- const config = this.parseStepConfig();
276
+ const { config, configType } = this.parseStepConfig();
277
277
  this.skipSpaces();
278
- return { kind: "Regular", name, config };
278
+ return { kind: "Regular", name, config, configType };
279
279
  }
280
280
  parseResultStep() {
281
281
  this.skipSpaces();
@@ -616,14 +616,6 @@ function printDescribe(describe) {
616
616
  }
617
617
  function prettyPrint(program) {
618
618
  const lines = [];
619
- program.routes.forEach((route) => {
620
- lines.push(printRoute(route));
621
- lines.push("");
622
- });
623
- program.describes.forEach((describe) => {
624
- lines.push(printDescribe(describe));
625
- lines.push("");
626
- });
627
619
  if (program.configs.length > 0) {
628
620
  lines.push("## Config");
629
621
  program.configs.forEach((config) => {
@@ -631,6 +623,10 @@ function prettyPrint(program) {
631
623
  lines.push("");
632
624
  });
633
625
  }
626
+ program.routes.forEach((route) => {
627
+ lines.push(printRoute(route));
628
+ lines.push("");
629
+ });
634
630
  program.pipelines.forEach((pipeline) => {
635
631
  lines.push(printPipeline(pipeline));
636
632
  lines.push("");
@@ -639,6 +635,10 @@ function prettyPrint(program) {
639
635
  lines.push(printVariable(variable));
640
636
  });
641
637
  if (program.variables.length > 0) lines.push("");
638
+ program.describes.forEach((describe) => {
639
+ lines.push(printDescribe(describe));
640
+ lines.push("");
641
+ });
642
642
  return lines.join("\n").trim();
643
643
  }
644
644
  function formatConfigValue(value) {
@@ -655,7 +655,7 @@ function formatConfigValue(value) {
655
655
  }
656
656
  function formatPipelineStep(step, indent = " ") {
657
657
  if (step.kind === "Regular") {
658
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config)}`;
658
+ return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
659
659
  } else {
660
660
  const lines = [`${indent}|> result`];
661
661
  step.branches.forEach((branch) => {
@@ -668,33 +668,16 @@ function formatPipelineStep(step, indent = " ") {
668
668
  return lines.join("\n");
669
669
  }
670
670
  }
671
- function formatStepConfig(config) {
672
- if (config.includes("\n") || config.includes("{") || config.includes("[") || config.includes(".") || config.includes("(")) {
673
- return `\`${config}\``;
674
- } else if (config.includes(" ")) {
675
- return `"${config}"`;
676
- } else if (isAuthStringValue(config)) {
677
- return `"${config}"`;
678
- } else {
679
- return config;
671
+ function formatStepConfig(config, configType) {
672
+ switch (configType) {
673
+ case "backtick":
674
+ return `\`${config}\``;
675
+ case "quoted":
676
+ return `"${config}"`;
677
+ case "identifier":
678
+ return config;
680
679
  }
681
680
  }
682
- function isAuthStringValue(config) {
683
- const authValues = [
684
- "login",
685
- "logout",
686
- "register",
687
- "required",
688
- "optional"
689
- ];
690
- if (authValues.includes(config)) {
691
- return true;
692
- }
693
- if (config.startsWith("type:")) {
694
- return true;
695
- }
696
- return false;
697
- }
698
681
  function formatPipelineRef(ref) {
699
682
  if (ref.kind === "Named") {
700
683
  return [` |> pipeline: ${ref.name}`];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",