UNPKG

unmock-core

Version:

[![npm](https://img.shields.io/npm/v/unmock-core.svg)][npmjs] [![CircleCI](https://circleci.com/gh/unmock/unmock-js.svg?style=svg)](https://circleci.com/gh/unmock/unmock-js) [![codecov](https://codecov.io/gh/unmock/unmock-js/branch/dev/graph/badge.svg)](h

45 lines 2.2 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); const debug_1 = require("debug"); const constants_1 = require("./constants"); const utils_1 = require("./utils"); const debugLog = debug_1.default("unmock:dsl:actors"); const actOn$times = (origState) => { const origTimes = origState.properties[constants_1.SCHEMA_TIMES]; const newTimes = origTimes.default - 1; const newState = newTimes > 0 ? Object.assign(Object.assign({}, origState), { properties: Object.assign(Object.assign({}, origState.properties), { [constants_1.SCHEMA_TIMES]: Object.assign(Object.assign({}, origTimes), { default: newTimes }) }) }) : undefined; debugLog(`new state for ${JSON.stringify(origState)} is '${JSON.stringify(newState)}'`); const { properties } = origState, rest = __rest(origState, ["properties"]); const _a = properties, _b = constants_1.SCHEMA_TIMES, unused = _a[_b], restProperties = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); return { parsed: Object.keys(restProperties).length > 0 ? Object.assign({ properties: restProperties }, rest) : Object.assign({}, rest), newState, }; }; const actors = { [constants_1.SCHEMA_TIMES]: actOn$times, }; exports.actWithAllActors = (schema) => Object.entries(actors).reduce(({ newState, parsed, }, [property, fn]) => { if (utils_1.hasUnmockProperty(schema, property)) { const result = fn(schema); return { newState: newState.concat(result.newState), parsed: parsed.concat(result.parsed), }; } return { newState, parsed: parsed.concat(schema) }; }, { newState: [], parsed: [] }); //# sourceMappingURL=actors.js.map