Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10352669
structured-array.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
structured-array.ts
View Options
import
{
Context
}
from
"koa"
;
import
{
Field
as
SealiousField
,
FieldTypes
as
SealiousFieldTypes
,
FieldsetInput
,
}
from
"sealious"
;
import
{
FormDataValue
}
from
"../form-types.js"
;
import
{
FormField
}
from
"./field.js"
;
import
{
Table
as
TableControl
}
from
"../controls/table.js"
;
import
{
sealiousToFormField
,
SealiousToFormField
,
}
from
"./get-field-for-sealious.js"
;
import
{
FormControlContext
}
from
"../controls/form-control.js"
;
import
{
Stringifiable
}
from
"tempstream/@types/stringify.js"
;
import
{
ExtractedFieldInfo
}
from
"../../utils/extract-fields-from-collection.js"
;
import
{
Table
}
from
"./table.js"
;
export
class
StructuredArray
<
SealiousFields
extends
Record
<
string
,
SealiousField
<
unknown
>>
,
FormFields
extends
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
=
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
>
extends
Table
<
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
>
{
public
sealious_field
:
SealiousFieldTypes
.
StructuredArray
<
SealiousFields
>
;
constructor
(
sealious_field
:
SealiousFieldTypes
.
StructuredArray
<
SealiousFields
>
)
{
const
columns
=
Object
.
fromEntries
(
Object
.
entries
(
sealious_field
.
subfields
).
map
(
([
key
,
sealious_field
])
=>
[
key
,
sealiousToFormField
(
sealious_field
),
]
)
)
as
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
};
super
(
columns
);
this
.
sealious_field
=
sealious_field
;
}
getControl
()
:
TableControl
<
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
>
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return
new
TableControl
<
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
>
(
this
as
any
,
{
label
:
this
.
name
,
render_fields
:
Object
.
fromEntries
(
Object
.
entries
(
this
.
sealious_field
.
subfields
).
map
(
([
column_name
,
subfield
])
=>
[
column_name
as
keyof
SealiousFields
,
(
fctx
,
name
,
value
)
=>
sealiousToFormField
(
subfield
)
.
getControl
()
.
render
(
fctx
),
]
)
)
as
{
[
field_name
in
keyof
FormFields
]
:
(
fctx
:
FormControlContext
,
name
:
string
,
value
:
string
)
=>
Stringifiable
|
Promise
<
Stringifiable
>
;
},
allow_adding
:
true
,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
make_new_row
:
()
=>
({}
as
any
),
});
}
generateFieldDeclaration
(
field_info
:
ExtractedFieldInfo
,
vars
:
{
form_field_types
:
string
;
sealious_field
:
string
}
)
:
string
{
return
`new
${
vars
.
form_field_types
}
.
${
this
.
constructor
.
name
}
(
${
vars
.
sealious_field
}
)`
;
}
async
getSealiousCreateValue
(
fctx
:
FormControlContext
)
:
Promise
<
SealiousFieldTypes
.
ArrayStorageInput
<
FieldsetInput
<
SealiousFields
>>
>
{
const
{
parsed
}
=
await
this
.
getParsedValue
(
fctx
.
ctx
,
fctx
.
data
);
return
(
(
parsed
as
SealiousFieldTypes
.
ArrayStorageInput
<
FieldsetInput
<
SealiousFields
>
>
)
||
this
.
getEmptyValue
()
);
}
async
sealiousValueToForm
(
ctx
:
Context
,
sealiousValue
:
Record
<
string
,
FormDataValue
>
[]
|
null
)
:
Promise
<
FormDataValue
>
{
return
Promise
.
all
(
(
sealiousValue
||
[]).
map
(
async
(
element
)
=>
Object
.
fromEntries
(
await
Promise
.
all
(
Object
.
entries
(
element
).
map
(
async
([
key
,
value
])
=>
{
const
sealious_subfield
=
this
.
sealious_field
.
subfields
[
key
];
const
form_subfield
=
sealiousToFormField
(
sealious_subfield
);
return
[
key
,
form_subfield
.
sealiousValueToForm
(
ctx
,
sealiousValue
),
];
})
)
)
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sun, Nov 2, 17:55 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1029146
Default Alt Text
structured-array.ts (3 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment