@erdoai/cli 0.109.1 → 0.110.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +32 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1141,6 +1141,11 @@ var ErdoClient = class {
|
|
|
1141
1141
|
const qs = q.toString();
|
|
1142
1142
|
return this.request("GET", `/v1/datasets-purposes${qs ? `?${qs}` : ""}`);
|
|
1143
1143
|
}
|
|
1144
|
+
// Create an empty dataset with its declared columns. The server refuses a
|
|
1145
|
+
// create without a schema unless the purpose's columns are platform-defined.
|
|
1146
|
+
createDataset(input) {
|
|
1147
|
+
return this.request("POST", "/v1/datasets-create", input);
|
|
1148
|
+
}
|
|
1144
1149
|
ensureDataset(input) {
|
|
1145
1150
|
return this.request("POST", "/v1/datasets-ensure", input);
|
|
1146
1151
|
}
|
|
@@ -6502,15 +6507,37 @@ datasetsCmd.command("purposes").description(
|
|
|
6502
6507
|
fail(e);
|
|
6503
6508
|
}
|
|
6504
6509
|
});
|
|
6510
|
+
function readSchemaFile(path) {
|
|
6511
|
+
const parsed = JSON.parse(readFileSync4(path, "utf8"));
|
|
6512
|
+
const schema = Array.isArray(parsed) ? { columns: parsed } : parsed;
|
|
6513
|
+
if (!schema || !Array.isArray(schema.columns)) {
|
|
6514
|
+
throw new Error('--schema must contain a JSON columns array or {"columns": [...]} object');
|
|
6515
|
+
}
|
|
6516
|
+
return schema;
|
|
6517
|
+
}
|
|
6518
|
+
datasetsCmd.command("create <name>").description(
|
|
6519
|
+
"Create an empty dataset with its columns declared up front. Every write is checked against the schema, which is set now rather than taken from the first rows. --schema is required unless the purpose is one whose columns Erdo defines (page events, widget events, widget leads)."
|
|
6520
|
+
).option("--schema <file>", "JSON file containing { columns: [...] } or a columns array").option("--purpose <purpose>", "the dataset's role in the org vocabulary, e.g. leads (see `erdo datasets purposes`)").option("--purpose-description <text>", "what writes and reads this purpose").option("--description <text>", "what the dataset holds").option("--separate", "deliberately create a second dataset for a purpose the org already has").action(async (name, opts) => {
|
|
6521
|
+
try {
|
|
6522
|
+
const result = await new ErdoClient().createDataset({
|
|
6523
|
+
name,
|
|
6524
|
+
...opts.schema ? { schema: readSchemaFile(opts.schema) } : {},
|
|
6525
|
+
...opts.purpose ? { purpose: opts.purpose } : {},
|
|
6526
|
+
...opts.purposeDescription ? { purpose_description: opts.purposeDescription } : {},
|
|
6527
|
+
...opts.description ? { description: opts.description } : {},
|
|
6528
|
+
...opts.separate ? { separate_dataset: true } : {}
|
|
6529
|
+
});
|
|
6530
|
+
console.log(`${result.slug} created${result.purpose ? ` ${result.purpose}` : ""}`);
|
|
6531
|
+
for (const warning of result.warnings ?? []) console.error(`warning: ${warning}`);
|
|
6532
|
+
} catch (e) {
|
|
6533
|
+
fail(e);
|
|
6534
|
+
}
|
|
6535
|
+
});
|
|
6505
6536
|
datasetsCmd.command("ensure <purpose>").description(
|
|
6506
6537
|
"Create or reuse the one dataset for a purpose and verify its declared producer contract. Refuses legacy splits and incompatible populated datasets instead of choosing silently."
|
|
6507
6538
|
).requiredOption("--schema <file>", "JSON file containing { columns: [...] } or a columns array").option("--name <name>", "dataset name when creation is required").option("--description <text>", "dataset description when creation is required").option("--purpose-description <text>", "what writes and reads this purpose").option("--preferred-dataset <slug>", "existing bound dataset slug or id to adopt").option("--email-column <name>", "for a leads purpose: which declared column holds the email (default email)").option("--phone-column <name>", "for a leads purpose: which declared column holds the phone (default phone)").action(async (purpose, opts) => {
|
|
6508
6539
|
try {
|
|
6509
|
-
const
|
|
6510
|
-
const declaredSchema = Array.isArray(parsed) ? { columns: parsed } : parsed;
|
|
6511
|
-
if (!declaredSchema || !Array.isArray(declaredSchema.columns)) {
|
|
6512
|
-
throw new Error('--schema must contain a JSON columns array or {"columns": [...]} object');
|
|
6513
|
-
}
|
|
6540
|
+
const declaredSchema = readSchemaFile(opts.schema);
|
|
6514
6541
|
const result = await new ErdoClient().ensureDataset({
|
|
6515
6542
|
purpose,
|
|
6516
6543
|
...opts.name ? { name: opts.name } : {},
|