Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22396231
get-field-for-sealious.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
11 KB
Referenced Files
None
Subscribers
None
get-field-for-sealious.ts
View Options
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import
{
Collection
,
Field
as
SealiousField
,
FieldTypes
as
SealiousFieldTypes
,
RequiredField
as
SealiousRequiredField
,
}
from
"sealious"
;
import
{
Boolean
as
BooleanField
}
from
"./boolean.js"
;
import
{
SimpleFormField
,
TextBasedSimpleField
}
from
"./simple-form-field.js"
;
import
{
File
}
from
"./file.js"
;
import
{
CollectionField
}
from
"./collection-field.js"
;
import
{
StructuredArray
as
StructuredArrayField
}
from
"./structured-array.js"
;
import
{
Color
}
from
"./color.js"
;
import
{
DateField
}
from
"./date.js"
;
import
{
DateTime
}
from
"./datetime.js"
;
import
{
EmailField
}
from
"./email.js"
;
import
{
Float
}
from
"./float.js"
;
import
{
HTML
}
from
"./html.js"
;
import
{
Int
}
from
"./int.js"
;
import
{
JSONField
}
from
"./json.js"
;
import
{
Password
}
from
"./password.js"
;
import
{
Text
}
from
"./text.js"
;
import
{
Markdown
}
from
"./markdown.js"
;
import
{
DeepReverseSingleReferenceTable
}
from
"./deep-reverse-single-reference-table.js"
;
import
{
DeepReverseSingleReferenceList
}
from
"./deep-reverse-single-reference-list.js"
;
import
{
Coordinates
}
from
"./coordinates.js"
;
import
{
SimpleInput
}
from
"../controls/simple-input.js"
;
import
{
FormField
}
from
"./field.js"
;
import
{
PickFromListSealious
}
from
"./pick-from-list-sealious.js"
;
import
{
SingleReference
}
from
"./single-reference.js"
;
import
extract_fields_from_collection
,
{
ExtractedFieldInfo
,
}
from
"../../utils/extract-fields-from-collection.js"
;
import
{
EnumMultipleSealious
}
from
"./enum-multiple-sealious.js"
;
import
{
URLField
}
from
"./url.js"
;
import
{
Image
}
from
"./image.js"
;
import
{
PhoneNumberWithCountryCode
}
from
"./phone-number-with-country-code.js"
;
import
{
ItemDraft
}
from
"./item-draft.js"
;
export
type
SealiousToFormField
<
T
>
=
T
extends
SealiousFieldTypes
.
Boolean
?
BooleanField
<
false
>
:
T
extends
SealiousFieldTypes
.
Color
?
Color
<
false
>
:
T
extends
SealiousFieldTypes
.
ControlAccess
<
infer
R
>
?
SealiousToFormField
<
R
>
:
T
extends
SealiousFieldTypes
.
Date
?
DateField
<
false
>
:
T
extends
SealiousFieldTypes
.
DateTime
?
DateTime
<
false
>
:
T
extends
SealiousFieldTypes
.
DeepReverseSingleReference
?
DeepReverseSingleReferenceList
|
DeepReverseSingleReferenceTable
:
T
extends
SealiousFieldTypes
.
DisallowUpdate
<
any
,
any
,
any
,
infer
R
>
?
SealiousToFormField
<
R
>
:
T
extends
SealiousFieldTypes
.
Email
?
EmailField
<
false
>
:
T
extends
SealiousFieldTypes
.
Enum
<
any
>
?
PickFromListSealious
<
false
>
:
T
extends
SealiousFieldTypes
.
EnumMultiple
<
infer
R
>
?
R
extends
string
[]
?
EnumMultipleSealious
<
R
>
:
TextBasedSimpleField
<
false
>
:
T
extends
SealiousFieldTypes
.
File
?
File
<
false
>
:
T
extends
SealiousFieldTypes
.
Float
?
Float
<
false
>
:
T
extends
SealiousFieldTypes
.
HTML
?
HTML
<
false
>
:
T
extends
SealiousFieldTypes
.
Image
?
Image
<
false
>
:
T
extends
SealiousFieldTypes
.
Int
?
Int
<
false
>
:
T
extends
SealiousFieldTypes
.
ItemDraft
<
infer
C
extends
Collection
>
?
ItemDraft
<
C
>
:
T
extends
SealiousFieldTypes
.
JsonObject
?
JSONField
<
false
>
:
T
extends
SealiousFieldTypes
.
JDD
?
TextBasedSimpleField
<
false
,
SimpleInput
>
:
T
extends
SealiousFieldTypes
.
Password
?
Password
<
false
>
:
T
extends
SealiousFieldTypes
.
PhoneNumber
?
PhoneNumberWithCountryCode
<
false
>
:
T
extends
SealiousFieldTypes
.
ReverseSingleReference
?
TextBasedSimpleField
<
false
,
SimpleInput
>
:
T
extends
SealiousFieldTypes
.
SecretToken
?
TextBasedSimpleField
<
false
,
SimpleInput
>
:
T
extends
SealiousFieldTypes
.
SettableBy
<
infer
R
>
?
SealiousToFormField
<
R
>
:
T
extends
SealiousFieldTypes
.
SingleReference
?
SingleReference
<
Collection
,
boolean
,
T
>
:
T
extends
SealiousFieldTypes
.
Text
?
Text
<
false
>
:
T
extends
SealiousFieldTypes
.
Username
?
CollectionField
<
SealiousFieldTypes
.
Username
,
false
>
:
T
extends
SealiousFieldTypes
.
ValueExistingInCollection
?
SimpleFormField
<
false
>
:
T
extends
SealiousFieldTypes
.
ValueNotExistingInCollection
?
SimpleFormField
<
false
>
:
T
extends
SealiousRequiredField
<
any
,
any
,
any
>
?
SimpleFormField
<
false
>
:
T
extends
SealiousFieldTypes
.
Url
?
URLField
<
false
>
:
T
extends
SealiousFieldTypes
.
Money
?
SimpleFormField
<
false
>
:
T
extends
SealiousFieldTypes
.
Markdown
?
Markdown
<
false
>
:
T
extends
SealiousFieldTypes
.
Coordinates
?
Coordinates
<
false
>
:
T
extends
SealiousFieldTypes
.
StructuredArray
<
infer
R
>
?
StructuredArrayField
<
R
>
:
TextBasedSimpleField
<
any
>
;
export
function
sealiousToFormField
<
SF
extends
SealiousField
<
any
>>
(
sealious_field
:
SF
)
:
SealiousToFormField
<
SF
>
{
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Boolean
)
{
return
new
BooleanField
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Color
)
{
return
new
Color
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
ControlAccess
)
{
const
target_field
=
sealious_field
.
virtual_field
;
return
sealiousToFormField
(
target_field
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Date
)
{
return
new
DateField
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
DateTime
)
{
return
new
DateTime
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
DeepReverseSingleReference
)
{
const
referencing_collection
=
sealious_field
.
collection
.
app
.
collections
[
sealious_field
.
referencing_collection
];
if
(
!
referencing_collection
)
{
throw
new
Error
(
"Unknown collection: "
+
sealious_field
.
referencing_collection
);
}
if
(
Object
.
keys
(
referencing_collection
.
fields
).
length
==
2
)
{
return
new
DeepReverseSingleReferenceList
(
sealious_field
)
as
SealiousToFormField
<
SF
>
;
}
else
{
return
new
DeepReverseSingleReferenceTable
(
sealious_field
)
as
SealiousToFormField
<
SF
>
;
}
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
DisallowUpdate
)
{
return
sealiousToFormField
(
sealious_field
.
virtual_field
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Email
)
{
return
new
EmailField
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Enum
)
{
return
new
PickFromListSealious
(
sealious_field
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
EnumMultiple
)
{
return
new
EnumMultipleSealious
(
sealious_field
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
File
)
{
return
new
File
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Float
)
{
return
new
Float
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
HTML
)
{
return
new
HTML
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Image
)
{
return
new
Image
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Int
)
{
return
new
Int
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
ItemDraft
)
{
return
new
ItemDraft
(
sealious_field
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
JsonObject
)
{
return
new
JSONField
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Password
)
{
return
new
Password
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
PhoneNumber
)
{
return
new
PhoneNumberWithCountryCode
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
SettableBy
)
{
return
sealiousToFormField
(
sealious_field
.
virtual_field
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
SingleReference
)
{
return
new
SingleReference
(
false
,
sealious_field
)
as
unknown
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Text
)
{
return
new
Text
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Username
)
{
return
new
Text
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Url
)
{
return
new
URLField
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Money
)
{
return
new
Float
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Markdown
)
{
return
new
Markdown
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
Coordinates
)
{
return
new
Coordinates
(
sealious_field
.
required
)
as
SealiousToFormField
<
SF
>
;
}
if
(
sealious_field
instanceof
SealiousFieldTypes
.
StructuredArray
)
{
return
new
StructuredArrayField
(
sealious_field
)
as
SealiousToFormField
<
SF
>
;
}
return
new
TextBasedSimpleField
(
false
)
as
SealiousToFormField
<
SF
>
;
}
export
async
function
sealiousFieldInfoToFormField
(
field_info
:
ExtractedFieldInfo
)
:
Promise
<
FormField
>
{
switch
(
field_info
.
type
)
{
case
"boolean"
:
return
new
BooleanField
(
field_info
.
is_required
);
case
"color"
:
return
new
Color
(
field_info
.
is_required
);
case
"date"
:
return
new
DateField
(
field_info
.
is_required
);
case
"datetime"
:
return
new
DateTime
(
field_info
.
is_required
);
case
"deep-reverse-single-reference"
:
{
const
referencing_fields
=
await
extract_fields_from_collection
(
field_info
.
referencing_collection
as
string
);
if
(
referencing_fields
.
length
==
2
)
{
return
new
DeepReverseSingleReferenceList
({}
as
any
);
}
else
{
return
new
DeepReverseSingleReferenceTable
({}
as
any
);
}
}
case
"email"
:
return
new
EmailField
(
field_info
.
is_required
);
case
"enum"
:
return
new
PickFromListSealious
({}
as
any
);
case
"enum-multiple"
:
return
new
EnumMultipleSealious
({}
as
any
);
case
"file"
:
return
new
File
(
field_info
.
is_required
);
case
"float"
:
return
new
Float
(
field_info
.
is_required
);
case
"html"
:
return
new
HTML
(
field_info
.
is_required
);
case
"image"
:
return
new
Image
(
field_info
.
is_required
);
case
"int"
:
return
new
Int
(
field_info
.
is_required
);
case
"item-draft"
:
return
new
ItemDraft
({
target_collection
:
{
fields
:
{}
}
}
as
any
);
case
"json-object"
:
return
new
JSONField
(
field_info
.
is_required
);
case
"password"
:
return
new
Password
(
field_info
.
is_required
);
case
"phone-number"
:
return
new
PhoneNumberWithCountryCode
(
field_info
.
is_required
);
case
"single-reference"
:
return
new
SingleReference
(
false
,
{}
as
any
);
case
"text"
:
return
new
Text
(
field_info
.
is_required
);
case
"username"
:
return
new
Text
(
field_info
.
is_required
);
case
"url"
:
return
new
URLField
(
field_info
.
is_required
);
case
"money"
:
return
new
Float
(
field_info
.
is_required
);
case
"markdown"
:
return
new
Markdown
(
field_info
.
is_required
);
case
"coordinates"
:
return
new
Coordinates
(
field_info
.
is_required
);
case
"structured-array"
:
// we don't need the full thing at this point, so we don't fill in the subfields
return
new
StructuredArrayField
(
new
SealiousFieldTypes
.
StructuredArray
({})
);
default
:
return
new
TextBasedSimpleField
(
false
);
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 16:39 (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1198076
Default Alt Text
get-field-for-sealious.ts (11 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline