Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010597
structured-array.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-array.ts
View Options
import
{
predicates
}
from
"@sealcode/ts-predicates"
;
import
type
Field
from
"../../../chip-types/field.js"
;
import
{
App
,
Collection
,
Context
,
Fieldset
,
FieldsetInput
,
}
from
"../../../main.js"
;
import
{
ArrayStorage
}
from
"./array-storage.js"
;
export
class
StructuredArray
<
Subfields
extends
Record
<
string
,
Field
<
any
>>
>
extends
ArrayStorage
<
FieldsetInput
<
Subfields
>>
{
typeName
=
"structured-array"
;
constructor
(
public
subfields
:
Subfields
)
{
super
(
predicates
.
object
);
}
async
init
(
app
:
App
,
collection
:
Collection
)
:
Promise
<
void
>
{
await
super
.
init
(
app
,
collection
);
await
Promise
.
all
(
Object
.
values
(
this
.
subfields
).
map
((
subfield
)
=>
subfield
.
init
(
app
,
collection
)
)
);
}
async
getEmptyElement
()
{
return
{}
as
FieldsetInput
<
Subfields
>
;
}
async
isProperElement
(
context
:
Context
,
element
:
unknown
,
index
:
number
)
:
Promise
<
{
valid
:
boolean
;
reason
:
string
}
>
{
const
orig_result
=
await
super
.
isProperElement
(
context
,
element
,
index
);
if
(
!
orig_result
.
valid
)
{
return
orig_result
;
}
const
obj
=
element
as
FieldsetInput
<
Subfields
>
;
const
fieldset
=
new
Fieldset
(
this
.
subfields
);
fieldset
.
setMultiple
(
obj
as
any
);
const
result
=
await
fieldset
.
validate
(
context
,
new
Fieldset
(
this
.
subfields
),
true
);
if
(
result
.
valid
)
{
return
{
valid
:
true
,
reason
:
"no validation errors"
};
}
else
{
return
{
valid
:
false
,
reason
:
JSON
.
stringify
(
Object
.
fromEntries
(
Object
.
entries
(
result
.
errors
).
map
(([
key
,
value
])
=>
[
`[
${
index
}
]
${
key
}
`
,
value
,
])
)
),
};
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:44 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
661981
Default Alt Text
structured-array.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment