Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010560
negate-stage.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
negate-stage.ts
View Options
import
type
{
MatchBody
}
from
"./query-stage.js"
;
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"
)
{
// in this case, the behavior for true and false is not symmetrical.
// We treat "unset" values as false. - see if.test.ts
if
(
stage
[
key
])
{
// negating a 'true' value - so we're matching both false and unset
negated_stage
[
key
]
=
{
$ne
:
true
};
}
else
{
// negating a 'false' value - so we're matching only true
negated_stage
[
key
]
=
true
;
}
}
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
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:44 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
632122
Default Alt Text
negate-stage.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment