UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

46 lines (45 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TableSpy = void 0; const constants_js_1 = require("../../../table/constants.js"); const index_js_1 = require("../../../table/index.js"); const actionInspector_js_1 = require("./actionInspector.js"); const actionStub_js_1 = require("./actionStub.js"); const constants_js_2 = require("./constants.js"); class TableSpy extends index_js_1.TableAction { constructor(table) { super(table); this[constants_js_2.$mocks] = {}; this[constants_js_2.$sentActions] = {}; table[constants_js_1.$interceptor] = (action) => { const actionName = action.constructor.actionName; const sentArgs = action[constants_js_1.$sentArgs](); const actionSentArgs = this[constants_js_2.$sentActions][actionName]; if (actionSentArgs !== undefined) { actionSentArgs.push(sentArgs); } else { this[constants_js_2.$sentActions][actionName] = [sentArgs]; } const actionMock = this[constants_js_2.$mocks][actionName]; if (actionMock !== undefined) { return actionMock(...sentArgs); } }; } reset() { this[constants_js_2.$mocks] = {}; this[constants_js_2.$sentActions] = {}; return this; } on(Action) { return new actionStub_js_1.TableActionStub(this, Action); } sent(Action) { return new actionInspector_js_1.TableActionInspector(this, Action); } restore() { delete this.table[constants_js_1.$interceptor]; } } exports.TableSpy = TableSpy;