Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010804
array-action.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
array-action.ts
View Options
import
{
hasShape
,
Predicate
,
Shape
,
ShapeToType
,
}
from
"@sealcode/ts-predicates"
;
import
type
Context
from
"../../../../context"
;
export
abstract
class
ArrayAction
<
InputShape
extends
Record
<
string
,
unknown
>
,
ParsedShape
extends
Record
<
string
,
unknown
>
>
{
constructor
(
public
element_predicate
:
Predicate
,
public
element_validator
:
(
context
:
Context
,
element
:
unknown
,
index
:
number
)
=>
Promise
<
{
valid
:
boolean
;
reason
:
string
;
}
>
)
{}
abstract
InputShape
:
Shape
;
async
validate
<
T
>
(
context
:
Context
,
action
:
unknown
,
array
:
T
[]
)
:
Promise
<
{
valid
:
boolean
;
reason
:
string
}
>
{
if
(
!
hasShape
(
this
.
InputShape
,
action
))
{
return
{
valid
:
false
,
reason
:
"Wrong action shape"
};
}
return
this
.
_validate
(
context
,
action
,
array
);
}
async
_validate
<
T
>
(
context
:
Context
,
action
:
ShapeToType
<
this
[
"InputShape"
]
>
,
array
:
T
[]
)
:
Promise
<
{
valid
:
boolean
;
reason
:
string
}
>
{
return
{
valid
:
true
,
reason
:
"Correct shape"
};
}
abstract
_parse
<
T
>
(
context
:
Context
,
input
:
InputShape
,
array
:
T
[],
empty_element
:
T
)
:
Promise
<
ParsedShape
|
null
>
;
abstract
run
<
T
>
(
context
:
Context
,
action
:
ParsedShape
,
array
:
T
[],
empty_element
:
T
)
:
Promise
<
T
[]
>
;
async
parse
<
T
>
(
context
:
Context
,
input
:
unknown
,
array
:
T
[],
empty_element
:
T
)
{
const
validate_result
=
await
this
.
validate
(
context
,
input
,
array
);
if
(
!
validate_result
.
valid
)
{
return
null
;
}
return
this
.
_parse
(
context
,
input
as
InputShape
,
array
,
empty_element
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:47 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
631164
Default Alt Text
array-action.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment