webpipe-js 0.1.7 → 0.1.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
@@ -73,6 +73,9 @@ var Parser = class {
73
73
  while (i < this.text.length && this.text[i] !== "\n") i++;
74
74
  return i;
75
75
  }
76
+ getLineNumber(pos) {
77
+ return this.text.slice(0, pos).split("\n").length;
78
+ }
76
79
  parseProgram() {
77
80
  this.skipSpaces();
78
81
  const configs = [];
@@ -86,26 +89,31 @@ var Parser = class {
86
89
  const start = this.pos;
87
90
  const cfg = this.tryParse(() => this.parseConfig());
88
91
  if (cfg) {
92
+ cfg.lineNumber = this.getLineNumber(start);
89
93
  configs.push(cfg);
90
94
  continue;
91
95
  }
92
96
  const namedPipe = this.tryParse(() => this.parseNamedPipeline());
93
97
  if (namedPipe) {
98
+ namedPipe.lineNumber = this.getLineNumber(start);
94
99
  pipelines.push(namedPipe);
95
100
  continue;
96
101
  }
97
102
  const variable = this.tryParse(() => this.parseVariable());
98
103
  if (variable) {
104
+ variable.lineNumber = this.getLineNumber(start);
99
105
  variables.push(variable);
100
106
  continue;
101
107
  }
102
108
  const route = this.tryParse(() => this.parseRoute());
103
109
  if (route) {
110
+ route.lineNumber = this.getLineNumber(start);
104
111
  routes.push(route);
105
112
  continue;
106
113
  }
107
114
  const describe = this.tryParse(() => this.parseDescribe());
108
115
  if (describe) {
116
+ describe.lineNumber = this.getLineNumber(start);
109
117
  describes.push(describe);
110
118
  continue;
111
119
  }
@@ -240,11 +248,11 @@ var Parser = class {
240
248
  }
241
249
  parseStepConfig() {
242
250
  const bt = this.tryParse(() => this.parseBacktickString());
243
- if (bt !== null) return bt;
251
+ if (bt !== null) return { config: bt, configType: "backtick" };
244
252
  const dq = this.tryParse(() => this.parseQuotedString());
245
- if (dq !== null) return dq;
253
+ if (dq !== null) return { config: dq, configType: "quoted" };
246
254
  const id = this.tryParse(() => this.parseIdentifier());
247
- if (id !== null) return id;
255
+ if (id !== null) return { config: id, configType: "identifier" };
248
256
  throw new ParseFailure("step-config", this.pos);
249
257
  }
250
258
  parseConfigValue() {
@@ -316,9 +324,9 @@ var Parser = class {
316
324
  const name = this.parseIdentifier();
317
325
  this.expect(":");
318
326
  this.skipInlineSpaces();
319
- const config = this.parseStepConfig();
327
+ const { config, configType } = this.parseStepConfig();
320
328
  this.skipSpaces();
321
- return { kind: "Regular", name, config };
329
+ return { kind: "Regular", name, config, configType };
322
330
  }
323
331
  parseResultStep() {
324
332
  this.skipSpaces();
@@ -659,28 +667,52 @@ function printDescribe(describe) {
659
667
  }
660
668
  function prettyPrint(program) {
661
669
  const lines = [];
662
- if (program.configs.length > 0) {
663
- lines.push("## Config");
664
- program.configs.forEach((config) => {
665
- lines.push(printConfig(config));
666
- lines.push("");
667
- });
668
- }
670
+ const allItems = [];
671
+ program.configs.forEach((config) => {
672
+ allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
673
+ });
669
674
  program.routes.forEach((route) => {
670
- lines.push(printRoute(route));
671
- lines.push("");
675
+ allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
672
676
  });
673
677
  program.pipelines.forEach((pipeline) => {
674
- lines.push(printPipeline(pipeline));
675
- lines.push("");
678
+ allItems.push({ type: "pipeline", item: pipeline, lineNumber: pipeline.lineNumber || 0 });
676
679
  });
677
680
  program.variables.forEach((variable) => {
678
- lines.push(printVariable(variable));
681
+ allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
679
682
  });
680
- if (program.variables.length > 0) lines.push("");
681
683
  program.describes.forEach((describe) => {
682
- lines.push(printDescribe(describe));
683
- lines.push("");
684
+ allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
685
+ });
686
+ allItems.sort((a, b) => a.lineNumber - b.lineNumber);
687
+ let hasConfigs = false;
688
+ allItems.forEach((entry, index) => {
689
+ if (entry.type === "config" && !hasConfigs) {
690
+ lines.push("## Config");
691
+ hasConfigs = true;
692
+ }
693
+ switch (entry.type) {
694
+ case "config":
695
+ lines.push(printConfig(entry.item));
696
+ lines.push("");
697
+ break;
698
+ case "route":
699
+ lines.push(printRoute(entry.item));
700
+ lines.push("");
701
+ break;
702
+ case "pipeline":
703
+ lines.push(printPipeline(entry.item));
704
+ lines.push("");
705
+ break;
706
+ case "variable":
707
+ lines.push(printVariable(entry.item));
708
+ const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
709
+ if (nextNonVariable) lines.push("");
710
+ break;
711
+ case "describe":
712
+ lines.push(printDescribe(entry.item));
713
+ lines.push("");
714
+ break;
715
+ }
684
716
  });
685
717
  return lines.join("\n").trim();
686
718
  }
@@ -698,7 +730,7 @@ function formatConfigValue(value) {
698
730
  }
699
731
  function formatPipelineStep(step, indent = " ") {
700
732
  if (step.kind === "Regular") {
701
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config)}`;
733
+ return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
702
734
  } else {
703
735
  const lines = [`${indent}|> result`];
704
736
  step.branches.forEach((branch) => {
@@ -711,33 +743,16 @@ function formatPipelineStep(step, indent = " ") {
711
743
  return lines.join("\n");
712
744
  }
713
745
  }
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;
746
+ function formatStepConfig(config, configType) {
747
+ switch (configType) {
748
+ case "backtick":
749
+ return `\`${config}\``;
750
+ case "quoted":
751
+ return `"${config}"`;
752
+ case "identifier":
753
+ return config;
723
754
  }
724
755
  }
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
756
  function formatPipelineRef(ref) {
742
757
  if (ref.kind === "Named") {
743
758
  return [` |> pipeline: ${ref.name}`];
package/dist/index.d.cts CHANGED
@@ -8,6 +8,7 @@ interface Program {
8
8
  interface Config {
9
9
  name: string;
10
10
  properties: ConfigProperty[];
11
+ lineNumber?: number;
11
12
  }
12
13
  interface ConfigProperty {
13
14
  key: string;
@@ -30,16 +31,19 @@ type ConfigValue = {
30
31
  interface NamedPipeline {
31
32
  name: string;
32
33
  pipeline: Pipeline;
34
+ lineNumber?: number;
33
35
  }
34
36
  interface Variable {
35
37
  varType: string;
36
38
  name: string;
37
39
  value: string;
40
+ lineNumber?: number;
38
41
  }
39
42
  interface Route {
40
43
  method: string;
41
44
  path: string;
42
45
  pipeline: PipelineRef;
46
+ lineNumber?: number;
43
47
  }
44
48
  type PipelineRef = {
45
49
  kind: 'Inline';
@@ -51,10 +55,12 @@ type PipelineRef = {
51
55
  interface Pipeline {
52
56
  steps: PipelineStep[];
53
57
  }
58
+ type ConfigType = 'backtick' | 'quoted' | 'identifier';
54
59
  type PipelineStep = {
55
60
  kind: 'Regular';
56
61
  name: string;
57
62
  config: string;
63
+ configType: ConfigType;
58
64
  } | {
59
65
  kind: 'Result';
60
66
  branches: ResultBranch[];
@@ -76,6 +82,7 @@ interface Describe {
76
82
  name: string;
77
83
  mocks: Mock[];
78
84
  tests: It[];
85
+ lineNumber?: number;
79
86
  }
80
87
  interface Mock {
81
88
  target: string;
@@ -138,8 +145,8 @@ declare function printDescribe(describe: Describe): string;
138
145
  declare function prettyPrint(program: Program): string;
139
146
  declare function formatConfigValue(value: ConfigValue): string;
140
147
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
141
- declare function formatStepConfig(config: string): string;
148
+ declare function formatStepConfig(config: string, configType: ConfigType): string;
142
149
  declare function formatPipelineRef(ref: PipelineRef): string[];
143
150
  declare function formatWhen(when: When): string;
144
151
 
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 };
152
+ 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
@@ -8,6 +8,7 @@ interface Program {
8
8
  interface Config {
9
9
  name: string;
10
10
  properties: ConfigProperty[];
11
+ lineNumber?: number;
11
12
  }
12
13
  interface ConfigProperty {
13
14
  key: string;
@@ -30,16 +31,19 @@ type ConfigValue = {
30
31
  interface NamedPipeline {
31
32
  name: string;
32
33
  pipeline: Pipeline;
34
+ lineNumber?: number;
33
35
  }
34
36
  interface Variable {
35
37
  varType: string;
36
38
  name: string;
37
39
  value: string;
40
+ lineNumber?: number;
38
41
  }
39
42
  interface Route {
40
43
  method: string;
41
44
  path: string;
42
45
  pipeline: PipelineRef;
46
+ lineNumber?: number;
43
47
  }
44
48
  type PipelineRef = {
45
49
  kind: 'Inline';
@@ -51,10 +55,12 @@ type PipelineRef = {
51
55
  interface Pipeline {
52
56
  steps: PipelineStep[];
53
57
  }
58
+ type ConfigType = 'backtick' | 'quoted' | 'identifier';
54
59
  type PipelineStep = {
55
60
  kind: 'Regular';
56
61
  name: string;
57
62
  config: string;
63
+ configType: ConfigType;
58
64
  } | {
59
65
  kind: 'Result';
60
66
  branches: ResultBranch[];
@@ -76,6 +82,7 @@ interface Describe {
76
82
  name: string;
77
83
  mocks: Mock[];
78
84
  tests: It[];
85
+ lineNumber?: number;
79
86
  }
80
87
  interface Mock {
81
88
  target: string;
@@ -138,8 +145,8 @@ declare function printDescribe(describe: Describe): string;
138
145
  declare function prettyPrint(program: Program): string;
139
146
  declare function formatConfigValue(value: ConfigValue): string;
140
147
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
141
- declare function formatStepConfig(config: string): string;
148
+ declare function formatStepConfig(config: string, configType: ConfigType): string;
142
149
  declare function formatPipelineRef(ref: PipelineRef): string[];
143
150
  declare function formatWhen(when: When): string;
144
151
 
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 };
152
+ 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
@@ -30,6 +30,9 @@ var Parser = class {
30
30
  while (i < this.text.length && this.text[i] !== "\n") i++;
31
31
  return i;
32
32
  }
33
+ getLineNumber(pos) {
34
+ return this.text.slice(0, pos).split("\n").length;
35
+ }
33
36
  parseProgram() {
34
37
  this.skipSpaces();
35
38
  const configs = [];
@@ -43,26 +46,31 @@ var Parser = class {
43
46
  const start = this.pos;
44
47
  const cfg = this.tryParse(() => this.parseConfig());
45
48
  if (cfg) {
49
+ cfg.lineNumber = this.getLineNumber(start);
46
50
  configs.push(cfg);
47
51
  continue;
48
52
  }
49
53
  const namedPipe = this.tryParse(() => this.parseNamedPipeline());
50
54
  if (namedPipe) {
55
+ namedPipe.lineNumber = this.getLineNumber(start);
51
56
  pipelines.push(namedPipe);
52
57
  continue;
53
58
  }
54
59
  const variable = this.tryParse(() => this.parseVariable());
55
60
  if (variable) {
61
+ variable.lineNumber = this.getLineNumber(start);
56
62
  variables.push(variable);
57
63
  continue;
58
64
  }
59
65
  const route = this.tryParse(() => this.parseRoute());
60
66
  if (route) {
67
+ route.lineNumber = this.getLineNumber(start);
61
68
  routes.push(route);
62
69
  continue;
63
70
  }
64
71
  const describe = this.tryParse(() => this.parseDescribe());
65
72
  if (describe) {
73
+ describe.lineNumber = this.getLineNumber(start);
66
74
  describes.push(describe);
67
75
  continue;
68
76
  }
@@ -197,11 +205,11 @@ var Parser = class {
197
205
  }
198
206
  parseStepConfig() {
199
207
  const bt = this.tryParse(() => this.parseBacktickString());
200
- if (bt !== null) return bt;
208
+ if (bt !== null) return { config: bt, configType: "backtick" };
201
209
  const dq = this.tryParse(() => this.parseQuotedString());
202
- if (dq !== null) return dq;
210
+ if (dq !== null) return { config: dq, configType: "quoted" };
203
211
  const id = this.tryParse(() => this.parseIdentifier());
204
- if (id !== null) return id;
212
+ if (id !== null) return { config: id, configType: "identifier" };
205
213
  throw new ParseFailure("step-config", this.pos);
206
214
  }
207
215
  parseConfigValue() {
@@ -273,9 +281,9 @@ var Parser = class {
273
281
  const name = this.parseIdentifier();
274
282
  this.expect(":");
275
283
  this.skipInlineSpaces();
276
- const config = this.parseStepConfig();
284
+ const { config, configType } = this.parseStepConfig();
277
285
  this.skipSpaces();
278
- return { kind: "Regular", name, config };
286
+ return { kind: "Regular", name, config, configType };
279
287
  }
280
288
  parseResultStep() {
281
289
  this.skipSpaces();
@@ -616,28 +624,52 @@ function printDescribe(describe) {
616
624
  }
617
625
  function prettyPrint(program) {
618
626
  const lines = [];
619
- if (program.configs.length > 0) {
620
- lines.push("## Config");
621
- program.configs.forEach((config) => {
622
- lines.push(printConfig(config));
623
- lines.push("");
624
- });
625
- }
627
+ const allItems = [];
628
+ program.configs.forEach((config) => {
629
+ allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
630
+ });
626
631
  program.routes.forEach((route) => {
627
- lines.push(printRoute(route));
628
- lines.push("");
632
+ allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
629
633
  });
630
634
  program.pipelines.forEach((pipeline) => {
631
- lines.push(printPipeline(pipeline));
632
- lines.push("");
635
+ allItems.push({ type: "pipeline", item: pipeline, lineNumber: pipeline.lineNumber || 0 });
633
636
  });
634
637
  program.variables.forEach((variable) => {
635
- lines.push(printVariable(variable));
638
+ allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
636
639
  });
637
- if (program.variables.length > 0) lines.push("");
638
640
  program.describes.forEach((describe) => {
639
- lines.push(printDescribe(describe));
640
- lines.push("");
641
+ allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
642
+ });
643
+ allItems.sort((a, b) => a.lineNumber - b.lineNumber);
644
+ let hasConfigs = false;
645
+ allItems.forEach((entry, index) => {
646
+ if (entry.type === "config" && !hasConfigs) {
647
+ lines.push("## Config");
648
+ hasConfigs = true;
649
+ }
650
+ switch (entry.type) {
651
+ case "config":
652
+ lines.push(printConfig(entry.item));
653
+ lines.push("");
654
+ break;
655
+ case "route":
656
+ lines.push(printRoute(entry.item));
657
+ lines.push("");
658
+ break;
659
+ case "pipeline":
660
+ lines.push(printPipeline(entry.item));
661
+ lines.push("");
662
+ break;
663
+ case "variable":
664
+ lines.push(printVariable(entry.item));
665
+ const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
666
+ if (nextNonVariable) lines.push("");
667
+ break;
668
+ case "describe":
669
+ lines.push(printDescribe(entry.item));
670
+ lines.push("");
671
+ break;
672
+ }
641
673
  });
642
674
  return lines.join("\n").trim();
643
675
  }
@@ -655,7 +687,7 @@ function formatConfigValue(value) {
655
687
  }
656
688
  function formatPipelineStep(step, indent = " ") {
657
689
  if (step.kind === "Regular") {
658
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config)}`;
690
+ return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
659
691
  } else {
660
692
  const lines = [`${indent}|> result`];
661
693
  step.branches.forEach((branch) => {
@@ -668,33 +700,16 @@ function formatPipelineStep(step, indent = " ") {
668
700
  return lines.join("\n");
669
701
  }
670
702
  }
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;
703
+ function formatStepConfig(config, configType) {
704
+ switch (configType) {
705
+ case "backtick":
706
+ return `\`${config}\``;
707
+ case "quoted":
708
+ return `"${config}"`;
709
+ case "identifier":
710
+ return config;
680
711
  }
681
712
  }
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
713
  function formatPipelineRef(ref) {
699
714
  if (ref.kind === "Named") {
700
715
  return [` |> pipeline: ${ref.name}`];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",