Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1374861
collection-field.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
collection-field.ts
View Options
import
{
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
Context
}
from
"koa"
;
import
{
Depromisify
,
ExtractFieldDecoded
,
Field
}
from
"sealious"
;
import
{
FormDataValue
}
from
"../form-types.js"
;
import
{
FieldParseResult
,
FormField
,
FormFieldValidationResponse
,
}
from
"./field.js"
;
export
class
CollectionField
<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
F
extends
Field
<
any
>
,
Required
extends
boolean
>
extends
FormField
<
Required
,
ExtractFieldDecoded
<
F
>
|
null
>
{
constructor
(
required
:
Required
,
public
sealiousField
:
F
)
{
super
(
required
);
}
predicate
=
predicates
.
unknown
;
async
parse
(
ctx
:
Context
,
raw_value
:
FormDataValue
)
:
Promise
<
FieldParseResult
<
ExtractFieldDecoded
<
F
>
|
null
>>
{
if
(
raw_value
===
undefined
)
{
return
{
parsable
:
true
,
parsed_value
:
null
,
error
:
null
};
}
const
encoded_value
=
(
await
this
.
sealiousField
.
encode
(
ctx
.
$context
,
raw_value
))
as
Depromisify
<
ReturnType
<
F
[
"encode"
]
>>
;
const
parsed_value
=
(
await
this
.
sealiousField
.
decode
(
ctx
.
$context
,
encoded_value
,
null
,
this
.
sealiousField
.
typeName
==
"text"
?
"original"
:
{}
))
as
ExtractFieldDecoded
<
F
>
;
return
{
parsable
:
true
,
error
:
null
,
parsed_value
,
};
}
public
async
isValueValid
(
ctx
:
Context
,
value
:
ExtractFieldDecoded
<
F
>
)
:
Promise
<
FormFieldValidationResponse
>
{
const
{
valid
,
reason
}
=
await
this
.
sealiousField
.
checkValue
(
ctx
.
$context
,
value
,
undefined
,
null
);
return
{
valid
,
message
:
reason
||
(
!
valid
?
"Wrong value"
:
""
)
};
}
public
getEmptyValue
()
:
ExtractFieldDecoded
<
F
>
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return
""
as
unknown
as
ExtractFieldDecoded
<
F
>
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Feb 25, 15:23 (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
610592
Default Alt Text
collection-field.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment