Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22399011
single-reference.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
single-reference.ts
View Options
import
{
Collection
,
ExtractFieldInput
,
FieldTypes
as
SealiousFieldTypes
,
}
from
"sealious"
;
import
{
CollectionField
}
from
"./collection-field.js"
;
import
{
SingleReferenceDropdown
}
from
"../controls/single-reference.js"
;
import
{
Context
}
from
"koa"
;
import
{
ExtractedFieldInfo
}
from
"../../utils/extract-fields-from-collection.js"
;
import
{
toPascalCase
}
from
"js-convert-case"
;
export
class
SingleReference
<
TargetCollection
extends
Collection
,
Required
extends
boolean
,
F
extends
SealiousFieldTypes
.
SingleReference
,
>
extends
CollectionField
<
F
,
Required
>
{
getControl
()
:
SingleReferenceDropdown
<
TargetCollection
,
F
,
Required
>
{
return
new
SingleReferenceDropdown
(
this
,
{
label
:
this
.
label
||
this
.
name
,
getLabel
:
(
item
)
=>
item
.
id
,
});
}
async
parsedToSealious
(
parsed
:
string
)
:
Promise
<
ExtractFieldInput
<
F
>>
{
return
(
parsed
||
""
)
as
ExtractFieldInput
<
F
>
;
}
async
sealiousValueToForm
(
_ctx
:
Context
,
value
:
string
|
null
)
{
return
value
||
undefined
;
}
generateImportsForFieldList
(
field_info
:
ExtractedFieldInfo
)
{
if
(
!
field_info
.
target
)
{
throw
new
Error
(
"Expected 'target' attribute in field info"
);
}
return
[
{
what
:
toPascalCase
(
field_info
.
target
),
from
:
"src/back/collections/collections.js"
,
},
];
}
generateFieldDeclaration
(
field_info
:
ExtractedFieldInfo
,
vars
:
{
form_field_types
:
string
;
sealious_field
:
string
}
)
:
string
{
if
(
!
field_info
.
target
)
{
throw
new
Error
(
"Expected 'target' attribute in field info"
);
}
return
`new
${
vars
.
form_field_types
}
.
${
this
.
constructor
.
name
}
<typeof
${
toPascalCase
(
field_info
.
target
)
}
,
${
String
(
field_info
.
is_required
)
}
, typeof
${
vars
.
sealious_field
}
>(
${
String
(
field_info
.
is_required
)
}
,
${
vars
.
sealious_field
}
)`
;
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 17:28 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1202246
Default Alt Text
single-reference.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline