UNPKG

pact-gen-ts

Version:

Generating pact files from typescript definitions

27 lines (26 loc) 1.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Query = void 0; const type_representation_1 = require("./type-representation"); const interaction_creator_1 = require("./interaction-creator"); const create_pact_example_object_1 = require("./create-pact-example-object"); const create_pact_matching_rules_1 = require("./create-pact-matching-rules"); const pact_annotations_1 = require("../consts/pact-annotations"); const qs_1 = __importDefault(require("qs")); class Query { constructor(apiFunctionNode, sourceFile, queryArrayFormat) { const queryElement = interaction_creator_1.InteractionCreator.getParameterWithJsDocFromFunction(apiFunctionNode, pact_annotations_1.PACT_ANNOTATIONS.PACT_QUERY) || interaction_creator_1.InteractionCreator.getVariableWithJsDocFromFunction(apiFunctionNode, pact_annotations_1.PACT_ANNOTATIONS.PACT_QUERY); if (queryElement) { const queryElementType = queryElement.getType(); const basicTypeRepresentationOfRequestBody = (0, type_representation_1.getTypeRepresentation)(queryElementType, sourceFile); const exampleRepresentationOfQueryObject = (0, create_pact_example_object_1.changeObjectRepresentationIntoExample)(basicTypeRepresentationOfRequestBody); this.query = qs_1.default.stringify(exampleRepresentationOfQueryObject, { arrayFormat: queryArrayFormat || 'brackets' }); this.matchingRules = (0, create_pact_matching_rules_1.changeObjectRepresentationIntoMatchingRules)(basicTypeRepresentationOfRequestBody, '$.query'); } } } exports.Query = Query;