webpipe-js 0.1.11 → 2.0.0

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
@@ -24,6 +24,8 @@ __export(index_exports, {
24
24
  formatPipelineRef: () => formatPipelineRef,
25
25
  formatPipelineStep: () => formatPipelineStep,
26
26
  formatStepConfig: () => formatStepConfig,
27
+ formatTag: () => formatTag,
28
+ formatTags: () => formatTags,
27
29
  formatWhen: () => formatWhen,
28
30
  getPipelineRanges: () => getPipelineRanges,
29
31
  getVariableRanges: () => getVariableRanges,
@@ -316,6 +318,54 @@ var Parser = class {
316
318
  if (id !== null) return { config: id, configType: "identifier" };
317
319
  throw new ParseFailure("step-config", this.pos);
318
320
  }
321
+ parseTag() {
322
+ this.expect("@");
323
+ const negated = this.cur() === "!";
324
+ if (negated) this.pos++;
325
+ const name = this.parseIdentifier();
326
+ let args = [];
327
+ if (this.cur() === "(") {
328
+ args = this.parseTagArgs();
329
+ }
330
+ return { name, negated, args };
331
+ }
332
+ parseTagArgs() {
333
+ this.expect("(");
334
+ const args = [];
335
+ this.skipInlineSpaces();
336
+ if (this.cur() === ")") {
337
+ throw new ParseFailure("empty tag arguments not allowed", this.pos);
338
+ }
339
+ args.push(this.parseIdentifier());
340
+ this.skipInlineSpaces();
341
+ while (this.cur() === ",") {
342
+ this.pos++;
343
+ this.skipInlineSpaces();
344
+ if (this.cur() === ")") {
345
+ throw new ParseFailure("trailing comma in tag arguments", this.pos);
346
+ }
347
+ args.push(this.parseIdentifier());
348
+ this.skipInlineSpaces();
349
+ }
350
+ this.expect(")");
351
+ return args;
352
+ }
353
+ parseTags() {
354
+ const tags = [];
355
+ while (!this.eof()) {
356
+ this.skipInlineSpaces();
357
+ const ch = this.cur();
358
+ if (ch === "\n" || ch === "\r" || ch === "#" || this.text.startsWith("//", this.pos)) {
359
+ break;
360
+ }
361
+ if (ch === "@") {
362
+ tags.push(this.parseTag());
363
+ } else {
364
+ break;
365
+ }
366
+ }
367
+ return tags;
368
+ }
319
369
  parseConfigValue() {
320
370
  const envWithDefault = this.tryParse(() => {
321
371
  this.expect("$");
@@ -387,8 +437,9 @@ var Parser = class {
387
437
  this.expect(":");
388
438
  this.skipInlineSpaces();
389
439
  const { config, configType } = this.parseStepConfig();
440
+ const tags = this.parseTags();
390
441
  this.skipWhitespaceOnly();
391
- return { kind: "Regular", name, config, configType };
442
+ return { kind: "Regular", name, config, configType, tags };
392
443
  }
393
444
  parseResultStep() {
394
445
  this.skipWhitespaceOnly();
@@ -786,12 +837,7 @@ function prettyPrint(program) {
786
837
  allItems.push({ type: "comment", item: comment, lineNumber: comment.lineNumber || 0 });
787
838
  });
788
839
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
789
- let hasConfigs = false;
790
840
  allItems.forEach((entry, index) => {
791
- if (entry.type === "config" && !hasConfigs) {
792
- lines.push("## Config");
793
- hasConfigs = true;
794
- }
795
841
  switch (entry.type) {
796
842
  case "comment":
797
843
  lines.push(printComment(entry.item));
@@ -835,7 +881,9 @@ function formatConfigValue(value) {
835
881
  }
836
882
  function formatPipelineStep(step, indent = " ") {
837
883
  if (step.kind === "Regular") {
838
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
884
+ const configPart = formatStepConfig(step.config, step.configType);
885
+ const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
886
+ return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
839
887
  } else {
840
888
  const lines = [`${indent}|> result`];
841
889
  step.branches.forEach((branch) => {
@@ -858,6 +906,14 @@ function formatStepConfig(config, configType) {
858
906
  return config;
859
907
  }
860
908
  }
909
+ function formatTags(tags) {
910
+ return tags.map(formatTag).join(" ");
911
+ }
912
+ function formatTag(tag) {
913
+ const negation = tag.negated ? "!" : "";
914
+ const args = tag.args.length > 0 ? `(${tag.args.join(",")})` : "";
915
+ return `@${negation}${tag.name}${args}`;
916
+ }
861
917
  function formatPipelineRef(ref) {
862
918
  if (ref.kind === "Named") {
863
919
  return [` |> pipeline: ${ref.name}`];
@@ -885,6 +941,8 @@ function formatWhen(when) {
885
941
  formatPipelineRef,
886
942
  formatPipelineStep,
887
943
  formatStepConfig,
944
+ formatTag,
945
+ formatTags,
888
946
  formatWhen,
889
947
  getPipelineRanges,
890
948
  getVariableRanges,
package/dist/index.d.cts CHANGED
@@ -67,11 +67,17 @@ interface Pipeline {
67
67
  steps: PipelineStep[];
68
68
  }
69
69
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
70
+ interface Tag {
71
+ name: string;
72
+ negated: boolean;
73
+ args: string[];
74
+ }
70
75
  type PipelineStep = {
71
76
  kind: 'Regular';
72
77
  name: string;
73
78
  config: string;
74
79
  configType: ConfigType;
80
+ tags: Tag[];
75
81
  } | {
76
82
  kind: 'Result';
77
83
  branches: ResultBranch[];
@@ -159,7 +165,9 @@ declare function prettyPrint(program: Program): string;
159
165
  declare function formatConfigValue(value: ConfigValue): string;
160
166
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
161
167
  declare function formatStepConfig(config: string, configType: ConfigType): string;
168
+ declare function formatTags(tags: Tag[]): string;
169
+ declare function formatTag(tag: Tag): string;
162
170
  declare function formatPipelineRef(ref: PipelineRef): string[];
163
171
  declare function formatWhen(when: When): string;
164
172
 
165
- export { type Comment, 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, printComment, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
173
+ export { type Comment, 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 Tag, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
package/dist/index.d.ts CHANGED
@@ -67,11 +67,17 @@ interface Pipeline {
67
67
  steps: PipelineStep[];
68
68
  }
69
69
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
70
+ interface Tag {
71
+ name: string;
72
+ negated: boolean;
73
+ args: string[];
74
+ }
70
75
  type PipelineStep = {
71
76
  kind: 'Regular';
72
77
  name: string;
73
78
  config: string;
74
79
  configType: ConfigType;
80
+ tags: Tag[];
75
81
  } | {
76
82
  kind: 'Result';
77
83
  branches: ResultBranch[];
@@ -159,7 +165,9 @@ declare function prettyPrint(program: Program): string;
159
165
  declare function formatConfigValue(value: ConfigValue): string;
160
166
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
161
167
  declare function formatStepConfig(config: string, configType: ConfigType): string;
168
+ declare function formatTags(tags: Tag[]): string;
169
+ declare function formatTag(tag: Tag): string;
162
170
  declare function formatPipelineRef(ref: PipelineRef): string[];
163
171
  declare function formatWhen(when: When): string;
164
172
 
165
- export { type Comment, 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, printComment, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
173
+ export { type Comment, 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 Tag, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTags, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
package/dist/index.mjs CHANGED
@@ -272,6 +272,54 @@ var Parser = class {
272
272
  if (id !== null) return { config: id, configType: "identifier" };
273
273
  throw new ParseFailure("step-config", this.pos);
274
274
  }
275
+ parseTag() {
276
+ this.expect("@");
277
+ const negated = this.cur() === "!";
278
+ if (negated) this.pos++;
279
+ const name = this.parseIdentifier();
280
+ let args = [];
281
+ if (this.cur() === "(") {
282
+ args = this.parseTagArgs();
283
+ }
284
+ return { name, negated, args };
285
+ }
286
+ parseTagArgs() {
287
+ this.expect("(");
288
+ const args = [];
289
+ this.skipInlineSpaces();
290
+ if (this.cur() === ")") {
291
+ throw new ParseFailure("empty tag arguments not allowed", this.pos);
292
+ }
293
+ args.push(this.parseIdentifier());
294
+ this.skipInlineSpaces();
295
+ while (this.cur() === ",") {
296
+ this.pos++;
297
+ this.skipInlineSpaces();
298
+ if (this.cur() === ")") {
299
+ throw new ParseFailure("trailing comma in tag arguments", this.pos);
300
+ }
301
+ args.push(this.parseIdentifier());
302
+ this.skipInlineSpaces();
303
+ }
304
+ this.expect(")");
305
+ return args;
306
+ }
307
+ parseTags() {
308
+ const tags = [];
309
+ while (!this.eof()) {
310
+ this.skipInlineSpaces();
311
+ const ch = this.cur();
312
+ if (ch === "\n" || ch === "\r" || ch === "#" || this.text.startsWith("//", this.pos)) {
313
+ break;
314
+ }
315
+ if (ch === "@") {
316
+ tags.push(this.parseTag());
317
+ } else {
318
+ break;
319
+ }
320
+ }
321
+ return tags;
322
+ }
275
323
  parseConfigValue() {
276
324
  const envWithDefault = this.tryParse(() => {
277
325
  this.expect("$");
@@ -343,8 +391,9 @@ var Parser = class {
343
391
  this.expect(":");
344
392
  this.skipInlineSpaces();
345
393
  const { config, configType } = this.parseStepConfig();
394
+ const tags = this.parseTags();
346
395
  this.skipWhitespaceOnly();
347
- return { kind: "Regular", name, config, configType };
396
+ return { kind: "Regular", name, config, configType, tags };
348
397
  }
349
398
  parseResultStep() {
350
399
  this.skipWhitespaceOnly();
@@ -742,12 +791,7 @@ function prettyPrint(program) {
742
791
  allItems.push({ type: "comment", item: comment, lineNumber: comment.lineNumber || 0 });
743
792
  });
744
793
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
745
- let hasConfigs = false;
746
794
  allItems.forEach((entry, index) => {
747
- if (entry.type === "config" && !hasConfigs) {
748
- lines.push("## Config");
749
- hasConfigs = true;
750
- }
751
795
  switch (entry.type) {
752
796
  case "comment":
753
797
  lines.push(printComment(entry.item));
@@ -791,7 +835,9 @@ function formatConfigValue(value) {
791
835
  }
792
836
  function formatPipelineStep(step, indent = " ") {
793
837
  if (step.kind === "Regular") {
794
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
838
+ const configPart = formatStepConfig(step.config, step.configType);
839
+ const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
840
+ return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
795
841
  } else {
796
842
  const lines = [`${indent}|> result`];
797
843
  step.branches.forEach((branch) => {
@@ -814,6 +860,14 @@ function formatStepConfig(config, configType) {
814
860
  return config;
815
861
  }
816
862
  }
863
+ function formatTags(tags) {
864
+ return tags.map(formatTag).join(" ");
865
+ }
866
+ function formatTag(tag) {
867
+ const negation = tag.negated ? "!" : "";
868
+ const args = tag.args.length > 0 ? `(${tag.args.join(",")})` : "";
869
+ return `@${negation}${tag.name}${args}`;
870
+ }
817
871
  function formatPipelineRef(ref) {
818
872
  if (ref.kind === "Named") {
819
873
  return [` |> pipeline: ${ref.name}`];
@@ -840,6 +894,8 @@ export {
840
894
  formatPipelineRef,
841
895
  formatPipelineStep,
842
896
  formatStepConfig,
897
+ formatTag,
898
+ formatTags,
843
899
  formatWhen,
844
900
  getPipelineRanges,
845
901
  getVariableRanges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "0.1.11",
3
+ "version": "2.0.0",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",