@pact-foundation/pact 16.3.1 → 16.5.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.
Files changed (261) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/README.md +22 -12
  4. package/package.json +26 -47
  5. package/scripts/ci/build-and-test.sh +0 -3
  6. package/scripts/install-plugins.js +104 -0
  7. package/src/common/graphQL/configurationError.js +2 -22
  8. package/src/common/graphQL/configurationError.js.map +1 -1
  9. package/src/common/graphQL/graphQL.d.ts +2 -2
  10. package/src/common/graphQL/graphQL.js +11 -14
  11. package/src/common/graphQL/graphQL.js.map +1 -1
  12. package/src/common/graphQL/graphQLQueryError.js +2 -22
  13. package/src/common/graphQL/graphQLQueryError.js.map +1 -1
  14. package/src/common/logger.js +9 -9
  15. package/src/common/logger.js.map +1 -1
  16. package/src/common/matchingRules.d.ts +7 -1
  17. package/src/common/matchingRules.js +42 -22
  18. package/src/common/matchingRules.js.map +1 -1
  19. package/src/common/net.js +36 -42
  20. package/src/common/net.js.map +1 -1
  21. package/src/common/net.spec.js +39 -87
  22. package/src/common/net.spec.js.map +1 -1
  23. package/src/common/request.js +33 -82
  24. package/src/common/request.js.map +1 -1
  25. package/src/common/request.spec.js +29 -73
  26. package/src/common/request.spec.js.map +1 -1
  27. package/src/common/spec.js +3 -4
  28. package/src/common/spec.js.map +1 -1
  29. package/src/dsl/apolloGraphql.js +7 -25
  30. package/src/dsl/apolloGraphql.js.map +1 -1
  31. package/src/dsl/apolloGraphql.spec.js +21 -58
  32. package/src/dsl/apolloGraphql.spec.js.map +1 -1
  33. package/src/dsl/graphql.d.ts +2 -2
  34. package/src/dsl/graphql.js +29 -48
  35. package/src/dsl/graphql.js.map +1 -1
  36. package/src/dsl/graphql.spec.js +92 -117
  37. package/src/dsl/graphql.spec.js.map +1 -1
  38. package/src/dsl/interaction.d.ts +2 -2
  39. package/src/dsl/interaction.js +41 -48
  40. package/src/dsl/interaction.js.map +1 -1
  41. package/src/dsl/interaction.spec.js +109 -132
  42. package/src/dsl/interaction.spec.js.map +1 -1
  43. package/src/dsl/matchers.d.ts +2 -3
  44. package/src/dsl/matchers.js +19 -31
  45. package/src/dsl/matchers.js.map +1 -1
  46. package/src/dsl/matchers.spec.js +279 -289
  47. package/src/dsl/matchers.spec.js.map +1 -1
  48. package/src/dsl/message.d.ts +3 -3
  49. package/src/dsl/options.d.ts +3 -3
  50. package/src/dsl/verifier/proxy/hooks.d.ts +2 -2
  51. package/src/dsl/verifier/proxy/hooks.js +42 -112
  52. package/src/dsl/verifier/proxy/hooks.js.map +1 -1
  53. package/src/dsl/verifier/proxy/hooks.spec.js +86 -199
  54. package/src/dsl/verifier/proxy/hooks.spec.js.map +1 -1
  55. package/src/dsl/verifier/proxy/messages.d.ts +2 -2
  56. package/src/dsl/verifier/proxy/messages.js +88 -106
  57. package/src/dsl/verifier/proxy/messages.js.map +1 -1
  58. package/src/dsl/verifier/proxy/parseBody.d.ts +1 -1
  59. package/src/dsl/verifier/proxy/parseBody.js +3 -3
  60. package/src/dsl/verifier/proxy/parseBody.js.map +1 -1
  61. package/src/dsl/verifier/proxy/parseBody.spec.js +35 -113
  62. package/src/dsl/verifier/proxy/parseBody.spec.js.map +1 -1
  63. package/src/dsl/verifier/proxy/proxy.d.ts +2 -2
  64. package/src/dsl/verifier/proxy/proxy.js +22 -26
  65. package/src/dsl/verifier/proxy/proxy.js.map +1 -1
  66. package/src/dsl/verifier/proxy/proxy.spec.js +11 -53
  67. package/src/dsl/verifier/proxy/proxy.spec.js.map +1 -1
  68. package/src/dsl/verifier/proxy/proxyRequest.d.ts +3 -3
  69. package/src/dsl/verifier/proxy/proxyRequest.js +7 -7
  70. package/src/dsl/verifier/proxy/proxyRequest.js.map +1 -1
  71. package/src/dsl/verifier/proxy/proxyRequest.spec.js +54 -104
  72. package/src/dsl/verifier/proxy/proxyRequest.spec.js.map +1 -1
  73. package/src/dsl/verifier/proxy/stateHandler/setupStates.d.ts +3 -3
  74. package/src/dsl/verifier/proxy/stateHandler/setupStates.js +14 -18
  75. package/src/dsl/verifier/proxy/stateHandler/setupStates.js.map +1 -1
  76. package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js +76 -193
  77. package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js.map +1 -1
  78. package/src/dsl/verifier/proxy/stateHandler/stateHandler.d.ts +2 -2
  79. package/src/dsl/verifier/proxy/stateHandler/stateHandler.js +23 -72
  80. package/src/dsl/verifier/proxy/stateHandler/stateHandler.js.map +1 -1
  81. package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js +37 -122
  82. package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js.map +1 -1
  83. package/src/dsl/verifier/proxy/tracer.d.ts +1 -1
  84. package/src/dsl/verifier/proxy/tracer.js +42 -35
  85. package/src/dsl/verifier/proxy/tracer.js.map +1 -1
  86. package/src/dsl/verifier/proxy/types.d.ts +5 -5
  87. package/src/dsl/verifier/types.d.ts +3 -3
  88. package/src/dsl/verifier/verifier.d.ts +5 -1
  89. package/src/dsl/verifier/verifier.js +53 -60
  90. package/src/dsl/verifier/verifier.js.map +1 -1
  91. package/src/dsl/verifier/verifier.spec.js +84 -151
  92. package/src/dsl/verifier/verifier.spec.js.map +1 -1
  93. package/src/errors/configurationError.js +2 -22
  94. package/src/errors/configurationError.js.map +1 -1
  95. package/src/errors/graphQLQueryError.js +2 -22
  96. package/src/errors/graphQLQueryError.js.map +1 -1
  97. package/src/errors/matcherError.js +2 -22
  98. package/src/errors/matcherError.js.map +1 -1
  99. package/src/errors/verificationError.js +2 -22
  100. package/src/errors/verificationError.js.map +1 -1
  101. package/src/httpPact/ffi.d.ts +2 -2
  102. package/src/httpPact/ffi.js +28 -29
  103. package/src/httpPact/ffi.js.map +1 -1
  104. package/src/httpPact/ffi.spec.js +40 -83
  105. package/src/httpPact/ffi.spec.js.map +1 -1
  106. package/src/httpPact/index.d.ts +3 -3
  107. package/src/httpPact/index.js +92 -149
  108. package/src/httpPact/index.js.map +1 -1
  109. package/src/httpPact/index.spec.js +102 -195
  110. package/src/httpPact/index.spec.js.map +1 -1
  111. package/src/httpPact/tracing.js +20 -28
  112. package/src/httpPact/tracing.js.map +1 -1
  113. package/src/index.d.ts +25 -25
  114. package/src/index.js +29 -29
  115. package/src/index.js.map +1 -1
  116. package/src/messageConsumerPact.d.ts +5 -5
  117. package/src/messageConsumerPact.js +59 -53
  118. package/src/messageConsumerPact.js.map +1 -1
  119. package/src/messageConsumerPact.spec.js +55 -97
  120. package/src/messageConsumerPact.spec.js.map +1 -1
  121. package/src/messageProviderPact.d.ts +3 -3
  122. package/src/messageProviderPact.js +68 -85
  123. package/src/messageProviderPact.js.map +1 -1
  124. package/src/messageProviderPact.spec.js +96 -123
  125. package/src/messageProviderPact.spec.js.map +1 -1
  126. package/src/pact.integration.spec.js +242 -351
  127. package/src/pact.integration.spec.js.map +1 -1
  128. package/src/v3/display.d.ts +1 -1
  129. package/src/v3/display.js +44 -58
  130. package/src/v3/display.js.map +1 -1
  131. package/src/v3/ffi.js +20 -16
  132. package/src/v3/ffi.js.map +1 -1
  133. package/src/v3/ffi.spec.js +7 -42
  134. package/src/v3/ffi.spec.js.map +1 -1
  135. package/src/v3/graphql/graphQL.d.ts +4 -4
  136. package/src/v3/graphql/graphQL.js +50 -75
  137. package/src/v3/graphql/graphQL.js.map +1 -1
  138. package/src/v3/graphql/index.d.ts +1 -1
  139. package/src/v3/graphql/index.js +1 -1
  140. package/src/v3/graphql/index.js.map +1 -1
  141. package/src/v3/index.d.ts +4 -12
  142. package/src/v3/index.js +4 -12
  143. package/src/v3/index.js.map +1 -1
  144. package/src/v3/matchers.d.ts +15 -3
  145. package/src/v3/matchers.js +131 -148
  146. package/src/v3/matchers.js.map +1 -1
  147. package/src/v3/matchers.spec.js +281 -232
  148. package/src/v3/matchers.spec.js.map +1 -1
  149. package/src/v3/pact.d.ts +2 -2
  150. package/src/v3/pact.js +108 -151
  151. package/src/v3/pact.js.map +1 -1
  152. package/src/v3/pact.spec.js +94 -0
  153. package/src/v3/pact.spec.js.map +1 -0
  154. package/src/v3/types.d.ts +19 -3
  155. package/src/v3/types.js +22 -1
  156. package/src/v3/types.js.map +1 -1
  157. package/src/v4/graphql/graphQLInteractionWithRequest.d.ts +4 -4
  158. package/src/v4/graphql/graphQLInteractionWithRequest.js +21 -17
  159. package/src/v4/graphql/graphQLInteractionWithRequest.js.map +1 -1
  160. package/src/v4/graphql/graphQLRequestBuilder.d.ts +3 -3
  161. package/src/v4/graphql/graphQLRequestBuilder.js +18 -20
  162. package/src/v4/graphql/graphQLRequestBuilder.js.map +1 -1
  163. package/src/v4/graphql/index.d.ts +6 -6
  164. package/src/v4/graphql/index.js +21 -17
  165. package/src/v4/graphql/index.js.map +1 -1
  166. package/src/v4/graphql/types.d.ts +5 -5
  167. package/src/v4/http/index.d.ts +2 -2
  168. package/src/v4/http/index.js +53 -93
  169. package/src/v4/http/index.js.map +1 -1
  170. package/src/v4/http/index.spec.d.ts +1 -0
  171. package/src/v4/http/index.spec.js +73 -0
  172. package/src/v4/http/index.spec.js.map +1 -0
  173. package/src/v4/http/interactionWithCompleteRequest.d.ts +4 -7
  174. package/src/v4/http/interactionWithCompleteRequest.js +6 -10
  175. package/src/v4/http/interactionWithCompleteRequest.js.map +1 -1
  176. package/src/v4/http/interactionWithPlugin.d.ts +3 -3
  177. package/src/v4/http/interactionWithPlugin.js +14 -11
  178. package/src/v4/http/interactionWithPlugin.js.map +1 -1
  179. package/src/v4/http/interactionWithPluginRequest.d.ts +4 -3
  180. package/src/v4/http/interactionWithPluginRequest.js +17 -9
  181. package/src/v4/http/interactionWithPluginRequest.js.map +1 -1
  182. package/src/v4/http/interactionWithPluginResponse.d.ts +2 -2
  183. package/src/v4/http/interactionWithPluginResponse.js +10 -48
  184. package/src/v4/http/interactionWithPluginResponse.js.map +1 -1
  185. package/src/v4/http/interactionWithRequest.d.ts +4 -3
  186. package/src/v4/http/interactionWithRequest.js +17 -9
  187. package/src/v4/http/interactionWithRequest.js.map +1 -1
  188. package/src/v4/http/interactionWithRequest.spec.d.ts +1 -0
  189. package/src/v4/http/interactionWithRequest.spec.js +82 -0
  190. package/src/v4/http/interactionWithRequest.spec.js.map +1 -0
  191. package/src/v4/http/interactionWithResponse.d.ts +2 -2
  192. package/src/v4/http/interactionWithResponse.js +10 -48
  193. package/src/v4/http/interactionWithResponse.js.map +1 -1
  194. package/src/v4/http/requestBuilder.d.ts +4 -3
  195. package/src/v4/http/requestBuilder.js +36 -34
  196. package/src/v4/http/requestBuilder.js.map +1 -1
  197. package/src/v4/http/requestBuilder.spec.d.ts +1 -0
  198. package/src/v4/http/requestBuilder.spec.js +42 -0
  199. package/src/v4/http/requestBuilder.spec.js.map +1 -0
  200. package/src/v4/http/requestWithPluginBuilder.d.ts +3 -2
  201. package/src/v4/http/requestWithPluginBuilder.js +30 -46
  202. package/src/v4/http/requestWithPluginBuilder.js.map +1 -1
  203. package/src/v4/http/requestWithPluginBuilder.spec.d.ts +1 -0
  204. package/src/v4/http/requestWithPluginBuilder.spec.js +34 -0
  205. package/src/v4/http/requestWithPluginBuilder.spec.js.map +1 -0
  206. package/src/v4/http/responseBuilder.d.ts +4 -3
  207. package/src/v4/http/responseBuilder.js +28 -25
  208. package/src/v4/http/responseBuilder.js.map +1 -1
  209. package/src/v4/http/responseBuilder.spec.d.ts +1 -0
  210. package/src/v4/http/responseBuilder.spec.js +42 -0
  211. package/src/v4/http/responseBuilder.spec.js.map +1 -0
  212. package/src/v4/http/responseWithPluginBuilder.d.ts +1 -1
  213. package/src/v4/http/responseWithPluginBuilder.js +5 -25
  214. package/src/v4/http/responseWithPluginBuilder.js.map +1 -1
  215. package/src/v4/http/responseWithPluginBuilder.spec.d.ts +1 -0
  216. package/src/v4/http/responseWithPluginBuilder.spec.js +34 -0
  217. package/src/v4/http/responseWithPluginBuilder.spec.js.map +1 -0
  218. package/src/v4/http/types.d.ts +13 -4
  219. package/src/v4/http/unconfiguredInteraction.d.ts +6 -5
  220. package/src/v4/http/unconfiguredInteraction.js +31 -26
  221. package/src/v4/http/unconfiguredInteraction.js.map +1 -1
  222. package/src/v4/index.d.ts +6 -5
  223. package/src/v4/index.js +32 -35
  224. package/src/v4/index.js.map +1 -1
  225. package/src/v4/message/asynchronousMessage.d.ts +7 -6
  226. package/src/v4/message/asynchronousMessage.js +157 -190
  227. package/src/v4/message/asynchronousMessage.js.map +1 -1
  228. package/src/v4/message/index.d.ts +7 -6
  229. package/src/v4/message/index.js +188 -217
  230. package/src/v4/message/index.js.map +1 -1
  231. package/src/v4/message/types.d.ts +5 -3
  232. package/src/v4/types.d.ts +3 -3
  233. package/src/xml/index.d.ts +4 -0
  234. package/src/xml/index.js +21 -0
  235. package/src/xml/index.js.map +1 -0
  236. package/src/{v3/xml → xml}/xmlBuilder.d.ts +1 -3
  237. package/src/{v3/xml → xml}/xmlBuilder.js +7 -9
  238. package/src/xml/xmlBuilder.js.map +1 -0
  239. package/src/{v3/xml → xml}/xmlElement.d.ts +2 -2
  240. package/src/xml/xmlElement.js +73 -0
  241. package/src/xml/xmlElement.js.map +1 -0
  242. package/src/xml/xmlElement.spec.d.ts +1 -0
  243. package/src/xml/xmlElement.spec.js +107 -0
  244. package/src/xml/xmlElement.spec.js.map +1 -0
  245. package/src/xml/xmlNode.js +7 -0
  246. package/src/xml/xmlNode.js.map +1 -0
  247. package/src/{v3/xml → xml}/xmlText.d.ts +1 -1
  248. package/src/xml/xmlText.js +15 -0
  249. package/src/xml/xmlText.js.map +1 -0
  250. package/scripts/install-plugins +0 -106
  251. package/src/v3/xml/xmlBuilder.js.map +0 -1
  252. package/src/v3/xml/xmlElement.js +0 -90
  253. package/src/v3/xml/xmlElement.js.map +0 -1
  254. package/src/v3/xml/xmlElement.spec.js +0 -113
  255. package/src/v3/xml/xmlElement.spec.js.map +0 -1
  256. package/src/v3/xml/xmlNode.js +0 -10
  257. package/src/v3/xml/xmlNode.js.map +0 -1
  258. package/src/v3/xml/xmlText.js +0 -31
  259. package/src/v3/xml/xmlText.js.map +0 -1
  260. /package/src/v3/{xml/xmlElement.spec.d.ts → pact.spec.d.ts} +0 -0
  261. /package/src/{v3/xml → xml}/xmlNode.d.ts +0 -0
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./graphQL"), exports);
18
17
  __exportStar(require("../../common/graphQL/configurationError"), exports);
19
18
  __exportStar(require("../../common/graphQL/graphQLQueryError"), exports);
20
19
  __exportStar(require("../../common/graphQL/types"), exports);
20
+ __exportStar(require("./graphQL"), exports);
21
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v3/graphql/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0EAAwD;AACxD,yEAAuD;AACvD,6DAA2C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v3/graphql/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAAwD;AACxD,yEAAuD;AACvD,6DAA2C;AAC3C,4CAA0B"}
package/src/v3/index.d.ts CHANGED
@@ -1,18 +1,10 @@
1
- export * from './pact';
2
- export * from './types';
1
+ export * from '../xml';
2
+ export * from './graphql';
3
3
  /**
4
4
  * Exposes {@link MatchersV3}
5
5
  * @memberof Pact
6
6
  * @static
7
7
  */
8
8
  export * as MatchersV3 from './matchers';
9
- /**
10
- * Exposes {@link xml}
11
- * @memberof Pact
12
- * @static
13
- */
14
- export * from './xml/xmlBuilder';
15
- export * from './xml/xmlElement';
16
- export * from './xml/xmlNode';
17
- export * from './xml/xmlText';
18
- export * from './graphql';
9
+ export * from './pact';
10
+ export * from './types';
package/src/v3/index.js CHANGED
@@ -37,22 +37,14 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.MatchersV3 = void 0;
40
- __exportStar(require("./pact"), exports);
41
- __exportStar(require("./types"), exports);
40
+ __exportStar(require("../xml"), exports);
41
+ __exportStar(require("./graphql"), exports);
42
42
  /**
43
43
  * Exposes {@link MatchersV3}
44
44
  * @memberof Pact
45
45
  * @static
46
46
  */
47
47
  exports.MatchersV3 = __importStar(require("./matchers"));
48
- /**
49
- * Exposes {@link xml}
50
- * @memberof Pact
51
- * @static
52
- */
53
- __exportStar(require("./xml/xmlBuilder"), exports);
54
- __exportStar(require("./xml/xmlElement"), exports);
55
- __exportStar(require("./xml/xmlNode"), exports);
56
- __exportStar(require("./xml/xmlText"), exports);
57
- __exportStar(require("./graphql"), exports);
48
+ __exportStar(require("./pact"), exports);
49
+ __exportStar(require("./types"), exports);
58
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AAExB;;;;GAIG;AACH,yDAAyC;AAEzC;;;;GAIG;AACH,mDAAiC;AACjC,mDAAiC;AACjC,gDAA8B;AAC9B,gDAA8B;AAE9B,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,4CAA0B;AAE1B;;;;GAIG;AACH,yDAAyC;AACzC,yCAAuB;AACvB,0CAAwB"}
@@ -1,5 +1,5 @@
1
- import { ArrayContainsMatcher, DateTimeMatcher, Matcher, MaxLikeMatcher, MinLikeMatcher, ProviderStateInjectedValue, RulesMatcher, V3RegexMatcher } from './types';
2
- import { AnyJson } from '../common/jsonTypes';
1
+ import type { AnyJson } from '../common/jsonTypes';
2
+ import type { ArrayContainsMatcher, DateTimeMatcher, HTTPResponseStatusClass, Matcher, MaxLikeMatcher, MinLikeMatcher, ProviderStateInjectedValue, RulesMatcher, StatusCodeMatcher, V3RegexMatcher } from './types';
3
3
  export * from './types';
