webpipe-js 2.0.14 → 2.0.16

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
@@ -879,7 +879,20 @@ var Parser = class {
879
879
  this.skipInlineSpaces();
880
880
  const field = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "`");
881
881
  this.skipInlineSpaces();
882
- const jqExpr = this.tryParse(() => this.parseBacktickString());
882
+ let headerName;
883
+ if (field === "header") {
884
+ const h1 = this.tryParse(() => this.parseBacktickString());
885
+ if (h1 !== null) {
886
+ headerName = h1;
887
+ } else {
888
+ const h2 = this.tryParse(() => this.parseQuotedString());
889
+ if (h2 !== null) {
890
+ headerName = h2;
891
+ }
892
+ }
893
+ this.skipInlineSpaces();
894
+ }
895
+ const jqExpr = headerName === void 0 ? this.tryParse(() => this.parseBacktickString()) : null;
883
896
  this.skipInlineSpaces();
884
897
  const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
885
898
  this.skipInlineSpaces();
@@ -890,7 +903,7 @@ var Parser = class {
890
903
  if (v2 !== null) return v2;
891
904
  return this.consumeWhile((c) => c !== "\n");
892
905
  })();
893
- return { conditionType: ct, field, jqExpr: jqExpr ?? void 0, comparison, value };
906
+ return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value };
894
907
  }
