webpipe-js 2.0.0 → 2.0.2

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
@@ -36,8 +36,11 @@ __export(index_exports, {
36
36
  printCondition: () => printCondition,
37
37
  printConfig: () => printConfig,
38
38
  printDescribe: () => printDescribe,
39
+ printGraphQLSchema: () => printGraphQLSchema,
39
40
  printMock: () => printMock,
41
+ printMutationResolver: () => printMutationResolver,
40
42
  printPipeline: () => printPipeline,
43
+ printQueryResolver: () => printQueryResolver,
41
44
  printRoute: () => printRoute,
42
45
  printTest: () => printTest,
43
46
  printVariable: () => printVariable
@@ -137,6 +140,10 @@ var Parser = class {
137
140
  const routes = [];
138
141
  const describes = [];
139
142
  const comments = [];
143
+ let graphqlSchema;
144
+ const queries = [];
145
+ const mutations = [];
146
+ let featureFlags;
140
147
  while (!this.eof()) {
141
148
  this.skipWhitespaceOnly();
142
149
  if (this.eof()) break;
@@ -153,6 +160,29 @@ var Parser = class {
153
160
  configs.push(cfg);
154
161
  continue;
155
162
  }
163
+ const schema = this.tryParse(() => this.parseGraphQLSchema());
164
+ if (schema) {
165
+ schema.lineNumber = this.getLineNumber(start);
166
+ graphqlSchema = schema;
167
+ continue;
168
+ }
169
+ const query = this.tryParse(() => this.parseQueryResolver());
170
+ if (query) {
171
+ query.lineNumber = this.getLineNumber(start);
172
+ queries.push(query);
173
+ continue;
174
+ }
175
+ const mutation = this.tryParse(() => this.parseMutationResolver());
176
+ if (mutation) {
177
+ mutation.lineNumber = this.getLineNumber(start);
178
+ mutations.push(mutation);
179
+ continue;
180
+ }
181
+ const flags = this.tryParse(() => this.parseFeatureFlags());
182
+ if (flags) {
183
+ featureFlags = flags;
184
+ continue;
185
+ }
156
186
  const namedPipe = this.tryParse(() => this.parseNamedPipeline());
157
187
  if (namedPipe) {
158
188
  namedPipe.lineNumber = this.getLineNumber(start);
@@ -192,7 +222,7 @@ var Parser = class {
192
222
  const start = Math.max(0, idx);
193
223
  this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
194
224
  }
195
- return { configs, pipelines, variables, routes, describes, comments };
225
+ return { configs, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations, featureFlags };
196
226
  }
197
227
  eof() {
198
228
  return this.pos >= this.len;
@@ -538,6 +568,51 @@ var Parser = class {
538
568
  this.skipWhitespaceOnly();
539
569
  return { varType, name, value, inlineComment: inlineComment || void 0 };
540
570
  }
571
+ parseGraphQLSchema() {
572
+ this.expect("graphql");
573
+ this.skipInlineSpaces();
574
+ this.expect("schema");
575
+ this.skipInlineSpaces();
576
+ this.expect("=");
577
+ const inlineComment = this.parseInlineComment();
578
+ this.skipInlineSpaces();
579
+ const sdl = this.parseBacktickString();
580
+ this.skipWhitespaceOnly();
581
+ return { sdl, inlineComment: inlineComment || void 0 };
582
+ }
583
+ parseQueryResolver() {
584
+ this.expect("query");
585
+ this.skipInlineSpaces();
586
+ const name = this.parseIdentifier();
587
+ this.skipInlineSpaces();
588
+ this.expect("=");
589
+ const inlineComment = this.parseInlineComment();
590
+ this.skipWhitespaceOnly();
591
+ const pipeline = this.parsePipeline();
592
+ this.skipWhitespaceOnly();
593
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
594
+ }
595
+ parseMutationResolver() {
596
+ this.expect("mutation");
597
+ this.skipInlineSpaces();
598
+ const name = this.parseIdentifier();
599
+ this.skipInlineSpaces();
600
+ this.expect("=");
601
+ const inlineComment = this.parseInlineComment();
602
+ this.skipWhitespaceOnly();
603
+ const pipeline = this.parsePipeline();
604
+ this.skipWhitespaceOnly();
605
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
606
+ }
607
+ parseFeatureFlags() {
608
+ this.expect("featureFlags");
609
+ this.skipInlineSpaces();
610
+ this.expect("=");
611
+ this.skipWhitespaceOnly();
612
+ const pipeline = this.parsePipeline();
613
+ this.skipWhitespaceOnly();
614
+ return pipeline;
615
+ }
541
616
  parseRoute() {
542
617
  const method = this.parseMethod();
543
618
  this.skipInlineSpaces();
@@ -762,6 +837,39 @@ function printVariable(variable) {
762
837
  }
763
838
  return variableLine;
764
839
  }
840
+ function printGraphQLSchema(schema) {
841
+ const schemaLine = `graphql schema = \`${schema.sdl}\``;
842
+ if (schema.inlineComment) {
843
+ return `${schemaLine} ${printComment(schema.inlineComment)}`;
844
+ }
845
+ return schemaLine;
846
+ }
847
+ function printQueryResolver(query) {
848
+ const lines = [];
849
+ const queryLine = `query ${query.name} =`;
850
+ if (query.inlineComment) {
851
+ lines.push(`${queryLine} ${printComment(query.inlineComment)}`);
852
+ } else {
853
+ lines.push(queryLine);
854
+ }
855
+ query.pipeline.steps.forEach((step) => {
856
+ lines.push(formatPipelineStep(step));
857
+ });
858
+ return lines.join("\n");
859
+ }
860
+ function printMutationResolver(mutation) {
861
+ const lines = [];
862
+ const mutationLine = `mutation ${mutation.name} =`;
863
+ if (mutation.inlineComment) {
864
+ lines.push(`${mutationLine} ${printComment(mutation.inlineComment)}`);
865
+ } else {
866
+ lines.push(mutationLine);
867
+ }
868
+ mutation.pipeline.steps.forEach((step) => {
869
+ lines.push(formatPipelineStep(step));
870
+ });
871
+ return lines.join("\n");
872
+ }
765
873
  function printMock(mock, indent = " ") {
766
874
  return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
767
875
  }
@@ -821,6 +929,15 @@ function prettyPrint(program) {
821
929
  program.configs.forEach((config) => {
822
930
  allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
823
931
  });
932
+ if (program.graphqlSchema) {
933
+ allItems.push({ type: "graphqlSchema", item: program.graphqlSchema, lineNumber: program.graphqlSchema.lineNumber || 0 });
934
+ }
935
+ program.queries.forEach((query) => {
936
+ allItems.push({ type: "query", item: query, lineNumber: query.lineNumber || 0 });
937
+ });
938
+ program.mutations.forEach((mutation) => {
939
+ allItems.push({ type: "mutation", item: mutation, lineNumber: mutation.lineNumber || 0 });
940
+ });
824
941
  program.routes.forEach((route) => {
825
942
  allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
826
943
  });
@@ -846,6 +963,18 @@ function prettyPrint(program) {
846
963
  lines.push(printConfig(entry.item));
847
964
  lines.push("");
848
965
  break;
966
+ case "graphqlSchema":
967
+ lines.push(printGraphQLSchema(entry.item));
968
+ lines.push("");
969
+ break;
970
+ case "query":
971
+ lines.push(printQueryResolver(entry.item));
972
+ lines.push("");
973
+ break;
974
+ case "mutation":
975
+ lines.push(printMutationResolver(entry.item));
976
+ lines.push("");
977
+ break;
849
978
  case "route":
850
979
  lines.push(printRoute(entry.item));
851
980
  lines.push("");
@@ -953,8 +1082,11 @@ function formatWhen(when) {
953
1082
  printCondition,
954
1083
  printConfig,
955
1084
  printDescribe,
1085
+ printGraphQLSchema,
956
1086
  printMock,
1087
+ printMutationResolver,
957
1088
  printPipeline,
1089
+ printQueryResolver,
958
1090
  printRoute,
959
1091
  printTest,
960
1092
  printVariable
package/dist/index.d.cts CHANGED
@@ -5,6 +5,10 @@ interface Program {
5
5
  routes: Route[];
6
6
  describes: Describe[];
7
7
  comments: Comment[];
8
+ graphqlSchema?: GraphQLSchema;
9
+ queries: QueryResolver[];
10
+ mutations: MutationResolver[];
11
+ featureFlags?: Pipeline;
8
12
  }
9
13
  interface Comment {
10
14
  type: 'standalone' | 'inline';
@@ -49,6 +53,23 @@ interface Variable {
49
53
  lineNumber?: number;
50
54
  inlineComment?: Comment;
51
55
  }
56
+ interface GraphQLSchema {
57
+ sdl: string;
58
+ lineNumber?: number;
59
+ inlineComment?: Comment;
60
+ }
61
+ interface QueryResolver {
62
+ name: string;
63
+ pipeline: Pipeline;
64
+ lineNumber?: number;
65
+ inlineComment?: Comment;
66
+ }
67
+ interface MutationResolver {
68
+ name: string;
69
+ pipeline: Pipeline;
70
+ lineNumber?: number;
71
+ inlineComment?: Comment;
72
+ }
52
73
  interface Route {
53
74
  method: string;
54
75
  path: string;
@@ -156,6 +177,9 @@ declare function printRoute(route: Route): string;
156
177
  declare function printConfig(config: Config): string;
157
178
  declare function printPipeline(pipeline: NamedPipeline): string;
158
179
  declare function printVariable(variable: Variable): string;
180
+ declare function printGraphQLSchema(schema: GraphQLSchema): string;
181
+ declare function printQueryResolver(query: QueryResolver): string;
182
+ declare function printMutationResolver(mutation: MutationResolver): string;
159
183
  declare function printMock(mock: Mock, indent?: string): string;
160
184
  declare function printCondition(condition: Condition, indent?: string): string;
161
185
  declare function printTest(test: It): string;
@@ -170,4 +194,4 @@ declare function formatTag(tag: Tag): string;
170
194
  declare function formatPipelineRef(ref: PipelineRef): string[];
171
195
  declare function formatWhen(when: When): string;
172
196
 
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 };
197
+ 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,10 @@ interface Program {
5
5
  routes: Route[];
6
6
  describes: Describe[];
7
7
  comments: Comment[];
8
+ graphqlSchema?: GraphQLSchema;
9
+ queries: QueryResolver[];
10
+ mutations: MutationResolver[];
11
+ featureFlags?: Pipeline;
8
12
  }
9
13
  interface Comment {
10
14
  type: 'standalone' | 'inline';
@@ -49,6 +53,23 @@ interface Variable {
49
53
  lineNumber?: number;
50
54
  inlineComment?: Comment;
51
55
  }
56
+ interface GraphQLSchema {
57
+ sdl: string;
58
+ lineNumber?: number;
59
+ inlineComment?: Comment;
60
+ }
61
+ interface QueryResolver {
62
+ name: string;
63
+ pipeline: Pipeline;
64
+ lineNumber?: number;
65
+ inlineComment?: Comment;
66
+ }
67
+ interface MutationResolver {
68
+ name: string;
69
+ pipeline: Pipeline;
70
+ lineNumber?: number;
71
+ inlineComment?: Comment;
72
+ }
52
73
  interface Route {
53
74
  method: string;
54
75
  path: string;
@@ -156,6 +177,9 @@ declare function printRoute(route: Route): string;
156
177
  declare function printConfig(config: Config): string;
157
178
  declare function printPipeline(pipeline: NamedPipeline): string;
158
179
  declare function printVariable(variable: Variable): string;
180
+ declare function printGraphQLSchema(schema: GraphQLSchema): string;
181
+ declare function printQueryResolver(query: QueryResolver): string;
182
+ declare function printMutationResolver(mutation: MutationResolver): string;
159
183
  declare function printMock(mock: Mock, indent?: string): string;
160
184
  declare function printCondition(condition: Condition, indent?: string): string;
161
185
  declare function printTest(test: It): string;
@@ -170,4 +194,4 @@ declare function formatTag(tag: Tag): string;
170
194
  declare function formatPipelineRef(ref: PipelineRef): string[];
171
195
  declare function formatWhen(when: When): string;
172
196
 
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 };
197
+ 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,10 @@ var Parser = class {
91
91
  const routes = [];
92
92
  const describes = [];
93
93
  const comments = [];
94
+ let graphqlSchema;
95
+ const queries = [];
96
+ const mutations = [];
97
+ let featureFlags;
94
98
  while (!this.eof()) {
95
99
  this.skipWhitespaceOnly();
96
100
  if (this.eof()) break;
@@ -107,6 +111,29 @@ var Parser = class {
107
111
  configs.push(cfg);
108
112
  continue;
109
113
  }
114
+ const schema = this.tryParse(() => this.parseGraphQLSchema());
115
+ if (schema) {
116
+ schema.lineNumber = this.getLineNumber(start);
117
+ graphqlSchema = schema;
118
+ continue;
119
+ }
120
+ const query = this.tryParse(() => this.parseQueryResolver());
121
+ if (query) {
122
+ query.lineNumber = this.getLineNumber(start);
123
+ queries.push(query);
124
+ continue;
125
+ }
126
+ const mutation = this.tryParse(() => this.parseMutationResolver());
127
+ if (mutation) {
128
+ mutation.lineNumber = this.getLineNumber(start);
129
+ mutations.push(mutation);
130
+ continue;
131
+ }
132
+ const flags = this.tryParse(() => this.parseFeatureFlags());
133
+ if (flags) {
134
+ featureFlags = flags;
135
+ continue;
136
+ }
110
137
  const namedPipe = this.tryParse(() => this.parseNamedPipeline());
111
138
  if (namedPipe) {
112
139
  namedPipe.lineNumber = this.getLineNumber(start);
@@ -146,7 +173,7 @@ var Parser = class {
146
173
  const start = Math.max(0, idx);
147
174
  this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
148
175
  }
149
- return { configs, pipelines, variables, routes, describes, comments };
176
+ return { configs, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations, featureFlags };
150
177
  }
151
178
  eof() {
152
179
  return this.pos >= this.len;
@@ -492,6 +519,51 @@ var Parser = class {
492
519
  this.skipWhitespaceOnly();
493
520
  return { varType, name, value, inlineComment: inlineComment || void 0 };
494
521
  }
522
+ parseGraphQLSchema() {
523
+ this.expect("graphql");
524
+ this.skipInlineSpaces();
525
+ this.expect("schema");
526
+ this.skipInlineSpaces();
527
+ this.expect("=");
528
+ const inlineComment = this.parseInlineComment();
529
+ this.skipInlineSpaces();
530
+ const sdl = this.parseBacktickString();
531
+ this.skipWhitespaceOnly();
532
+ return { sdl, inlineComment: inlineComment || void 0 };
533
+ }
534
+ parseQueryResolver() {
535
+ this.expect("query");
536
+ this.skipInlineSpaces();
537
+ const name = this.parseIdentifier();
538
+ this.skipInlineSpaces();
539
+ this.expect("=");
540
+ const inlineComment = this.parseInlineComment();
541
+ this.skipWhitespaceOnly();
542
+ const pipeline = this.parsePipeline();
543
+ this.skipWhitespaceOnly();
544
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
545
+ }
546
+ parseMutationResolver() {
547
+ this.expect("mutation");
548
+ this.skipInlineSpaces();
549
+ const name = this.parseIdentifier();
550
+ this.skipInlineSpaces();
551
+ this.expect("=");
552
+ const inlineComment = this.parseInlineComment();
553
+ this.skipWhitespaceOnly();
554
+ const pipeline = this.parsePipeline();
555
+ this.skipWhitespaceOnly();
556
+ return { name, pipeline, inlineComment: inlineComment || void 0 };
557
+ }
558
+ parseFeatureFlags() {
559
+ this.expect("featureFlags");
560
+ this.skipInlineSpaces();
561
+ this.expect("=");
562
+ this.skipWhitespaceOnly();
563
+ const pipeline = this.parsePipeline();
564
+ this.skipWhitespaceOnly();
565
+ return pipeline;
566
+ }
495
567
  parseRoute() {
496
568
  const method = this.parseMethod();
497
569
  this.skipInlineSpaces();
@@ -716,6 +788,39 @@ function printVariable(variable) {
716
788
  }
717
789
  return variableLine;
718
790
  }
791
+ function printGraphQLSchema(schema) {
792
+ const schemaLine = `graphql schema = \`${schema.sdl}\``;
793
+ if (schema.inlineComment) {
794
+ return `${schemaLine} ${printComment(schema.inlineComment)}`;
795
+ }
796
+ return schemaLine;
797
+ }
798
+ function printQueryResolver(query) {
799
+ const lines = [];
800
+ const queryLine = `query ${query.name} =`;
801
+ if (query.inlineComment) {
802
+ lines.push(`${queryLine} ${printComment(query.inlineComment)}`);
803
+ } else {
804
+ lines.push(queryLine);
805
+ }
806
+ query.pipeline.steps.forEach((step) => {
807
+ lines.push(formatPipelineStep(step));
808
+ });
809
+ return lines.join("\n");
810
+ }
811
+ function printMutationResolver(mutation) {
812
+ const lines = [];
813
+ const mutationLine = `mutation ${mutation.name} =`;
814
+ if (mutation.inlineComment) {
815
+ lines.push(`${mutationLine} ${printComment(mutation.inlineComment)}`);
816
+ } else {
817
+ lines.push(mutationLine);
818
+ }
819
+ mutation.pipeline.steps.forEach((step) => {
820
+ lines.push(formatPipelineStep(step));
821
+ });
822
+ return lines.join("\n");
823
+ }
719
824
  function printMock(mock, indent = " ") {
720
825
  return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
721
826
  }
@@ -775,6 +880,15 @@ function prettyPrint(program) {
775
880
  program.configs.forEach((config) => {
776
881
  allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
777
882
  });
883
+ if (program.graphqlSchema) {
884
+ allItems.push({ type: "graphqlSchema", item: program.graphqlSchema, lineNumber: program.graphqlSchema.lineNumber || 0 });
885
+ }
886
+ program.queries.forEach((query) => {
887
+ allItems.push({ type: "query", item: query, lineNumber: query.lineNumber || 0 });
888
+ });
889
+ program.mutations.forEach((mutation) => {
890
+ allItems.push({ type: "mutation", item: mutation, lineNumber: mutation.lineNumber || 0 });
891
+ });
778
892
  program.routes.forEach((route) => {
779
893
  allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
780
894
  });
@@ -800,6 +914,18 @@ function prettyPrint(program) {
800
914
  lines.push(printConfig(entry.item));
801
915
  lines.push("");
802
916
  break;
917
+ case "graphqlSchema":
918
+ lines.push(printGraphQLSchema(entry.item));
919
+ lines.push("");
920
+ break;
921
+ case "query":
922
+ lines.push(printQueryResolver(entry.item));
923
+ lines.push("");
924
+ break;
925
+ case "mutation":
926
+ lines.push(printMutationResolver(entry.item));
927
+ lines.push("");
928
+ break;
803
929
  case "route":
804
930
  lines.push(printRoute(entry.item));
805
931
  lines.push("");
@@ -906,8 +1032,11 @@ export {
906
1032
  printCondition,
907
1033
  printConfig,
908
1034
  printDescribe,
1035
+ printGraphQLSchema,
909
1036
  printMock,
1037
+ printMutationResolver,
910
1038
  printPipeline,
1039
+ printQueryResolver,
911
1040
  printRoute,
912
1041
  printTest,
913
1042
  printVariable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",