ottoman
Version:
Ottoman Couchbase ODM
32 lines • 1.56 kB
JavaScript
;
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.execHooks = void 0;
const pipe_1 = require("../../utils/pipe");
/**
* Executes hooks in a chain,
* passing previous result to the next hook in chain.
*/
const execHooks = (schema, hookType, hookAction, document) => __awaiter(void 0, void 0, void 0, function* () {
for (const key in schema.fields) {
const field = schema.fields[key];
if (field.typeName === 'Embed' && field.schema) {
yield (0, exports.execHooks)(field.schema, hookType, hookAction, document[field.name]);
}
}
if (schema[hookType] && schema[hookType][hookAction]) {
const hooks = schema[hookType][hookAction];
const hooksFn = (0, pipe_1.pipe)(...hooks);
yield hooksFn(document);
}
});
exports.execHooks = execHooks;
//# sourceMappingURL=exec-hooks.js.map