895
908
  parseMockHead(prefixWord) {
896
909
  this.skipSpaces();
@@ -930,15 +943,50 @@ var Parser = class {
930
943
  this.skipInlineSpaces();
931
944
  const when = this.parseWhen();
932
945
  this.skipSpaces();
933
- const input = this.tryParse(() => {
934
- this.expect("with");
935
- this.skipInlineSpaces();
936
- this.expect("input");
937
- this.skipInlineSpaces();
938
- const v = this.parseBacktickString();
939
- this.skipSpaces();
940
- return v;
941
- }) ?? void 0;
946
+ let input;
947
+ let body;
948
+ let headers;
949
+ let cookies;
950
+ while (true) {
951
+ const parsed = this.tryParse(() => {
952
+ this.expect("with");
953
+ this.skipInlineSpaces();
954
+ if (this.text.startsWith("input", this.pos)) {
955
+ this.expect("input");
956
+ this.skipInlineSpaces();
957
+ const v = this.parseBacktickString();
958
+ this.skipSpaces();
959
+ return { type: "input", value: v };
960
+ } else if (this.text.startsWith("body", this.pos)) {
961
+ this.expect("body");
962
+ this.skipInlineSpaces();
963
+ const v = this.parseBacktickString();
964
+ this.skipSpaces();
965
+ return { type: "body", value: v };
966
+ } else if (this.text.startsWith("headers", this.pos)) {
967
+ this.expect("headers");
968
+ this.skipInlineSpaces();
969
+ const v = this.parseBacktickString();
970
+ this.skipSpaces();
971
+ return { type: "headers", value: v };
972
+ } else if (this.text.startsWith("cookies", this.pos)) {
973
+ this.expect("cookies");
974
+ this.skipInlineSpaces();
975
+ const v = this.parseBacktickString();
976
+ this.skipSpaces();
977
+ return { type: "cookies", value: v };
978
+ } else if (this.text.startsWith("mock", this.pos)) {
979
+ throw new Error("mock");
980
+ } else {
981
+ throw new Error("unknown with clause");
982
+ }
983
+ });
984
+ if (!parsed) break;
985
+ if (parsed.type === "input") input = parsed.value;
986
+ else if (parsed.type === "body") body = parsed.value;
987
+ else if (parsed.type === "headers") headers = parsed.value;
988
+ else if (parsed.type === "cookies") cookies = parsed.value;
989
+ }
942
990
  const extraMocks = [];
943
991
  while (true) {
944
992
  const m = this.tryParse(() => this.parseAndMock());
@@ -952,7 +1000,7 @@ var Parser = class {
952
1000
  if (!c) break;
953
1001
  conditions.push(c);
954
1002
  }
955
- return { name, mocks: [...mocks, ...extraMocks], when, input, conditions };
1003
+ return { name, mocks: [...mocks, ...extraMocks], when, input, body, headers, cookies, conditions };
956
1004
  }
957
1005
  parseDescribe() {
958
1006
  this.skipSpaces();
@@ -1089,9 +1137,9 @@ function printMock(mock, indent = " ") {
1089
1137
  }
1090
1138
  function printCondition(condition, indent = " ") {
1091
1139
  const condType = condition.conditionType.toLowerCase();
1092
- const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
1140
+ const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1093
1141
  const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1094
- return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
1142
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1095
1143
  }
1096
1144
  function printTest(test) {
1097
1145
  const lines = [];
@@ -1103,6 +1151,15 @@ function printTest(test) {
1103
1151
  if (test.input) {
1104
1152
  lines.push(` with input \`${test.input}\``);
1105
1153
  }
1154
+ if (test.body) {
1155
+ lines.push(` with body \`${test.body}\``);
1156
+ }
1157
+ if (test.headers) {
1158
+ lines.push(` with headers \`${test.headers}\``);
1159
+ }
1160
+ if (test.cookies) {
1161
+ lines.push(` with cookies \`${test.cookies}\``);
1162
+ }
1106
1163
  test.conditions.forEach((condition) => {
1107
1164
  lines.push(printCondition(condition));
1108
1165
  });
package/dist/index.d.cts CHANGED
@@ -163,6 +163,9 @@ interface It {
163
163
  mocks: Mock[];
164
164
  when: When;
165
165
  input?: string;
166
+ body?: string;
167
+ headers?: string;
168
+ cookies?: string;
166
169
  conditions: Condition[];
167
170
  }
168
171
  type When = {
@@ -180,6 +183,7 @@ type When = {
180
183
  interface Condition {
181
184
  conditionType: 'Then' | 'And';
182
185
  field: string;
186
+ headerName?: string;
183
187
  jqExpr?: string;
184
188
  comparison: string;
185
189
  value: string;
package/dist/index.d.ts CHANGED
@@ -163,6 +163,9 @@ interface It {
163
163
  mocks: Mock[];
164
164
  when: When;
165
165
  input?: string;
166
+ body?: string;
167
+ headers?: string;
168
+ cookies?: string;
166
169
  conditions: Condition[];
167
170
  }
168
171
  type When = {
@@ -180,6 +183,7 @@ type When = {
180
183
  interface Condition {
181
184
  conditionType: 'Then' | 'And';
182
185
  field: string;
186
+ headerName?: string;
183
187
  jqExpr?: string;
184
188
  comparison: string;
185
189
  value: string;
package/dist/index.mjs CHANGED
@@ -829,7 +829,20 @@ var Parser = class {
829
829
  this.skipInlineSpaces();
830
830
  const field = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "`");
831
831
  this.skipInlineSpaces();
832
- const jqExpr = this.tryParse(() => this.parseBacktickString());
832
+ let headerName;
833
+ if (field === "header") {
834
+ const h1 = this.tryParse(() => this.parseBacktickString());
835
+ if (h1 !== null) {
836
+ headerName = h1;
837
+ } else {
838
+ const h2 = this.tryParse(() => this.parseQuotedString());
839
+ if (h2 !== null) {
840
+ headerName = h2;
841
+ }
842
+ }
843
+ this.skipInlineSpaces();
844
+ }
845
+ const jqExpr = headerName === void 0 ? this.tryParse(() => this.parseBacktickString()) : null;
833
846
  this.skipInlineSpaces();
834
847
  const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
835
848
  this.skipInlineSpaces();
@@ -840,7 +853,7 @@ var Parser = class {
840
853
  if (v2 !== null) return v2;
841
854
  return this.consumeWhile((c) => c !== "\n");
842
855
  })();
843
- return { conditionType: ct, field, jqExpr: jqExpr ?? void 0, comparison, value };
856
+ return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value };
844
857
  }
845
858
  parseMockHead(prefixWord) {
846
859
  this.skipSpaces();
@@ -880,15 +893,50 @@ var Parser = class {
880
893
  this.skipInlineSpaces();
881
894
  const when = this.parseWhen();
882
895
  this.skipSpaces();
883
- const input = this.tryParse(() => {
884
- this.expect("with");
885
- this.skipInlineSpaces();
886
- this.expect("input");
887
- this.skipInlineSpaces();
888
- const v = this.parseBacktickString();
889
- this.skipSpaces();
890
- return v;
891
- }) ?? void 0;
896
+ let input;
897
+ let body;
898
+ let headers;
899
+ let cookies;
900
+ while (true) {
901
+ const parsed = this.tryParse(() => {
902
+ this.expect("with");
903
+ this.skipInlineSpaces();
904
+ if (this.text.startsWith("input", this.pos)) {
905
+ this.expect("input");
906
+ this.skipInlineSpaces();
907
+ const v = this.parseBacktickString();
908
+ this.skipSpaces();
909
+ return { type: "input", value: v };
910
+ } else if (this.text.startsWith("body", this.pos)) {
911
+ this.expect("body");
912
+ this.skipInlineSpaces();
913
+ const v = this.parseBacktickString();
914
+ this.skipSpaces();
915
+ return { type: "body", value: v };
916
+ } else if (this.text.startsWith("headers", this.pos)) {
917
+ this.expect("headers");
918
+ this.skipInlineSpaces();
919
+ const v = this.parseBacktickString();
920
+ this.skipSpaces();
921
+ return { type: "headers", value: v };
922
+ } else if (this.text.startsWith("cookies", this.pos)) {
923
+ this.expect("cookies");
924
+ this.skipInlineSpaces();
925
+ const v = this.parseBacktickString();
926
+ this.skipSpaces();
927
+ return { type: "cookies", value: v };
928
+ } else if (this.text.startsWith("mock", this.pos)) {
929
+ throw new Error("mock");
930
+ } else {
931
+ throw new Error("unknown with clause");
932
+ }
933
+ });
934
+ if (!parsed) break;
935
+ if (parsed.type === "input") input = parsed.value;
936
+ else if (parsed.type === "body") body = parsed.value;
937
+ else if (parsed.type === "headers") headers = parsed.value;
938
+ else if (parsed.type === "cookies") cookies = parsed.value;
939
+ }
892
940
  const extraMocks = [];
893
941
  while (true) {
894
942
  const m = this.tryParse(() => this.parseAndMock());
@@ -902,7 +950,7 @@ var Parser = class {
902
950
  if (!c) break;
903
951
  conditions.push(c);
904
952
  }
905
- return { name, mocks: [...mocks, ...extraMocks], when, input, conditions };
953
+ return { name, mocks: [...mocks, ...extraMocks], when, input, body, headers, cookies, conditions };
906
954
  }
907
955
  parseDescribe() {
908
956
  this.skipSpaces();
@@ -1039,9 +1087,9 @@ function printMock(mock, indent = " ") {
1039
1087
  }
1040
1088
  function printCondition(condition, indent = " ") {
1041
1089
  const condType = condition.conditionType.toLowerCase();
1042
- const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
1090
+ const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1043
1091
  const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1044
- return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
1092
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1045
1093
  }
1046
1094
  function printTest(test) {
1047
1095
  const lines = [];
@@ -1053,6 +1101,15 @@ function printTest(test) {
1053
1101
  if (test.input) {
1054
1102
  lines.push(` with input \`${test.input}\``);
1055
1103
  }
1104
+ if (test.body) {
1105
+ lines.push(` with body \`${test.body}\``);
1106
+ }
1107
+ if (test.headers) {
1108
+ lines.push(` with headers \`${test.headers}\``);
1109
+ }
1110
+ if (test.cookies) {
1111
+ lines.push(` with cookies \`${test.cookies}\``);
1112
+ }
1056
1113
  test.conditions.forEach((condition) => {
1057
1114
  lines.push(printCondition(condition));
1058
1115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",