UNPKG

@n1k1t/mock-server

Version:

The ultimate toolkit to intercept, transform, and simulate HTTP/WS traffic with type-safe expectations

42 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Provider = void 0; const expectations_1 = require("../../../expectations"); const containers_1 = require("../containers"); const history_1 = require("../history"); const client_1 = require("../../../client"); class Provider { constructor(provided) { this.provided = provided; this.timestamp = Date.now(); this.client = client_1.OnsiteClient.build(this); this.group = this.provided.group; this.storages = { expectations: new expectations_1.ExpectationsStorage({ group: this.group }), containers: new containers_1.ContainersStorage({ group: this.group }), history: new history_1.HistoryStorage({ group: this.group, limit: this.provided.history?.limit }), }; /** Seconds */ this.ttl = this.provided.ttl; } checkIsExpired(timestamp = Date.now()) { return this.ttl ? (this.timestamp + this.ttl * 1000) < timestamp : false; } assign(payload) { return Object.assign(this, payload); } /** Extends storages of this instance with another provider */ extend(provider) { this.storages.expectations.extend(provider.storages.expectations); this.storages.containers.extend(provider.storages.containers); this.storages.history.extend(provider.storages.history); return this; } static build(provided) { return new Provider(provided); } } exports.Provider = Provider; //# sourceMappingURL=model.js.map