grafast
Version:
Cutting edge GraphQL planning and execution engine
61 lines • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoalesceStep = void 0;
exports.coalesce = coalesce;
const constants_ts_1 = require("../constants.js");
const step_ts_1 = require("../step.js");
const constant_ts_1 = require("./constant.js");
const ube0 = () => null;
const ube1 = (_info, a) => a ?? null;
const ube2 = (_info, a, b) => a ?? b ?? null;
const ube3 = (_info, a, b, c) => a ?? b ?? c ?? null;
const ube4 = (_info, a, b, c, d) => a ?? b ?? c ?? d ?? null;
class CoalesceStep extends step_ts_1.UnbatchedStep {
static { this.$$export = {
moduleName: "grafast",
exportName: "CoalesceStep",
}; }
constructor(steps) {
super();
this.isSyncAndSafe = true;
this.allowMultipleOptimizations = true;
for (const step of steps) {
this.addDataDependency({
step,
acceptFlags: constants_ts_1.FLAG_INHIBITED | constants_ts_1.FLAG_NULL,
});
}
}
finalize() {
// Use optimal callback functions rather than looping
const l = this.dependencies.length;
if (l === 0)
this.unbatchedExecute = ube0;
else if (l === 1)
this.unbatchedExecute = ube1;
else if (l === 2)
this.unbatchedExecute = ube2;
else if (l === 3)
this.unbatchedExecute = ube3;
else if (l === 4)
this.unbatchedExecute = ube4;
else {
// Keep default
}
super.finalize();
}
unbatchedExecute(_info, ...values) {
return values.find((v) => v != null) ?? null;
}
}
exports.CoalesceStep = CoalesceStep;
function coalesce(...input) {
const list = Array.isArray(input[0])
? input[0]
: input;
if (list.length === 0) {
return (0, constant_ts_1.constant)(null);
}
return new CoalesceStep(list);
}
//# sourceMappingURL=coalesce.js.map