4
4
  export declare function isMatcher(x: unknown): x is Matcher<unknown>;
5
5
  /**
@@ -33,6 +33,14 @@ export declare const eachKeyMatches: (example: Record<string, unknown>, matchers
33
33
  * @param matchers Matchers to apply to each value
34
34
  */
35
35
  export declare const eachValueMatches: <T>(example: Record<string, T>, matchers: Matcher<T> | Matcher<T>[]) => RulesMatcher<T>;
36
+ /**
37
+ * Matches HTTP status codes either by a class (e.g. 2XX) or a list of specific codes.
38
+ *
39
+ * @param example Example status code to use in consumer tests
40
+ * @param status Allowed status codes - either an HTTPResponseStatusClass (e.g. Success for 2XX)
41
+ * or an array of specific status codes (e.g. [200, 201])
42
+ */
43
+ export declare const matchStatus: (example: number, status: HTTPResponseStatusClass | number[]) => StatusCodeMatcher<number>;
36
44
  /**
37
45
  * Array where each element must match the given template
38
46
  * @param template Template to base the comparison on
@@ -170,9 +178,13 @@ export declare function fromProviderState<V>(expression: string, exampleValue: V
170
178
  */
171
179
  export declare function uuid(example?: string): V3RegexMatcher;
172
180
  export declare const matcherValueOrString: (obj: unknown) => string;
181
+ /**
182
+ * Type guard to check if a value is a StatusCodeMatcher.
183
+ */
184
+ export declare const isStatusCodeMatcher: (status: number | StatusCodeMatcher<number>) => status is StatusCodeMatcher<number>;
173
185
  /**
174
186
  * Recurse the object removing any underlying matching guff, returning the raw
175
187
  * example content.
176
188
  */
177
- export declare function reify(input: unknown): AnyJson;
189
+ export declare function reify<T extends AnyJson = AnyJson>(input: unknown): T;
178
190
  export { reify as extractPayload };
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -24,20 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
24
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
15
  };
27
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
28
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
29
- if (ar || !(i in from)) {
30
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
31
- ar[i] = from[i];
32
- }
33
- }
34
- return to.concat(ar || Array.prototype.slice.call(from));
35
- };
36
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
18
  };
