Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9582922
event-matchers.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
event-matchers.ts
View Options
import
{
ActionName
}
from
"../action"
;
import
assert
from
"assert"
;
export
type
When
=
"before"
|
"after"
;
export
type
MatcherParams
=
{
when
:
When
;
subject_path
:
RegExp
;
action
:
ActionName
|
ActionName
[];
};
export
class
EventMatcher
{
when
:
When
;
subject_path
:
RegExp
;
actions
:
ActionName
[];
collection_name
:
null
|
string
;
constructor
({
when
,
subject_path
=
/.*/
,
action
}
:
MatcherParams
)
{
if
(
arguments
[
0
]
instanceof
EventMatcher
)
{
return
arguments
[
0
];
}
assert
.
equal
(
typeof
when
,
"string"
);
assert
(
subject_path
instanceof
RegExp
);
assert
(
typeof
action
===
"string"
||
Array
.
isArray
(
action
));
this
.
when
=
when
;
this
.
subject_path
=
subject_path
;
if
(
Array
.
isArray
(
action
))
{
this
.
actions
=
action
;
}
else
{
this
.
actions
=
[
action
];
}
}
containsAction
(
action_name
:
ActionName
)
{
return
this
.
actions
.
includes
(
action_name
);
}
}
export
class
Collection
extends
EventMatcher
{
collection_name
:
string
;
constructor
({
when
,
collection_name
,
action
,
}
:
Pick
<
MatcherParams
,
"when"
|
"action"
>
&
{
collection_name
:
string
})
{
super
({
when
,
subject_path
:
new
RegExp
(
`collections.
${
collection_name
}
`
),
action
,
});
assert
.
equal
(
typeof
collection_name
,
"string"
);
this
.
collection_name
=
collection_name
;
}
}
export
class
Resource
extends
EventMatcher
{
collection_name
:
string
;
constructor
({
when
,
collection_name
,
action
,
}
:
Pick
<
MatcherParams
,
"when"
|
"action"
>
&
{
collection_name
:
string
})
{
super
({
when
,
subject_path
:
new
RegExp
(
`collections.
${
collection_name
}
\\..*`
),
action
,
});
assert
.
equal
(
typeof
collection_name
,
"string"
);
this
.
collection_name
=
collection_name
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Oct 11, 08:11 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
984031
Default Alt Text
event-matchers.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment