Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188031
structured.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
structured.ts
View Options
import
{
JDDContext
}
from
".."
;
import
{
ComponentArgument
,
ExtractComponentArgumentValue
,
}
from
"./component-argument"
;
export
class
Structured
<
T
extends
Record
<
string
,
ComponentArgument
<
unknown
>>
>
extends
ComponentArgument
<
{
[
property
in
keyof
T
]
:
ExtractComponentArgumentValue
<
T
[
property
]
>
;
}
>
{
constructor
(
public
structure
:
T
)
{
super
();
Object
.
values
(
structure
).
forEach
((
arg
)
=>
(
arg
.
parent_argument
=
this
));
}
getTypeName
()
{
return
"structured"
;
}
countWords
(
value
:
{
[
property
in
keyof
T
]
:
ExtractComponentArgumentValue
<
T
[
property
]
>
;
})
:
number
{
return
Object
.
entries
(
value
).
reduce
((
acc
,
[
key
,
val
])
=>
{
if
(
!
this
.
structure
[
key
])
{
console
.
warn
(
`Key
${
key
}
doesn't exist in structured argument`
);
return
acc
+
0
;
}
return
acc
+
this
.
structure
[
key
].
countWords
(
val
);
},
0
);
}
getEmptyValue
()
{
return
Object
.
fromEntries
(
Object
.
entries
(
this
.
structure
).
map
(([
name
,
arg
])
=>
[
name
,
arg
.
getEmptyValue
(),
])
)
as
{
[
property
in
keyof
T
]
:
ExtractComponentArgumentValue
<
T
[
property
]
>
;
};
}
async
getExampleValue
(
context
:
JDDContext
)
{
return
Object
.
fromEntries
(
await
Promise
.
all
(
Object
.
entries
(
this
.
structure
).
map
(
async
([
name
,
arg
])
=>
[
name
,
await
arg
.
getExampleValue
(
context
),
])
)
)
as
{
[
property
in
keyof
T
]
:
ExtractComponentArgumentValue
<
T
[
property
]
>
;
};
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Jul 8, 07:50 (17 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
810422
Default Alt Text
structured.ts (1 KB)
Attached To
Mode
rJDD jdd
Attached
Detach File
Event Timeline
Log In to Comment