mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
@@ -153,10 +153,12 @@ export default function useMonacoCustomizations({
|
||||
return;
|
||||
} else {
|
||||
const jsonInput = jsonInputForTargetLanguage("typescript");
|
||||
console.log("jsonInput", jsonInput);
|
||||
await jsonInput.addSource({
|
||||
name: interfaceName,
|
||||
samples,
|
||||
});
|
||||
|
||||
const inputData = new InputData();
|
||||
inputData.addInput(jsonInput);
|
||||
const result = await quicktype({
|
||||
@@ -187,64 +189,57 @@ export default function useMonacoCustomizations({
|
||||
console.error("Could not set secret definitions: ", error);
|
||||
}
|
||||
};
|
||||
const setBaseDefinitions = (monaco, columns) => {
|
||||
const rowDefinition =
|
||||
[
|
||||
Object.keys(columns).map((columnKey: string) => {
|
||||
const column = columns[columnKey];
|
||||
const type = getColumnType(column);
|
||||
if (type === "JSON") {
|
||||
console.log("adding json field definition");
|
||||
const interfaceName =
|
||||
columnKey[0].toUpperCase() + columnKey.slice(1);
|
||||
addJsonFieldDefinition(columnKey, interfaceName);
|
||||
const def = `static "${columnKey}": ${interfaceName}`;
|
||||
return def;
|
||||
}
|
||||
return `static "${columnKey}": ${getFieldProp("dataType", type)}`;
|
||||
}),
|
||||
].join(";\n") + ";";
|
||||
|
||||
const availableFields = Object.keys(columns)
|
||||
.map((columnKey: string) => `"${columnKey}"`)
|
||||
.join("|\n");
|
||||
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(
|
||||
["/**", " * extensions type configuration", " */", extensionsDefs].join(
|
||||
"\n"
|
||||
),
|
||||
"ts:filename/extensions.d.ts"
|
||||
);
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(
|
||||
[
|
||||
"// basic types that are used in all places",
|
||||
"declare var require: any;",
|
||||
"declare var Buffer: any;",
|
||||
"const ref: FirebaseFirestore.DocumentReference;",
|
||||
"const storage: firebasestorage.Storage;",
|
||||
"const db: FirebaseFirestore.Firestore;",
|
||||
"const auth: firebaseauth.BaseAuth;",
|
||||
`type Row = {${rowDefinition}};`,
|
||||
`type Field = ${availableFields} | string | object;`,
|
||||
`type Fields = Field[];`,
|
||||
].join("\n"),
|
||||
"ts:filename/rowFields.d.ts"
|
||||
);
|
||||
};
|
||||
// Set row definitions
|
||||
useEffect(() => {
|
||||
if (!monaco || !rowyRun || !tableState?.columns) return;
|
||||
try {
|
||||
const rowDefinition =
|
||||
Object.keys(tableState.columns)
|
||||
.map((columnKey: string) => {
|
||||
const column = tableState.columns[columnKey];
|
||||
if (getColumnType(column) === "JSON") {
|
||||
const interfaceName =
|
||||
columnKey[0].toUpperCase() + columnKey.slice(1);
|
||||
addJsonFieldDefinition(columnKey, interfaceName);
|
||||
return `static "${columnKey}": ${interfaceName}`;
|
||||
}
|
||||
return `static "${columnKey}": ${getFieldProp(
|
||||
"dataType",
|
||||
column.type
|
||||
)}`;
|
||||
})
|
||||
.join(";\n") + ";";
|
||||
|
||||
const availableFields = Object.keys(tableState.columns)
|
||||
.map((columnKey: string) => `"${columnKey}"`)
|
||||
.join("|\n");
|
||||
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(
|
||||
[
|
||||
"/**",
|
||||
" * extensions type configuration",
|
||||
" */",
|
||||
"// basic types that are used in all places",
|
||||
`type Row = {${rowDefinition}};`,
|
||||
`type Field = ${availableFields} | string | object;`,
|
||||
`type Fields = Field[];`,
|
||||
extensionsDefs,
|
||||
].join("\n"),
|
||||
"ts:filename/extensions.d.ts"
|
||||
);
|
||||
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(
|
||||
[
|
||||
"declare var require: any;",
|
||||
"declare var Buffer: any;",
|
||||
"const ref: FirebaseFirestore.DocumentReference;",
|
||||
"const storage: firebasestorage.Storage;",
|
||||
"const db: FirebaseFirestore.Firestore;",
|
||||
"const auth: firebaseauth.BaseAuth;",
|
||||
"declare class row {",
|
||||
" /**",
|
||||
" * Returns the row fields",
|
||||
" */",
|
||||
rowDefinition,
|
||||
"}",
|
||||
].join("\n"),
|
||||
"ts:filename/rowFields.d.ts"
|
||||
);
|
||||
setBaseDefinitions(monaco, tableState.columns);
|
||||
} catch (error) {
|
||||
console.error("Could not set row definitions: ", error);
|
||||
console.error("Could not set basic", error);
|
||||
}
|
||||
// set available secrets from secretManager
|
||||
try {
|
||||
|
||||
@@ -55,20 +55,29 @@ export const triggerTypes: ExtensionTrigger[] = ["create", "update", "delete"];
|
||||
const extensionBodyTemplate = {
|
||||
task: `const extensionBody: TaskBody = async({row, db, change, ref}) => {
|
||||
// task extensions are very flexible you can do anything from updating other documents in your database, to making an api request to 3rd party service.
|
||||
|
||||
// eg:
|
||||
// const got = require('got');
|
||||
// const {body} = await got.post('https://httpbin.org/anything', {
|
||||
// json: {
|
||||
// hello: 'world'
|
||||
// },
|
||||
// responseType: 'json'
|
||||
// });
|
||||
|
||||
// console.log(body.data);
|
||||
// => {hello: 'world'}
|
||||
|
||||
console.log("Task Extension completed.")
|
||||
|
||||
// example:
|
||||
// we can post notification to different discord channels based on row data
|
||||
/*
|
||||
const topic = row.topic;
|
||||
const channel = await db.collection('discordChannels').doc(topic).get();
|
||||
const channelUrl = await channel.get("channelUrl");
|
||||
const content = "Hello discord channel";
|
||||
return fetch("https://discord.com/api/webhooks/"+channelUrl, {
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content
|
||||
})
|
||||
}).then(async resp => {
|
||||
const result = await resp.json()
|
||||
if (resp.ok) console.info(result)
|
||||
else console.error(result)
|
||||
})
|
||||
*/
|
||||
}`,
|
||||
docSync: `const extensionBody: DocSyncBody = async({row, db, change, ref}) => {
|
||||
// feel free to add your own code logic here
|
||||
|
||||
Reference in New Issue
Block a user