MCPcopy
hub / github.com/sequelize/sequelize / runHooks

Function runHooks

src/hooks.js:93–133  ·  view source on GitHub ↗
(hooks, ...hookArgs)

Source from the content-addressed store, hash-verified

91 },
92
93 async runHooks(hooks, ...hookArgs) {
94 if (!hooks) throw new Error('runHooks requires at least 1 argument');
95
96 let hookType;
97
98 if (typeof hooks === 'string') {
99 hookType = hooks;
100 hooks = getHooks(this, hookType);
101
102 if (this.sequelize) {
103 hooks = hooks.concat(getHooks(this.sequelize, hookType));
104 }
105 }
106
107 if (!Array.isArray(hooks)) {
108 hooks = [hooks];
109 }
110
111 // synchronous hooks
112 if (hookTypes[hookType] && hookTypes[hookType].sync) {
113 for (let hook of hooks) {
114 if (typeof hook === 'object') {
115 hook = hook.fn;
116 }
117
118 debug(`running hook(sync) ${hookType}`);
119 hook.apply(this, hookArgs);
120 }
121 return;
122 }
123
124 // asynchronous hooks (default)
125 for (let hook of hooks) {
126 if (typeof hook === 'object') {
127 hook = hook.fn;
128 }
129
130 debug(`running hook ${hookType}`);
131 await hook.apply(this, hookArgs);
132 }
133 },
134
135 /**
136 * Add a hook to the model

Callers 1

_validateAndRunHooksMethod · 0.85

Calls 1

getHooksFunction · 0.85

Tested by

no test coverage detected