Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996418
map-reduce.ts
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
map-reduce.ts
View Options
import
{
App
,
Collection
,
CalculatedField
,
Item
,
SubjectPathEquiv
,
ActionName
,
Context
,
}
from
"../../../main"
;
type
ParamGetter
<
T
>
=
(
context
:
Context
,
item
:
Item
)
=>
Promise
<
T
>
|
T
;
type
ParamOrGetter
<
T
>
=
T
|
ParamGetter
<
T
>
;
type
MapReduceParams
<
ReturnType
,
IntermediateValue
=
any
>
=
{
source
:
{
subject_path
:
ParamOrGetter
<
SubjectPathEquiv
>
;
action_name
:
ParamOrGetter
<
ActionName
>
;
params
:
ParamOrGetter
<
any
>
;
};
map
:
(
items
:
Item
[])
=>
IntermediateValue
[];
reduce
:
[(
intermediate
:
IntermediateValue
[])
=>
ReturnType
,
any
];
};
export
default
class
MapReduce
<
ReturnType
,
IntermediateValue
>
extends
CalculatedField
<
ReturnType
>
{
name
=
"map-reduce"
;
params
:
MapReduceParams
<
ReturnType
,
IntermediateValue
>
;
constructor
(
app
:
App
,
collection
:
Collection
,
params
:
MapReduceParams
<
ReturnType
,
IntermediateValue
>
)
{
super
(
app
,
collection
);
this
.
params
=
params
;
}
async
calculate
(
context
:
Context
,
item
:
Item
)
{
const
action_arguments
=
[
context
,
this
.
params
.
source
.
subject_path
,
this
.
params
.
source
.
action_name
,
this
.
params
.
source
.
params
,
].
map
(
function
(
element
)
{
if
(
element
instanceof
Function
)
{
return
element
(
context
,
item
);
}
else
{
return
element
;
}
});
const
fulfilled_params
=
Promise
.
all
(
action_arguments
);
return
(
await
this
.
app
.
runAction
.
apply
(
App
,
fulfilled_params
))
.
map
(
this
.
params
.
map
)
.
reduce
(
this
.
params
.
reduce
[
0
],
this
.
params
.
reduce
[
1
]);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 14:02 (17 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557248
Default Alt Text
map-reduce.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment