Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010506
extract-fields-from-collection.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
extract-fields-from-collection.ts
View Options
import
_locreq
from
"locreq"
;
import
{
exec
}
from
"./utils.js"
;
const
target_locreq
=
_locreq
(
process
.
cwd
());
import
{
promises
as
fs
}
from
"fs"
;
import
{
is
,
predicates
}
from
"@sealcode/ts-predicates"
;
export
default
async
function
extract_fields_from_collection
(
collection_name
:
string
)
:
Promise
<
{
name
:
string
;
type
:
string
}[]
>
{
const
extractor_code
=
`import {default as the_app} from "./app.js";
const c = new the_app().collections["
${
collection_name
}
"];
const fields = [];
for (const field_name in c.fields){
const field = c.fields[field_name];
let type = field.typeName;
if(["derived-value", "cached-value"].includes(type)){
type = field.virtual_field.typeName
}
fields.push({name: field_name, type})
}
console.log(JSON.stringify(fields));
`
;
const
extractor_code_path
=
target_locreq
.
resolve
(
"dist/back/___extract_fields.js"
);
await
fs
.
writeFile
(
extractor_code_path
,
extractor_code
);
const
{
stdout
}
=
await
exec
(
"node"
,
[
extractor_code_path
]);
await
fs
.
unlink
(
extractor_code_path
);
const
ret
=
JSON
.
parse
(
stdout
)
as
unknown
;
if
(
!
is
(
ret
,
predicates
.
array
(
predicates
.
shape
({
name
:
predicates
.
string
,
type
:
predicates
.
string
,
})
)
)
)
{
throw
new
Error
(
"Encountered a problem while extracting the names of fields from collection. Got: "
+
stdout
);
}
return
ret
;
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:43 (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
630319
Default Alt Text
extract-fields-from-collection.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment