Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22397117
shared-crud-form-fields.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
shared-crud-form-fields.ts
View Options
import
{
toPascalCase
}
from
"js-convert-case"
;
import
extract_fields_from_collection
from
"../../utils/extract-fields-from-collection.js"
;
import
{
formatWithPrettier
}
from
"../../utils/prettier.js"
;
import
{
wrapAttribute
}
from
"../../utils/wrap-attributes.js"
;
export
async
function
sharedCrudFormFields
(
collection_name
:
string
)
{
const
collection_fields
=
await
extract_fields_from_collection
(
collection_name
);
const
uppercase_collection
=
toPascalCase
(
collection_name
);
const
result
=
`import { type Controls, Fields } from "@sealcode/sealgen";
import {
${
uppercase_collection
}
} from "src/back/collections/collections.js";
${
Array
.
from
(
new
Set
(
collection_fields
.
map
((
field_info
)
=>
field_info
.
form_field
.
generateImportsForFieldList
(
field_info
)
)
.
flat
()
.
map
(
({
what
,
from
,
as
}
) =>
`
import
{
$
{
what
}
$
{
as
?
` as
${
as
}
`
:
""
}
}
from
"${from}"
`
)
).values()
).join(";\n")}
export const
${
toPascalCase
(
collection_name
)
}
FormFields = <const>{
${
collection_fields
.
map
((
field_info
)
=>
{
return
`
${
field_info
.
name
}
:
${
field_info
.
form_field
.
generateFieldDeclaration
(
field_info
,
{
form_field_types
:
"Fields"
,
sealious_field
:
`
${
uppercase_collection
}
.fields
${
wrapAttribute
(
field_info
.
name
)
}
`
,
}
)}`
;
}
)
.join(",\n")}
};
const fields =
${
toPascalCase
(
collection_name
)
}
FormFields
export const get
${
toPascalCase
(
collection_name
)
}
FormControls: () => Controls.FormControl[] = () => [
${
collection_fields
.
map
(({
name
}
) => `
fields$
{
wrapAttribute
(
name
)}.
getControl
()
`)
.join(",\n")}
];
`
;
return
formatWithPrettier
(
result
);
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 17:06 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1199978
Default Alt Text
shared-crud-form-fields.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline