UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

52 lines 2.17 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.jpathFind = exports.jpathFindAll = exports.jpathSearch = exports.JsonDoc = void 0; const jmespath = require("jmespath"); const helpers_1 = require("../helpers"); const value_promise_1 = require("../value-promise"); class JsonDoc { constructor(jsonRoot) { this.jsonRoot = jsonRoot; this.search = (path) => __awaiter(this, void 0, void 0, function* () { try { return exports.jpathSearch(this.jsonRoot, path); } catch (ex) { return undefined; } }); } get root() { return this.jsonRoot; } } exports.JsonDoc = JsonDoc; const jpathSearch = (input, path) => { return jmespath.search(input, path); }; exports.jpathSearch = jpathSearch; const jpathFindAll = (self, path) => __awaiter(void 0, void 0, void 0, function* () { const item = yield self.find(path); return [item]; }); exports.jpathFindAll = jpathFindAll; const jpathFind = (self, path) => { return value_promise_1.ValuePromise.execute(() => __awaiter(void 0, void 0, void 0, function* () { if (self.jsonDoc === undefined) { throw Error("No JSON document is defined."); } const selection = yield self.jsonDoc.search(path); return helpers_1.wrapAsValue(self.context, selection, path, selection); })); }; exports.jpathFind = jpathFind; //# sourceMappingURL=jpath.js.map