39
19
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.matcherValueOrString = exports.equal = exports.contentType = exports.decimal = exports.integer = exports.boolean = exports.constrainedArrayLike = exports.atMostLike = exports.atLeastLike = exports.atLeastOneLike = exports.eachLike = exports.eachValueMatches = exports.eachKeyMatches = exports.eachKeyLike = exports.like = void 0;
20
+ exports.isStatusCodeMatcher = exports.matcherValueOrString = exports.equal = exports.contentType = exports.decimal = exports.integer = exports.boolean = exports.constrainedArrayLike = exports.atMostLike = exports.atLeastLike = exports.atLeastOneLike = exports.eachLike = exports.matchStatus = exports.eachValueMatches = exports.eachKeyMatches = exports.eachKeyLike = exports.like = void 0;
41
21
  exports.isMatcher = isMatcher;
42
22
  exports.number = number;
43
23
  exports.string = string;
@@ -55,8 +35,8 @@ exports.fromProviderState = fromProviderState;
55
35
  exports.uuid = uuid;
56
36
  exports.reify = reify;
57
37
  exports.extractPayload = reify;
58
- var ramda_1 = require("ramda");
59
- var randexp_1 = __importDefault(require("randexp"));
38
+ const ramda_1 = require("ramda");
39
+ const randexp_1 = __importDefault(require("randexp"));
60
40
  __exportStar(require("./types"), exports);
