webpipe-js 0.1.12 → 2.0.1

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,
@@ -34,8 +36,11 @@ __export(index_exports, {
34
36
  printCondition: () => printCondition,
35
37
  printConfig: () => printConfig,
36
38
  printDescribe: () => printDescribe,
39
+ printGraphQLSchema: () => printGraphQLSchema,
37
40
  printMock: () => printMock,
41
+ printMutationResolver: () => printMutationResolver,
38
42
  printPipeline: () => printPipeline,
43
+ printQueryResolver: () => printQueryResolver,
39
44
  printRoute: () => printRoute,
40
45
  printTest: () => printTest,
41
46
  printVariable: () => printVariable
@@ -135,6 +140,9 @@ var Parser = class {
135
140
  const routes = [];
136
141
  const describes = [];
137
142
  const comments = [];
143
+ let graphqlSchema;
144
+ const queries = [];
145
+ const mutations = [];
138
146
  while (!this.eof()) {
139
147
  this.skipWhitespaceOnly();
140
148
  if (this.eof()) break;
@@ -151,6 +159,24 @@ var Parser = class {
151
159
  configs.push(cfg);
152
160
  continue;
153
161
  }
162
+ const schema = this.tryParse(() => this.parseGraphQLSchema());
163
+ if (schema) {
164
+ schema.lineNumber = this.getLineNumber(start);
165
+ graphqlSchema = schema;
166
+ continue;
167
+ }
168
+ const query = this.tryParse(() => this.parseQueryResolver());
169
+ if (query) {
170
+ query.lineNumber = this.getLineNumber(start);
171
+ queries.push(query);
172
+ continue;
173
+ }
174
+ const mutation = this.tryParse(() => this.parseMutationResolver());
175
+ if (mutation) {
176
+ mutation.lineNumber = this.getLineNumber(start);
177
+ mutations.push(mutation);
178
+ continue;
179
+ }
154
180
  const namedPipe = this.tryParse(() => this.parseNamedPipeline());
155
181
  if (namedPipe) {
156
182
  namedPipe.lineNumber = this.getLineNumber(start);
@@ -190,7 +216,7 @@ var Parser = class {
190
216
  const start = Math.max(0, idx);
191
217
  this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
192
218
  }
193
- return { configs, pipelines, variables, routes, describes, comments };
219
+ return { configs, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations };
194
220
  }
195
221
  eof() {
196
222
  return this.pos >= this.len;
@@ -316,6 +342,54 @@ var Parser = class {
316
342
  if (id !== null) return { config: id, configType: "identifier" };
317
343
  throw new ParseFailure("step-config", this.pos);
318
344
  }
345
+ parseTag() {
346
+ this.expect("@");
347
+ const negated = this.cur() === "!";
348
+ if (negated) this.pos++;
349
+ const name = this.parseIdentifier();
350
+ let args = [];
351
+ if (this.cur() === "(") {
352
+ args = this.parseTagArgs();
353
+ }
354
+ return { name, negated, args };
355
+ }
356
+ parseTagArgs() {
357
+ this.expect("(");
358
+ const args = [];
359
+ this.skipInlineSpaces();
360
+ if (this.cur() === ")") {
361
+ throw new ParseFailure("empty tag arguments not allowed", this.pos);
362
+ }
363
+ args.push(this.parseIdentifier());
364
+ this.skipInlineSpaces();
365
+ while (this.cur() === ",") {
366
+ this.pos++;
367
+ this.skipInlineSpaces();
368
+ if (this.cur() === ")") {
369
+ throw new ParseFailure("trailing comma in tag arguments", this.pos);
370
+ }
371
+ args.push(this.parseIdentifier());
372
+ this.skipInlineSpaces();
373
+ }
374
+ this.expect(")");
375
+ return args;
376
+ }
377
+ parseTags() {
378
+ const tags = [];
379
+ while (!this.eof()) {
380
+ this.skipInlineSpaces();
381
+ const ch = this.cur();
382
+ if (ch === "\n" || ch === "\r" || ch === "#" || this.text.startsWith("//", this.pos)) {
383
+ break;
384
+ }
385
+ if (ch === "@") {
386
+ tags.push(this.parseTag());
387
+ } else {
388
+ break;
389
+ }
390
+ }
391
+ return tags;
392
+ }
319
393
  parseConfigValue() {
320
394
  const envWithDefault = this.tryParse(() => {
321
395
  this.expect("$");
@@ -387,8 +461,9 @@ var Parser = class {
387
461
  this.expect(":");
388
462
  this.skipInlineSpaces();
389
463
  const { config, configType } = this.parseStepConfig();
464
+ const tags = this.parseTags();
390
465
  this.skipWhitespaceOnly();
391
- return { kind: "Regular", name, config, configType };
466
+ return { kind: "Regular", name, config, configType, tags };
392
467
  }
393
468
  parseResultStep() {
394
469
  this.skipWhitespaceOnly();
@@ -487,6 +562,42 @@ var Parser = class {
487
562
  this.skipWhitespaceOnly();
488
563
  return { varType, name, value, inlineComment: inlineComment || void 0 };
489
564
  }
565
+ parseGraphQLSchema() {
566
+ this.expect("graphql");
567
+ this.skipInlineSpaces();
568
+ this.expect("schema");
569
+ this.skipInlineSpaces();
570
+ this.expect("=");
571
+ const inlineComment = this.parseInlineComment();
572
+ this.skipInlineSpaces();
573
+ const sdl = this.parseBacktickString();
574
+ this.skipWhitespaceOnly();
575
+ return { sdl, inlineComment: inlineComment || void 0 };
576
+ }
577
+ parseQueryResolver() {
578
+ this.expect("query");
579
+ this.skipInlineSpaces();
580
+ const name = this.parseIdentifier();
581
+ this.skipInlineSpaces();
582
+ this.expect("=");
583
+ const inlineComment = this.parseInlineComment();
584
+ this.skipWhitespaceOnly();
585
+ const pipeline = this.parsePipeline();
586
+ this.skipWhitespaceOnly();
587
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
588
+ }
589
+ parseMutationResolver() {
590
+ this.expect("mutation");
591
+ this.skipInlineSpaces();
592
+ const name = this.parseIdentifier();
593
+ this.skipInlineSpaces();
594
+ this.expect("=");
595
+ const inlineComment = this.parseInlineComment();
596
+ this.skipWhitespaceOnly();
597
+ const pipeline = this.parsePipeline();
598
+ this.skipWhitespaceOnly();
599
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
600
+ }
490
601
  parseRoute() {
491
602
  const method = this.parseMethod();
492
603
  this.skipInlineSpaces();
@@ -711,6 +822,39 @@ function printVariable(variable) {
711
822
  }
712
823
  return variableLine;
713
824
  }
825
+ function printGraphQLSchema(schema) {
826
+ const schemaLine = `graphql schema = \`${schema.sdl}\``;
827
+ if (schema.inlineComment) {
828
+ return `${schemaLine} ${printComment(schema.inlineComment)}`;
829
+ }
830
+ return schemaLine;
831
+ }
832
+ function printQueryResolver(query) {
833
+ const lines = [];
834
+ const queryLine = `query ${query.name} =`;
835
+ if (query.inlineComment) {
836
+ lines.push(`${queryLine} ${printComment(query.inlineComment)}`);
837
+ } else {
838
+ lines.push(queryLine);
839
+ }
840
+ query.pipeline.steps.forEach((step) => {
841
+ lines.push(formatPipelineStep(step));
842
+ });
843
+ return lines.join("\n");
844
+ }
845
+ function printMutationResolver(mutation) {
846
+ const lines = [];
847
+ const mutationLine = `mutation ${mutation.name} =`;
848
+ if (mutation.inlineComment) {
849
+ lines.push(`${mutationLine} ${printComment(mutation.inlineComment)}`);
850
+ } else {
851
+ lines.push(mutationLine);
852
+ }
853
+ mutation.pipeline.steps.forEach((step) => {
854
+ lines.push(formatPipelineStep(step));
855
+ });
856
+ return lines.join("\n");
857
+ }
714
858
  function printMock(mock, indent = " ") {
715
859
  return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
716
860
  }
@@ -770,6 +914,15 @@ function prettyPrint(program) {
770
914
  program.configs.forEach((config) => {
771
915
  allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
772
916
  });
917
+ if (program.graphqlSchema) {
918
+ allItems.push({ type: "graphqlSchema", item: program.graphqlSchema, lineNumber: program.graphqlSchema.lineNumber || 0 });
919
+ }
920
+ program.queries.forEach((query) => {
921
+ allItems.push({ type: "query", item: query, lineNumber: query.lineNumber || 0 });
922
+ });
923
+ program.mutations.forEach((mutation) => {
924
+ allItems.push({ type: "mutation", item: mutation, lineNumber: mutation.lineNumber || 0 });
925
+ });
773
926
  program.routes.forEach((route) => {
774
927
  allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
775
928
  });
@@ -795,6 +948,18 @@ function prettyPrint(program) {
795
948
  lines.push(printConfig(entry.item));
796
949
  lines.push("");
797
950
  break;
951
+ case "graphqlSchema":
952
+ lines.push(printGraphQLSchema(entry.item));
953
+ lines.push("");
954
+ break;
955
+ case "query":
956
+ lines.push(printQueryResolver(entry.item));
957
+ lines.push("");
958
+ break;
959
+ case "mutation":
960
+ lines.push(printMutationResolver(entry.item));
961
+ lines.push("");
962
+ break;
798
963
  case "route":
799
964
  lines.push(printRoute(entry.item));
800
965
  lines.push("");
@@ -830,7 +995,9 @@ function formatConfigValue(value) {
830
995
  }
831
996
  function formatPipelineStep(step, indent = " ") {
832
997
  if (step.kind === "Regular") {
833
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
998
+ const configPart = formatStepConfig(step.config, step.configType);
999
+ const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
1000
+ return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
834
1001
  } else {
835
1002
  const lines = [`${indent}|> result`];
836
1003
  step.branches.forEach((branch) => {
@@ -853,6 +1020,14 @@ function formatStepConfig(config, configType) {
853
1020
  return config;
854
1021
  }
855
1022
  }
1023
+ function formatTags(tags) {
1024
+ return tags.map(formatTag).join(" ");
1025
+ }
1026
+ function formatTag(tag) {
1027
+ const negation = tag.negated ? "!" : "";
1028
+ const args = tag.args.length > 0 ? `(${tag.args.join(",")})` : "";
1029
+ return `@${negation}${tag.name}${args}`;
1030
+ }
856
1031
  function formatPipelineRef(ref) {
857
1032
  if (ref.kind === "Named") {
858
1033
  return [` |> pipeline: ${ref.name}`];
@@ -880,6 +1055,8 @@ function formatWhen(when) {
880
1055
  formatPipelineRef,
881
1056
  formatPipelineStep,
882
1057
  formatStepConfig,
1058
+ formatTag,
1059
+ formatTags,
883
1060
  formatWhen,
884
1061
  getPipelineRanges,
885
1062
  getVariableRanges,
@@ -890,8 +1067,11 @@ function formatWhen(when) {
890
1067
  printCondition,
891
1068
  printConfig,
892
1069
  printDescribe,
1070
+ printGraphQLSchema,
893
1071
  printMock,
1072
+ printMutationResolver,
894
1073
  printPipeline,
1074
+ printQueryResolver,
895
1075
  printRoute,
896
1076
  printTest,
897
1077
  printVariable
package/dist/index.d.cts CHANGED
@@ -5,6 +5,9 @@ interface Program {
5
5
  routes: Route[];
6
6
  describes: Describe[];
7
7
  comments: Comment[];
8
+ graphqlSchema?: GraphQLSchema;
9
+ queries: QueryResolver[];
10
+ mutations: MutationResolver[];
8
11
  }
9
12
  interface Comment {
10
13
  type: 'standalone' | 'inline';
@@ -49,6 +52,23 @@ interface Variable {
49
52
  lineNumber?: number;
50
53
  inlineComment?: Comment;
51
54
  }
55
+ interface GraphQLSchema {
56
+ sdl: string;
57
+ lineNumber?: number;
58
+ inlineComment?: Comment;
59
+ }
60
+ interface QueryResolver {
61
+ name: string;
62
+ pipeline: Pipeline;
63
+ lineNumber?: number;
64
+ inlineComment?: Comment;
65
+ }
66
+ interface MutationResolver {
67
+ name: string;
68
+ pipeline: Pipeline;
69
+ lineNumber?: number;
70
+ inlineComment?: Comment;
71
+ }
52
72
  interface Route {
53
73
  method: string;
54
74
  path: string;
@@ -67,11 +87,17 @@ interface Pipeline {
67
87
  steps: PipelineStep[];
68
88
  }
69
89
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
90
+ interface Tag {
91
+ name: string;
92
+ negated: boolean;
93
+ args: string[];
94
+ }
70
95
  type PipelineStep = {
71
96
  kind: 'Regular';
72
97
  name: string;
73
98
  config: string;
74
99
  configType: ConfigType;
100
+ tags: Tag[];
75
101
  } | {
76
102
  kind: 'Result';
77
103
  branches: ResultBranch[];
@@ -150,6 +176,9 @@ declare function printRoute(route: Route): string;
150
176
  declare function printConfig(config: Config): string;
151
177
  declare function printPipeline(pipeline: NamedPipeline): string;
152
178
  declare function printVariable(variable: Variable): string;
179
+ declare function printGraphQLSchema(schema: GraphQLSchema): string;
180
+ declare function printQueryResolver(query: QueryResolver): string;
181
+ declare function printMutationResolver(mutation: MutationResolver): string;
153
182
  declare function printMock(mock: Mock, indent?: string): string;
154
183
  declare function printCondition(condition: Condition, indent?: string): string;
155
184
  declare function printTest(test: It): string;
@@ -159,7 +188,9 @@ declare function prettyPrint(program: Program): string;
159
188
  declare function formatConfigValue(value: ConfigValue): string;
160
189
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
161
190
  declare function formatStepConfig(config: string, configType: ConfigType): string;
191
+ declare function formatTags(tags: Tag[]): string;
192
+ declare function formatTag(tag: Tag): string;
162
193
  declare function formatPipelineRef(ref: PipelineRef): string[];
163
194
  declare function formatWhen(when: When): string;
164
195
 
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 };
196
+ 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 };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,9 @@ interface Program {
5
5
  routes: Route[];
6
6
  describes: Describe[];
7
7
  comments: Comment[];
8
+ graphqlSchema?: GraphQLSchema;
9
+ queries: QueryResolver[];
10
+ mutations: MutationResolver[];
8
11
  }
9
12
  interface Comment {
10
13
  type: 'standalone' | 'inline';
@@ -49,6 +52,23 @@ interface Variable {
49
52
  lineNumber?: number;
50
53
  inlineComment?: Comment;
51
54
  }
55
+ interface GraphQLSchema {
56
+ sdl: string;
57
+ lineNumber?: number;
58
+ inlineComment?: Comment;
59
+ }
60
+ interface QueryResolver {
61
+ name: string;
62
+ pipeline: Pipeline;
63
+ lineNumber?: number;
64
+ inlineComment?: Comment;
65
+ }
66
+ interface MutationResolver {
67
+ name: string;
68
+ pipeline: Pipeline;
69
+ lineNumber?: number;
70
+ inlineComment?: Comment;
71
+ }
52
72
  interface Route {
53
73
  method: string;
54
74
  path: string;
@@ -67,11 +87,17 @@ interface Pipeline {
67
87
  steps: PipelineStep[];
68
88
  }
69
89
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
90
+ interface Tag {
91
+ name: string;
92
+ negated: boolean;
93
+ args: string[];
94
+ }
70
95
  type PipelineStep = {
71
96
  kind: 'Regular';
72
97
  name: string;
73
98
  config: string;
74
99
  configType: ConfigType;
100
+ tags: Tag[];
75
101
  } | {
76
102
  kind: 'Result';
77
103
  branches: ResultBranch[];
@@ -150,6 +176,9 @@ declare function printRoute(route: Route): string;
150
176
  declare function printConfig(config: Config): string;
151
177
  declare function printPipeline(pipeline: NamedPipeline): string;
152
178
  declare function printVariable(variable: Variable): string;
179
+ declare function printGraphQLSchema(schema: GraphQLSchema): string;
180
+ declare function printQueryResolver(query: QueryResolver): string;
181
+ declare function printMutationResolver(mutation: MutationResolver): string;
153
182
  declare function printMock(mock: Mock, indent?: string): string;
154
183
  declare function printCondition(condition: Condition, indent?: string): string;
155
184
  declare function printTest(test: It): string;
@@ -159,7 +188,9 @@ declare function prettyPrint(program: Program): string;
159
188
  declare function formatConfigValue(value: ConfigValue): string;
160
189
  declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
161
190
  declare function formatStepConfig(config: string, configType: ConfigType): string;
191
+ declare function formatTags(tags: Tag[]): string;
192
+ declare function formatTag(tag: Tag): string;
162
193
  declare function formatPipelineRef(ref: PipelineRef): string[];
163
194
  declare function formatWhen(when: When): string;
164
195
 
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 };
196
+ 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 };
package/dist/index.mjs CHANGED
@@ -91,6 +91,9 @@ var Parser = class {
91
91
  const routes = [];
92
92
  const describes = [];
93
93
  const comments = [];
94
+ let graphqlSchema;
95
+ const queries = [];
96
+ const mutations = [];
94
97
  while (!this.eof()) {
95
98
  this.skipWhitespaceOnly();
96
99
  if (this.eof()) break;
@@ -107,6 +110,24 @@ var Parser = class {
107
110
  configs.push(cfg);
108
111
  continue;
109
112
  }
113
+ const schema = this.tryParse(() => this.parseGraphQLSchema());
114
+ if (schema) {
115
+ schema.lineNumber = this.getLineNumber(start);
116
+ graphqlSchema = schema;
117
+ continue;
118
+ }
119
+ const query = this.tryParse(() => this.parseQueryResolver());
120
+ if (query) {
121
+ query.lineNumber = this.getLineNumber(start);
122
+ queries.push(query);
123
+ continue;
124
+ }
125
+ const mutation = this.tryParse(() => this.parseMutationResolver());
126
+ if (mutation) {
127
+ mutation.lineNumber = this.getLineNumber(start);
128
+ mutations.push(mutation);
129
+ continue;
130
+ }
110
131
  const namedPipe = this.tryParse(() => this.parseNamedPipeline());
111
132
  if (namedPipe) {
112
133
  namedPipe.lineNumber = this.getLineNumber(start);
@@ -146,7 +167,7 @@ var Parser = class {
146
167
  const start = Math.max(0, idx);
147
168
  this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
148
169
  }
149
- return { configs, pipelines, variables, routes, describes, comments };
170
+ return { configs, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations };
150
171
  }
151
172
  eof() {
152
173
  return this.pos >= this.len;
@@ -272,6 +293,54 @@ var Parser = class {
272
293
  if (id !== null) return { config: id, configType: "identifier" };
273
294
  throw new ParseFailure("step-config", this.pos);
274
295
  }
296
+ parseTag() {
297
+ this.expect("@");
298
+ const negated = this.cur() === "!";
299
+ if (negated) this.pos++;
300
+ const name = this.parseIdentifier();
301
+ let args = [];
302
+ if (this.cur() === "(") {
303
+ args = this.parseTagArgs();
304
+ }
305
+ return { name, negated, args };
306
+ }
307
+ parseTagArgs() {
308
+ this.expect("(");
309
+ const args = [];
310
+ this.skipInlineSpaces();
311
+ if (this.cur() === ")") {
312
+ throw new ParseFailure("empty tag arguments not allowed", this.pos);
313
+ }
314
+ args.push(this.parseIdentifier());
315
+ this.skipInlineSpaces();
316
+ while (this.cur() === ",") {
317
+ this.pos++;
318
+ this.skipInlineSpaces();
319
+ if (this.cur() === ")") {
320
+ throw new ParseFailure("trailing comma in tag arguments", this.pos);
321
+ }
322
+ args.push(this.parseIdentifier());
323
+ this.skipInlineSpaces();
324
+ }
325
+ this.expect(")");
326
+ return args;
327
+ }
328
+ parseTags() {
329
+ const tags = [];
330
+ while (!this.eof()) {
331
+ this.skipInlineSpaces();
332
+ const ch = this.cur();
333
+ if (ch === "\n" || ch === "\r" || ch === "#" || this.text.startsWith("//", this.pos)) {
334
+ break;
335
+ }
336
+ if (ch === "@") {
337
+ tags.push(this.parseTag());
338
+ } else {
339
+ break;
340
+ }
341
+ }
342
+ return tags;
343
+ }
275
344
  parseConfigValue() {
276
345
  const envWithDefault = this.tryParse(() => {
277
346
  this.expect("$");
@@ -343,8 +412,9 @@ var Parser = class {
343
412
  this.expect(":");
344
413
  this.skipInlineSpaces();
345
414
  const { config, configType } = this.parseStepConfig();
415
+ const tags = this.parseTags();
346
416
  this.skipWhitespaceOnly();
347
- return { kind: "Regular", name, config, configType };
417
+ return { kind: "Regular", name, config, configType, tags };
348
418
  }
349
419
  parseResultStep() {
350
420
  this.skipWhitespaceOnly();
@@ -443,6 +513,42 @@ var Parser = class {
443
513
  this.skipWhitespaceOnly();
444
514
  return { varType, name, value, inlineComment: inlineComment || void 0 };
445
515
  }
516
+ parseGraphQLSchema() {
517
+ this.expect("graphql");
518
+ this.skipInlineSpaces();
519
+ this.expect("schema");
520
+ this.skipInlineSpaces();
521
+ this.expect("=");
522
+ const inlineComment = this.parseInlineComment();
523
+ this.skipInlineSpaces();
524
+ const sdl = this.parseBacktickString();
525
+ this.skipWhitespaceOnly();
526
+ return { sdl, inlineComment: inlineComment || void 0 };
527
+ }
528
+ parseQueryResolver() {
529
+ this.expect("query");
530
+ this.skipInlineSpaces();
531
+ const name = this.parseIdentifier();
532
+ this.skipInlineSpaces();
533
+ this.expect("=");
534
+ const inlineComment = this.parseInlineComment();
535
+ this.skipWhitespaceOnly();
536
+ const pipeline = this.parsePipeline();
537
+ this.skipWhitespaceOnly();
538
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
539
+ }
540
+ parseMutationResolver() {
541
+ this.expect("mutation");
542
+ this.skipInlineSpaces();
543
+ const name = this.parseIdentifier();
544
+ this.skipInlineSpaces();
545
+ this.expect("=");
546
+ const inlineComment = this.parseInlineComment();
547
+ this.skipWhitespaceOnly();
548
+ const pipeline = this.parsePipeline();
549
+ this.skipWhitespaceOnly();
550
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
551
+ }
446
552
  parseRoute() {
447
553
  const method = this.parseMethod();
448
554
  this.skipInlineSpaces();
@@ -667,6 +773,39 @@ function printVariable(variable) {
667
773
  }
668
774
  return variableLine;
669
775
  }
776
+ function printGraphQLSchema(schema) {
777
+ const schemaLine = `graphql schema = \`${schema.sdl}\``;
778
+ if (schema.inlineComment) {
779
+ return `${schemaLine} ${printComment(schema.inlineComment)}`;
780
+ }
781
+ return schemaLine;
782
+ }
783
+ function printQueryResolver(query) {
784
+ const lines = [];
785
+ const queryLine = `query ${query.name} =`;
786
+ if (query.inlineComment) {
787
+ lines.push(`${queryLine} ${printComment(query.inlineComment)}`);
788
+ } else {
789
+ lines.push(queryLine);
790
+ }
791
+ query.pipeline.steps.forEach((step) => {
792
+ lines.push(formatPipelineStep(step));
793
+ });
794
+ return lines.join("\n");
795
+ }
796
+ function printMutationResolver(mutation) {
797
+ const lines = [];
798
+ const mutationLine = `mutation ${mutation.name} =`;
799
+ if (mutation.inlineComment) {
800
+ lines.push(`${mutationLine} ${printComment(mutation.inlineComment)}`);
801
+ } else {
802
+ lines.push(mutationLine);
803
+ }
804
+ mutation.pipeline.steps.forEach((step) => {
805
+ lines.push(formatPipelineStep(step));
806
+ });
807
+ return lines.join("\n");
808
+ }
670
809
  function printMock(mock, indent = " ") {
671
810
  return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
672
811
  }
@@ -726,6 +865,15 @@ function prettyPrint(program) {
726
865
  program.configs.forEach((config) => {
727
866
  allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
728
867
  });
868
+ if (program.graphqlSchema) {
869
+ allItems.push({ type: "graphqlSchema", item: program.graphqlSchema, lineNumber: program.graphqlSchema.lineNumber || 0 });
870
+ }
871
+ program.queries.forEach((query) => {
872
+ allItems.push({ type: "query", item: query, lineNumber: query.lineNumber || 0 });
873
+ });
874
+ program.mutations.forEach((mutation) => {
875
+ allItems.push({ type: "mutation", item: mutation, lineNumber: mutation.lineNumber || 0 });
876
+ });
729
877
  program.routes.forEach((route) => {
730
878
  allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
731
879
  });
@@ -751,6 +899,18 @@ function prettyPrint(program) {
751
899
  lines.push(printConfig(entry.item));
752
900
  lines.push("");
753
901
  break;
902
+ case "graphqlSchema":
903
+ lines.push(printGraphQLSchema(entry.item));
904
+ lines.push("");
905
+ break;
906
+ case "query":
907
+ lines.push(printQueryResolver(entry.item));
908
+ lines.push("");
909
+ break;
910
+ case "mutation":
911
+ lines.push(printMutationResolver(entry.item));
912
+ lines.push("");
913
+ break;
754
914
  case "route":
755
915
  lines.push(printRoute(entry.item));
756
916
  lines.push("");
@@ -786,7 +946,9 @@ function formatConfigValue(value) {
786
946
  }
787
947
  function formatPipelineStep(step, indent = " ") {
788
948
  if (step.kind === "Regular") {
789
- return `${indent}|> ${step.name}: ${formatStepConfig(step.config, step.configType)}`;
949
+ const configPart = formatStepConfig(step.config, step.configType);
950
+ const tagsPart = step.tags.length > 0 ? " " + formatTags(step.tags) : "";
951
+ return `${indent}|> ${step.name}: ${configPart}${tagsPart}`;
790
952
  } else {
791
953
  const lines = [`${indent}|> result`];
792
954
  step.branches.forEach((branch) => {
@@ -809,6 +971,14 @@ function formatStepConfig(config, configType) {
809
971
  return config;
810
972
  }
811
973
  }
974
+ function formatTags(tags) {
975
+ return tags.map(formatTag).join(" ");
976
+ }
977
+ function formatTag(tag) {
978
+ const negation = tag.negated ? "!" : "";
979
+ const args = tag.args.length > 0 ? `(${tag.args.join(",")})` : "";
980
+ return `@${negation}${tag.name}${args}`;
981
+ }
812
982
  function formatPipelineRef(ref) {
813
983
  if (ref.kind === "Named") {
814
984
  return [` |> pipeline: ${ref.name}`];
@@ -835,6 +1005,8 @@ export {
835
1005
  formatPipelineRef,
836
1006
  formatPipelineStep,
837
1007
  formatStepConfig,
1008
+ formatTag,
1009
+ formatTags,
838
1010
  formatWhen,
839
1011
  getPipelineRanges,
840
1012
  getVariableRanges,
@@ -845,8 +1017,11 @@ export {
845
1017
  printCondition,
846
1018
  printConfig,
847
1019
  printDescribe,
1020
+ printGraphQLSchema,
848
1021
  printMock,
1022
+ printMutationResolver,
849
1023
  printPipeline,
1024
+ printQueryResolver,
850
1025
  printRoute,
851
1026
  printTest,
852
1027
  printVariable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "0.1.12",
3
+ "version": "2.0.1",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",