Page MenuHomeSealhub

extract-fields-from-collection.ts
No OneTemporary

extract-fields-from-collection.ts

import _locreq from "locreq";
import { curryImportPath, exec } from "./utils.js";
const target_locreq = _locreq(process.cwd());
import { promises as fs } from "fs";
export default async function extract_fields_from_collection(
collection_name: string
): Promise<{ name: string; type: string }[]> {
const rel = curryImportPath(target_locreq.resolve("dist/back"));
const extractor_code = `import {default as Collection} from "${rel(
`./back/collections/${collection_name}.js`
)}";
const c = new Collection();
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);
return JSON.parse(stdout);
}

File Metadata

Mime Type
text/x-java
Expires
Fri, Jul 4, 08:37 (5 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
799871
Default Alt Text
extract-fields-from-collection.ts (1 KB)

Event Timeline