Page MenuHomeSealhub

negate-stage.ts
No OneTemporary

negate-stage.ts

import type { MatchBody } from "./query-stage";
export default function negate_match(stage: MatchBody) {
const negated_stage: MatchBody = {};
for (const key in stage) {
if (key === "$or") {
negated_stage.$nor = stage.$or;
} else if (key === "$nor") {
negated_stage.$or = stage.$nor;
} else if (key === "$and") {
negated_stage.$or = stage.$and?.map((expression: MatchBody) =>
negate_match(expression)
);
} else {
if ((stage[key] as MatchBody).$not) {
negated_stage[key] = (stage[key] as MatchBody)
.$not as MatchBody;
} else if (typeof stage[key] == "boolean") {
negated_stage[key] = !stage[key];
} else if (typeof stage[key] !== "object") {
negated_stage[key] = { $not: { $eq: stage[key] } };
} else {
negated_stage[key] = { $not: stage[key] };
}
}
}
return negated_stage;
}

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:40 (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625678
Default Alt Text
negate-stage.ts (842 B)

Event Timeline