Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188519
enum-multiple.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
enum-multiple.ts
View Options
import
{
is
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
Field
,
Context
}
from
"../../../main"
;
import
{
ArrayStorage
}
from
"./array-storage"
;
export
class
EnumMultiple
<
Values
extends
string
>
extends
ArrayStorage
<
Values
>
{
typeName
=
"enum-multiple"
;
constructor
(
public
allowed_values
:
Values
[]
|
((
context
:
Context
)
=>
Values
[])
)
{
super
(
predicates
.
string
);
}
async
getEmptyElement
(
context
:
Context
)
:
Promise
<
Values
>
{
return
(
await
this
.
getAllowedValues
(
context
))[
0
];
}
async
getAllowedValues
(
context
:
Context
)
:
Promise
<
Values
[]
>
{
if
(
typeof
this
.
allowed_values
===
"function"
)
{
return
this
.
allowed_values
(
context
);
}
else
{
return
this
.
allowed_values
;
}
}
async
isProperValue
(
ctx
:
Context
,
value
:
string
[])
{
if
(
!
is
(
value
,
predicates
.
array
(
predicates
.
string
)))
{
return
Field
.
invalid
(
"Not an array of strings"
);
}
const
allowed_values
=
await
this
.
getAllowedValues
(
ctx
);
const
bad_values
=
value
.
filter
(
(
v
)
=>
!
allowed_values
.
includes
(
v
as
Values
)
);
if
(
bad_values
.
length
)
{
return
Field
.
invalid
(
`Invalid values:
${
bad_values
.
join
(
","
)
}
`
);
}
return
Field
.
valid
();
}
async
encode
(
_
:
Context
,
value
:
Values
[])
{
return
value
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Jul 8, 08:14 (23 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
774144
Default Alt Text
enum-multiple.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment