webpipe-js 0.1.12 → 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();
@@ -830,7 +881,9 @@ function formatConfigValue(value) {
830
881
  }
831
882
  function formatPipelineStep(step, indent = " ") {
832
883
  if (step.kind === "Regular") {
833
- 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}`;
834
887
  } else {
835
888
  const lines = [`${indent}|> result`];
836
889
  step.branches.forEach((branch) => {
@@ -853,6 +906,14 @@ function formatStepConfig(config, configType) {
853
906
  return config;
854
907
  }
855
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
+ }
856
917
  function formatPipelineRef(ref) {
857
918
  if (ref.kind === "Named") {
858
919
  return [` |> pipeline: ${ref.name}`];
@@ -880,6 +941,8 @@ function formatWhen(when) {
880
941
  formatPipelineRef,
881
942
  formatPipelineStep,
882
943
  formatStepConfig,
944
+ formatTag,
945
+ formatTags,
883
946
  formatWhen,
884
947
  getPipelineRanges,
885
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();
@@ -786,7 +835,9 @@ function formatConfigValue(value) {
786
835
  }
787
836
  function formatPipelineStep(step, indent = " ") {
788
837
  if (step.kind === "Regular") {
789
- 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}`;
790
841
  } else {
791
842
  const lines = [`${indent}|> result`];
792
843
  step.branches.forEach((branch) => {
@@ -809,6 +860,14 @@ function formatStepConfig(config, configType) {
809
860
  return config;
810
861
  }
811
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
+ }
812
871
  function formatPipelineRef(ref) {
813
872
  if (ref.kind === "Named") {
814
873
  return [` |> pipeline: ${ref.name}`];
@@ -835,6 +894,8 @@ export {
835
894
  formatPipelineRef,
836
895
  formatPipelineStep,
837
896
  formatStepConfig,
897
+ formatTag,
898
+ formatTags,
838
899
  formatWhen,
839
900
  getPipelineRanges,
840
901
  getVariableRanges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "0.1.12",
3
+ "version": "2.0.0",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",