Update packages, change to node16

This commit is contained in:
Lucas Costi
2022-04-05 10:05:12 +10:00
parent ab59b778e5
commit a8dd2c1169
542 changed files with 66325 additions and 65198 deletions

View File

@@ -1,46 +1,46 @@
module.exports = addHook
module.exports = addHook;
function addHook (state, kind, name, hook) {
var orig = hook
function addHook(state, kind, name, hook) {
var orig = hook;
if (!state.registry[name]) {
state.registry[name] = []
state.registry[name] = [];
}
if (kind === 'before') {
if (kind === "before") {
hook = function (method, options) {
return Promise.resolve()
.then(orig.bind(null, options))
.then(method.bind(null, options))
}
.then(method.bind(null, options));
};
}
if (kind === 'after') {
if (kind === "after") {
hook = function (method, options) {
var result
var result;
return Promise.resolve()
.then(method.bind(null, options))
.then(function (result_) {
result = result_
return orig(result, options)
result = result_;
return orig(result, options);
})
.then(function () {
return result
})
}
return result;
});
};
}
if (kind === 'error') {
if (kind === "error") {
hook = function (method, options) {
return Promise.resolve()
.then(method.bind(null, options))
.catch(function (error) {
return orig(error, options)
})
}
return orig(error, options);
});
};
}
state.registry[name].push({
hook: hook,
orig: orig
})
orig: orig,
});
}

View File

@@ -1,28 +1,27 @@
module.exports = register
module.exports = register;
function register (state, name, method, options) {
if (typeof method !== 'function') {
throw new Error('method for before hook must be a function')
function register(state, name, method, options) {
if (typeof method !== "function") {
throw new Error("method for before hook must be a function");
}
if (!options) {
options = {}
options = {};
}
if (Array.isArray(name)) {
return name.reverse().reduce(function (callback, name) {
return register.bind(null, state, name, callback, options)
}, method)()
return register.bind(null, state, name, callback, options);
}, method)();
}
return Promise.resolve()
.then(function () {
if (!state.registry[name]) {
return method(options)
}
return Promise.resolve().then(function () {
if (!state.registry[name]) {
return method(options);
}
return (state.registry[name]).reduce(function (method, registered) {
return registered.hook.bind(null, method, options)
}, method)()
})
return state.registry[name].reduce(function (method, registered) {
return registered.hook.bind(null, method, options);
}, method)();
});
}

View File

@@ -1,17 +1,19 @@
module.exports = removeHook
module.exports = removeHook;
function removeHook (state, name, method) {
function removeHook(state, name, method) {
if (!state.registry[name]) {
return
return;
}
var index = state.registry[name]
.map(function (registered) { return registered.orig })
.indexOf(method)
.map(function (registered) {
return registered.orig;
})
.indexOf(method);
if (index === -1) {
return
return;
}
state.registry[name].splice(index, 1)
state.registry[name].splice(index, 1);
}