61
41
  function isMatcher(x) {
62
42
  return (x != null &&
@@ -67,10 +47,10 @@ function isMatcher(x) {
67
47
  * Value must match the given template
68
48
  * @param template Template to base the comparison on
69
49
  */
70
- var like = function (template) { return ({
50
+ const like = (template) => ({
71
51
  'pact:matcher:type': 'type',
72
52
  value: template,
73
- }); };
53
+ });
74
54
  exports.like = like;
75
55
  /**
76
56
  * Object where the key itself is ignored, but the value template must match.
@@ -79,15 +59,12 @@ exports.like = like;
79
59
  * @param keyTemplate Example key to use
80
60
  * @param template Example value template to base the comparison on
81
61
  */
82
- var eachKeyLike = function (keyTemplate, template) {
83
- var _a;
84
- return ({
85
- 'pact:matcher:type': 'values',
86
- value: (_a = {},
87
- _a[keyTemplate] = template,
88
- _a),
89
- });
90
- };
62
+ const eachKeyLike = (keyTemplate, template) => ({
63
+ 'pact:matcher:type': 'values',
64
+ value: {
65
+ [keyTemplate]: template,
66
+ },
67
+ });
91
68
  exports.eachKeyLike = eachKeyLike;
92
69
  /**
93
70
  * Object where the _keys_ must match the supplied matchers.
@@ -97,14 +74,11 @@ exports.eachKeyLike = eachKeyLike;
97
74
  * @param example Example object with key/values e.g. `{ foo: 'bar', baz: 'qux'}`
98
75
  * @param matchers Matchers to apply to each key
99
76
  */
100
- var eachKeyMatches = function (example, matchers) {
101
- if (matchers === void 0) { matchers = (0, exports.like)('key'); }
102
- return ({
103
- 'pact:matcher:type': 'eachKey',
104
- rules: Array.isArray(matchers) ? matchers : [matchers],
105
- value: example,
106
- });
107
- };
77
+ const eachKeyMatches = (example, matchers = (0, exports.like)('key')) => ({
78
+ 'pact:matcher:type': 'eachKey',
79
+ rules: Array.isArray(matchers) ? matchers : [matchers],
80
+ value: example,
81
+ });
108
82
  exports.eachKeyMatches = eachKeyMatches;
109
83
  /**
110
84
  * Object where the _values_ must match the supplied matchers.
@@ -114,7 +88,7 @@ exports.eachKeyMatches = eachKeyMatches;
114
88
  * @param example Example object with key/values e.g. `{ foo: 'bar', baz: 'qux'}`
115
89
  * @param matchers Matchers to apply to each value
116
90
  */
117
- var eachValueMatches = function (example, matchers) { return ({
91
+ const eachValueMatches = (example, matchers) => ({
118
92
  'pact:matcher:type': 'eachValue',
119
93
  rules: Array.isArray(matchers) ? matchers : [matchers],
120
94
  value: example,
@@ -122,20 +96,32 @@ var eachValueMatches = function (example, matchers) { return ({
122
96
  // value: {
123
97
  // [keyTemplate]: template,
124
98
  // },
125
- }); };
99
+ });
126
100
  exports.eachValueMatches = eachValueMatches;
101
+ /**
102
+ * Matches HTTP status codes either by a class (e.g. 2XX) or a list of specific codes.
103
+ *
104
+ * @param example Example status code to use in consumer tests
105
+ * @param status Allowed status codes - either an HTTPResponseStatusClass (e.g. Success for 2XX)
106
+ * or an array of specific status codes (e.g. [200, 201])
107
+ */
108
+ const matchStatus = (example, status) => ({
109
+ 'pact:matcher:type': 'statusCode',
110
+ status,
111
+ value: example,
112
+ });
113
+ exports.matchStatus = matchStatus;
127
114
  /**
128
115
  * Array where each element must match the given template
129
116
  * @param template Template to base the comparison on
130
117
  * @param min Minimum number of elements required in the array
131
118
  */
132
- var eachLike = function (template, min) {
133
- if (min === void 0) { min = 1; }
134
- var elements = min;
119
+ const eachLike = (template, min = 1) => {
120
+ const elements = min;
135
121
  return {
136
- min: min,
122
+ min,
137
123
  'pact:matcher:type': 'type',
138
- value: (0, ramda_1.times)(function () { return template; }, elements),
124
+ value: (0, ramda_1.times)(() => template, elements),
139
125
  };
140
126
  };
141
127
  exports.eachLike = eachLike;
@@ -144,14 +130,11 @@ exports.eachLike = eachLike;
144
130
  * @param template Template to base the comparison on
145
131
  * @param count Number of examples to generate, defaults to one
146
132
  */
147
- var atLeastOneLike = function (template, count) {
148
- if (count === void 0) { count = 1; }
149
- return ({
150
- min: 1,
151
- 'pact:matcher:type': 'type',
152
- value: (0, ramda_1.times)(function () { return template; }, count),
153
- });
154
- };
133
+ const atLeastOneLike = (template, count = 1) => ({
134
+ min: 1,
135
+ 'pact:matcher:type': 'type',
136
+ value: (0, ramda_1.times)(() => template, count),
137
+ });
155
138
  exports.atLeastOneLike = atLeastOneLike;
156
139
  /**
157
140
  * An array that has to have at least the required number of elements and each element must match the given template
@@ -159,16 +142,16 @@ exports.atLeastOneLike = atLeastOneLike;
159
142
  * @param min Minimum number of elements required in the array
160
143
  * @param count Number of examples to generate, defaults to min
161
144
  */
162
- var atLeastLike = function (template, min, count) {
163
- var elements = count || min;
145
+ const atLeastLike = (template, min, count) => {
146
+ const elements = count || min;
164
147
  if (count && count < min) {
165
- throw new Error("atLeastLike has a minimum of ".concat(min, " but ").concat(count, " elements were requested.") +
166
- " Make sure the count is greater than or equal to the min.");
148
+ throw new Error(`atLeastLike has a minimum of ${min} but ${count} elements were requested.` +
149
+ ` Make sure the count is greater than or equal to the min.`);
167
150
  }
168
151
  return {
169
- min: min,
152
+ min,
170
153
  'pact:matcher:type': 'type',
171
- value: (0, ramda_1.times)(function () { return template; }, elements),
154
+ value: (0, ramda_1.times)(() => template, elements),
172
155
  };
173
156
  };
174
157
  exports.atLeastLike = atLeastLike;
@@ -178,16 +161,16 @@ exports.atLeastLike = atLeastLike;
178
161
  * @param max Maximum number of elements required in the array
179
162
  * @param count Number of examples to generate, defaults to one
180
163
  */
181
- var atMostLike = function (template, max, count) {
182
- var elements = count || 1;
164
+ const atMostLike = (template, max, count) => {
165
+ const elements = count || 1;
183
166
  if (count && count > max) {
184
- throw new Error("atMostLike has a maximum of ".concat(max, " but ").concat(count, " elements where requested.") +
185
- " Make sure the count is less than or equal to the max.");
167
+ throw new Error(`atMostLike has a maximum of ${max} but ${count} elements where requested.` +
168
+ ` Make sure the count is less than or equal to the max.`);
186
169
  }
187
170
  return {
188
- max: max,
171
+ max,
189
172
  'pact:matcher:type': 'type',
190
- value: (0, ramda_1.times)(function () { return template; }, elements),
173
+ value: (0, ramda_1.times)(() => template, elements),
191
174
  };
192
175
  };
193
176
  exports.atMostLike = atMostLike;
@@ -198,23 +181,23 @@ exports.atMostLike = atMostLike;
198
181
  * @param max Maximum number of elements required in the array
199
182
  * @param count Number of examples to generate, defaults to one
200
183
  */
201
- var constrainedArrayLike = function (template, min, max, count) {
202
- var elements = count || min;
184
+ const constrainedArrayLike = (template, min, max, count) => {
185
+ const elements = count || min;
203
186
  if (count) {
204
187
  if (count < min) {
205
- throw new Error("constrainedArrayLike has a minimum of ".concat(min, " but ").concat(count, " elements where requested.") +
206
- " Make sure the count is greater than or equal to the min.");
188
+ throw new Error(`constrainedArrayLike has a minimum of ${min} but ${count} elements where requested.` +
189
+ ` Make sure the count is greater than or equal to the min.`);
207
190
  }
208
191
  else if (count > max) {
209
- throw new Error("constrainedArrayLike has a maximum of ".concat(max, " but ").concat(count, " elements where requested.") +
210
- " Make sure the count is less than or equal to the max.");
192
+ throw new Error(`constrainedArrayLike has a maximum of ${max} but ${count} elements where requested.` +
193
+ ` Make sure the count is less than or equal to the max.`);
211
194
  }
212
195
  }
213
196
  return {
214
- min: min,
215
- max: max,
197
+ min,
198
+ max,
216
199
  'pact:matcher:type': 'type',
217
- value: (0, ramda_1.times)(function () { return template; }, elements),
200
+ value: (0, ramda_1.times)(() => template, elements),
218
201
  };
219
202
  };
220
203
  exports.constrainedArrayLike = constrainedArrayLike;
@@ -222,19 +205,16 @@ exports.constrainedArrayLike = constrainedArrayLike;
222
205
  * Value must be a boolean
223
206
  * @param b Boolean example value. Defaults to true if unsupplied
224
207
  */
225
- var boolean = function (b) {
226
- if (b === void 0) { b = true; }
227
- return ({
228
- 'pact:matcher:type': 'type',
229
- value: b,
230
- });
231
- };
208
+ const boolean = (b = true) => ({
209
+ 'pact:matcher:type': 'type',
210
+ value: b,
211
+ });
232
212
  exports.boolean = boolean;
233
213
  /**
234
214
  * Value must be an integer (must be a number and have no decimal places)
235
215
  * @param int Example value. If omitted a random value will be generated.
236
216
  */
237
- var integer = function (int) {
217
+ const integer = (int) => {
238
218
  if (Number.isInteger(int)) {
239
219
  return {
240
220
  'pact:matcher:type': 'integer',
@@ -242,7 +222,7 @@ var integer = function (int) {
242
222
  };
243
223
  }
244
224
  if (int) {
245
- throw new Error("The integer matcher was passed '".concat(int, "' which is not an integer."));
225
+ throw new Error(`The integer matcher was passed '${int}' which is not an integer.`);
246
226
  }
247
227
  return {
248
228
  'pact:generator:type': 'RandomInt',
@@ -255,7 +235,7 @@ exports.integer = integer;
255
235
  * Value must be a decimal number (must be a number and have decimal places)
256
236
  * @param num Example value. If omitted a random value will be generated.
257
237
  */
258
- var decimal = function (num) {
238
+ const decimal = (num) => {
259
239
  if (Number.isFinite(num)) {
260
240
  return {
261
241
  'pact:matcher:type': 'decimal',
@@ -263,7 +243,7 @@ var decimal = function (num) {
263
243
  };
264
244
  }
265
245
  if (num) {
266
- throw new Error("The decimal matcher was passed '".concat(num, "' which is not a number."));
246
+ throw new Error(`The decimal matcher was passed '${num}' which is not a number.`);
267
247
  }
268
248
  return {
269
249
  'pact:generator:type': 'RandomDecimal',
@@ -284,7 +264,7 @@ function number(num) {
284
264
  };
285
265
  }
286
266
  if (num) {
287
- throw new Error("The number matcher was passed '".concat(num, "' which is not a number."));
267
+ throw new Error(`The number matcher was passed '${num}' which is not a number.`);
288
268
  }
289
269
  return {
290
270
  'pact:generator:type': 'RandomInt',
@@ -296,8 +276,7 @@ function number(num) {
296
276
  * Value must be a string
297
277
  * @param str Example value
298
278
  */
299
- function string(str) {
300
- if (str === void 0) { str = 'some string'; }
279
+ function string(str = 'some string') {
301
280
  return {
302
281
  'pact:matcher:type': 'type',
303
282
  value: str,
@@ -327,19 +306,19 @@ function regex(pattern, str) {
327
306
  * Used for matching binary content or specific content types in multipart requests.
328
307
  * @param contentTypeValue The content type to match (e.g., 'image/jpeg', 'text/plain')
329
308
  */
330
- var contentType = function (contentTypeValue) { return ({
309
+ const contentType = (contentTypeValue) => ({
331
310
  'pact:matcher:type': 'contentType',
332
311
  value: contentTypeValue,
333
- }); };
312
+ });
334
313
  exports.contentType = contentType;
335
314
  /**
336
315
  * Value that must be equal to the example. This is mainly used to reset the matching rules which cascade.
337
316
  * @param value Example value
338
317
  */
339
- var equal = function (value) { return ({
318
+ const equal = (value) => ({
340
319
  'pact:matcher:type': 'equality',
341
- value: value,
342
- }); };
320
+ value,
321
+ });
343
322
  exports.equal = equal;
344
323
  /**
345
324
  * String value that must match the provided datetime format string.
@@ -348,12 +327,12 @@ exports.equal = equal;
348
327
  */
349
328
  function datetime(format, example) {
350
329
  if (!example) {
351
- throw new Error("you must provide an example datetime");
330
+ throw new Error(`you must provide an example datetime`);
352
331
  }
353
- return (0, ramda_1.pickBy)(function (v) { return !(0, ramda_1.isNil)(v); }, {
332
+ return (0, ramda_1.pickBy)((v) => !(0, ramda_1.isNil)(v), {
354
333
  'pact:generator:type': example ? undefined : 'DateTime',
355
334
  'pact:matcher:type': 'timestamp',
356
- format: format,
335
+ format,
357
336
  value: example,
358
337
  });
359
338
  }
@@ -364,7 +343,7 @@ function datetime(format, example) {
364
343
  */
365
344
  function timestamp(format, example) {
366
345
  if (!example) {
367
- throw new Error("you must provide an example timestamp");
346
+ throw new Error(`you must provide an example timestamp`);
368
347
  }
369
348
  return datetime(format, example);
370
349
  }
@@ -375,12 +354,12 @@ function timestamp(format, example) {
375
354
  */
376
355
  function time(format, example) {
377
356
  if (!example) {
378
- throw new Error("you must provide an example time");
357
+ throw new Error(`you must provide an example time`);
379
358
  }
380
- return (0, ramda_1.pickBy)(function (v) { return !(0, ramda_1.isNil)(v); }, {
359
+ return (0, ramda_1.pickBy)((v) => !(0, ramda_1.isNil)(v), {
381
360
  'pact:generator:type': example ? undefined : 'Time',
382
361
  'pact:matcher:type': 'time',
383
- format: format,
362
+ format,
384
363
  value: example,
385
364
  });
386
365
  }
@@ -391,10 +370,10 @@ function time(format, example) {
391
370
  */
392
371
  function date(format, example) {
393
372
  if (!example) {
394
- throw new Error("you must provide an example date");
373
+ throw new Error(`you must provide an example date`);
395
374
  }
396
- return (0, ramda_1.pickBy)(function (v) { return !(0, ramda_1.isNil)(v); }, {
397
- format: format,
375
+ return (0, ramda_1.pickBy)((v) => !(0, ramda_1.isNil)(v), {
376
+ format,
398
377
  'pact:generator:type': example ? undefined : 'Date',
399
378
  'pact:matcher:type': 'date',
400
379
  value: example,
@@ -407,7 +386,7 @@ function date(format, example) {
407
386
  function includes(value) {
408
387
  return {
409
388
  'pact:matcher:type': 'include',
410
- value: value,
389
+ value,
411
390
  };
412
391
  }
413
392
  /**
@@ -429,42 +408,44 @@ function stringFromRegex(r) {
429
408
  * @param pathFragments list of path fragments, can be regular expressions
430
409
  */
431
410
  function url2(basePath, pathFragments) {
432
- var regexpr = __spreadArray([
433
- '.*('
434
- ], pathFragments.map(function (p) {
435
- if (p instanceof RegExp) {
436
- return "\\/".concat(p.source);
437
- }
438
- if (p instanceof Object && p['pact:matcher:type'] === 'regex') {
439
- return "\\/".concat(p.regex);
440
- }
441
- return "\\/".concat(p.toString());
442
- }), true).join('');
443
- var example = __spreadArray([
444
- basePath || 'http://localhost:8080'
445
- ], pathFragments.map(function (p) {
446
- if (p instanceof RegExp) {
447
- return "/".concat(stringFromRegex(p));
448
- }
449
- if (p instanceof Object && p['pact:matcher:type'] === 'regex') {
450
- return "/".concat(p.value);
451
- }
452
- return "/".concat(p.toString());
453
- }), true).join('');
411
+ const regexpr = [
412
+ '.*(',
413
+ ...pathFragments.map((p) => {
414
+ if (p instanceof RegExp) {
415
+ return `\\/${p.source}`;
416
+ }
417
+ if (p instanceof Object && p['pact:matcher:type'] === 'regex') {
418
+ return `\\/${p.regex}`;
419
+ }
420
+ return `\\/${p.toString()}`;
421
+ }),
422
+ ].join('');
423
+ const example = [
424
+ basePath || 'http://localhost:8080',
425
+ ...pathFragments.map((p) => {
426
+ if (p instanceof RegExp) {
427
+ return `/${stringFromRegex(p)}`;
428
+ }
429
+ if (p instanceof Object && p['pact:matcher:type'] === 'regex') {
430
+ return `/${p.value}`;
431
+ }
432
+ return `/${p.toString()}`;
433
+ }),
434
+ ].join('');
454
435
  // Temporary fix for inconsistencies between matchers and generators. Matchers use "value" attribute for
455
436
  // example values, while generators use "example"
456
437
  if (basePath == null) {
457
438
  return {
458
439
  'pact:matcher:type': 'regex',
459
440
  'pact:generator:type': 'MockServerURL',
460
- regex: "".concat(regexpr, ")$"),
441
+ regex: `${regexpr})$`,
461
442
  value: example,
462
- example: example,
443
+ example,
463
444
  };
464
445
  }
465
446
  return {
466
447
  'pact:matcher:type': 'regex',
467
- regex: "".concat(regexpr, ")$"),
448
+ regex: `${regexpr})$`,
468
449
  value: example,
469
450
  };
470
451
  }
@@ -479,14 +460,10 @@ function url(pathFragments) {
479
460
  * Matches the items in an array against a number of variants. Matching is successful if each variant
480
461
  * occurs once in the array. Variants may be objects containing matching rules.
481
462
  */
482
- function arrayContaining() {
483
- var variants = [];
484
- for (var _i = 0; _i < arguments.length; _i++) {
485
- variants[_i] = arguments[_i];
486
- }
463
+ function arrayContaining(...variants) {
487
464
  return {
488
465
  'pact:matcher:type': 'arrayContains',
489
- variants: variants,
466
+ variants,
490
467
  };
491
468
  }
492
469
  /**
@@ -498,7 +475,7 @@ function fromProviderState(expression, exampleValue) {
498
475
  return {
499
476
  'pact:matcher:type': 'type',
500
477
  'pact:generator:type': 'ProviderState',
501
- expression: expression,
478
+ expression,
502
479
  value: exampleValue,
503
480
  };
504
481
  }
@@ -506,11 +483,11 @@ function fromProviderState(expression, exampleValue) {
506
483
  * Match a universally unique identifier (UUID). Random values will be used for examples if no example is given.
507
484
  */
508
485
  function uuid(example) {
509
- var regexStr = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
486
+ const regexStr = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
510
487
  if (example) {
511
- var regexpr = new RegExp("^".concat(regexStr, "$"));
488
+ const regexpr = new RegExp(`^${regexStr}$`);
512
489
  if (!example.match(regexpr)) {
513
- throw new Error("regex: Example value '".concat(example, "' does not match the UUID regular expression '").concat(regexStr, "'"));
490
+ throw new Error(`regex: Example value '${example}' does not match the UUID regular expression '${regexStr}'`);
514
491
  }
515
492
  return {
516
493
  'pact:matcher:type': 'regex',
@@ -525,12 +502,17 @@ function uuid(example) {
525
502
  value: 'e2490de5-5bd3-43d5-b7c4-526e33f71304',
526
503
  };
527
504
  }
528
- var matcherValueOrString = function (obj) {
505
+ const matcherValueOrString = (obj) => {
529
506
  if (typeof obj === 'string')
530
507
  return obj;
531
508
  return JSON.stringify(obj);
532
509
  };
533
510
  exports.matcherValueOrString = matcherValueOrString;
511
+ /**
512
+ * Type guard to check if a value is a StatusCodeMatcher.
513
+ */
514
+ const isStatusCodeMatcher = (status) => isMatcher(status) && status['pact:matcher:type'] === 'statusCode';
515
+ exports.isStatusCodeMatcher = isStatusCodeMatcher;
534
516
  /**
535
517
  * Recurse the object removing any underlying matching guff, returning the raw
536
518
  * example content.
@@ -546,9 +528,10 @@ function reify(input) {
546
528
  if (input === null) {
547
529
  return input;
548
530
  }
549
- return Object.keys(input).reduce(function (acc, propName) {
550
- var _a;
551
- return (__assign(__assign({}, acc), (_a = {}, _a[propName] = reify(input[propName]), _a)));
531
+ const objectInput = input;
532
+ return Object.keys(objectInput).reduce((acc, propName) => {
533
+ acc[propName] = reify(objectInput[propName]);
534
+ return acc;
552
535
  }, {});
553
536
  }
554
537
  if (typeof input === 'number' ||
@@ -556,6 +539,6 @@ function reify(input) {
556
539
  typeof input === 'boolean') {
557
540
  return input;
558
541
  }
559
- throw new Error("Unable to strip matcher from a '".concat(typeof input, "', as it is not valid in a Pact description"));
542
+ throw new Error(`Unable to strip matcher from a '${typeof input}', as it is not valid in a Pact description`);
560
543
  }
561
544
  //# sourceMappingURL=matchers.js.map