Hello,
I’m trying to make a pack that generates random content to populate the tables, but I’m running into errors :).
I don’t know much about JavaScript and I don’t understand the errors shown.
If any of you could help me, that would be cool.
Sincerely,
Thierry
P.S: Here are the errors given =>
We found some errors: Failed Typescript validation.
On line 1 Cannot find name ‘pack’.
On line 5 Cannot find name ‘coda’.
On line 6 Cannot find name ‘coda’.
On line 12 Cannot find name ‘coda’.
On line 10 Property ‘Table’ does not exist on type ‘typeof ParameterType’.
On line 21 Property ‘Table’ does not exist on type ‘typeof ValueType’.
On line 43 Property ‘random’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
On line 46 Property ‘random’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
On line 48 Property ‘Date’ does not exist on type ‘typeof ValueType’.
On line 49 Property ‘random’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
On line 52 Property ‘random’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
On line 65 Property ‘createTable’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
Translated with DeepL Translate: The world's most accurate translator (free version)
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.addFormula({
name: "Random Data Generator",
description: "Generates random data for a given table.",
parameters: [
coda.makeParameter({
type: coda.ParameterType.Table,
name: "GeneratorDatas",
description: "The table to generate random data for.",
}),
coda.makeParameter({
type: coda.ParameterType.Number,
name: "numRows",
description: "The number of rows of random data to generate.",
default: 10,
}),
],
resultType: coda.ValueType.Table,
execute: async function ([table, numRows]) {
// First, we get the column names and types of the input table
const columnNames = table.columns.map((c) => c.name);
const columnTypes = table.columns.map((c) => c.type);
// Next, we create an empty array to store the rows of random data
const rows = [];
// Then, we loop through the number of rows specified by the user
for (let i = 0; i < numRows; i++) {
// For each row, we create an empty object to store the cell values
const row = {};
// We then loop through the column names and types to generate random data for each cell
for (let j = 0; j < columnNames.length; j++) {
const columnName = columnNames[j];
const columnType = columnTypes[j];
// Depending on the column type, we generate the appropriate type of random data
switch (columnType) {
case coda.ValueType.String:
row[columnName] = coda.random.string();
break;
case coda.ValueType.Number:
row[columnName] = coda.random.number();
break;
case coda.ValueType.Date:
row[columnName] = coda.random.date();
break;
case coda.ValueType.Boolean:
row[columnName] = coda.random.boolean();
break;
default:
row[columnName] = null;
break;
}
}
// Finally, we add the row of random data to our array of rows
rows.push(row);
}
// Once all the rows have been generated, we create a new table with the same column names and types as the input table, and return it with the rows of random data
return coda.createTable(columnNames, columnTypes, rows);
},
});