@orizm/cli 2.1.2 → 2.2.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/cli.cjs +66 -53
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +63 -50
- package/dist/cli.js.map +1 -1
- package/dist/config/index.cjs +1 -1
- package/dist/config/index.cjs.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/package.json +5 -3
package/dist/cli.cjs
CHANGED
|
@@ -163,7 +163,7 @@ function getPath(issue) {
|
|
|
163
163
|
for (let j = pathInfoIndex; j < pathInfo.length; j++) {
|
|
164
164
|
const pathItem = pathInfo[j];
|
|
165
165
|
if (pathItem.type === "array" && pathItem.key === index) {
|
|
166
|
-
if (pathItem.value && typeof pathItem.value === "object" && "name" in pathItem.value) {
|
|
166
|
+
if (pathItem.value != null && typeof pathItem.value === "object" && "name" in pathItem.value) {
|
|
167
167
|
pathParts[i] = String(pathItem.value.name);
|
|
168
168
|
pathInfoIndex = j + 1;
|
|
169
169
|
break;
|
|
@@ -213,7 +213,7 @@ var client_ts_default = '// This file was automatically generated and should no
|
|
|
213
213
|
var prettier = __toESM(require("prettier/standalone"), 1);
|
|
214
214
|
var import_estree = __toESM(require("prettier/plugins/estree.js"), 1);
|
|
215
215
|
var import_typescript = __toESM(require("prettier/plugins/typescript.js"), 1);
|
|
216
|
-
|
|
216
|
+
function formatTsWithPrettier(code) {
|
|
217
217
|
return prettier.format(code, {
|
|
218
218
|
parser: "typescript",
|
|
219
219
|
plugins: [import_estree.default, import_typescript.default]
|
|
@@ -240,7 +240,7 @@ Handlebars.registerHelper(
|
|
|
240
240
|
return toCodeTypeName(column.moduleName) + moduleSuffix;
|
|
241
241
|
} else if (column.type === "module-array") {
|
|
242
242
|
return toCodeTypeName(column.moduleName) + moduleSuffix + "[]";
|
|
243
|
-
} else if (column.type
|
|
243
|
+
} else if (column.type === "json") {
|
|
244
244
|
return "unknown";
|
|
245
245
|
} else if (column.type === "storage") {
|
|
246
246
|
return "StorageItemType";
|
|
@@ -252,7 +252,7 @@ Handlebars.registerHelper(
|
|
|
252
252
|
Handlebars.registerHelper(
|
|
253
253
|
"filterRefColumn",
|
|
254
254
|
(columns) => {
|
|
255
|
-
return (columns
|
|
255
|
+
return (columns ?? []).filter(
|
|
256
256
|
(c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
|
|
257
257
|
);
|
|
258
258
|
}
|
|
@@ -279,7 +279,7 @@ Handlebars.registerHelper(
|
|
|
279
279
|
Handlebars.registerHelper(
|
|
280
280
|
"filterUniqueIndexes",
|
|
281
281
|
(indexes) => {
|
|
282
|
-
return (indexes
|
|
282
|
+
return (indexes ?? []).filter((i) => i.unique);
|
|
283
283
|
}
|
|
284
284
|
);
|
|
285
285
|
Handlebars.registerHelper(
|
|
@@ -980,7 +980,7 @@ Handlebars2.registerHelper("toCodeTypeName", toCodeTypeName2);
|
|
|
980
980
|
Handlebars2.registerHelper("typeName", (column) => {
|
|
981
981
|
if (column.type === "reference") {
|
|
982
982
|
return "string";
|
|
983
|
-
} else if (column.type
|
|
983
|
+
} else if (column.type === "json") {
|
|
984
984
|
return "unknown";
|
|
985
985
|
} else if (column.type === "module") {
|
|
986
986
|
if (!column.moduleName) {
|
|
@@ -1001,7 +1001,7 @@ Handlebars2.registerHelper("typeName", (column) => {
|
|
|
1001
1001
|
Handlebars2.registerHelper(
|
|
1002
1002
|
"filterRefColumn",
|
|
1003
1003
|
(columns) => {
|
|
1004
|
-
return (columns
|
|
1004
|
+
return (columns ?? []).filter(
|
|
1005
1005
|
(c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
|
|
1006
1006
|
);
|
|
1007
1007
|
}
|
|
@@ -1020,7 +1020,7 @@ Handlebars2.registerHelper("includeType", (column) => {
|
|
|
1020
1020
|
Handlebars2.registerHelper(
|
|
1021
1021
|
"filterUniqueIndexes",
|
|
1022
1022
|
(indexes) => {
|
|
1023
|
-
return (indexes
|
|
1023
|
+
return (indexes ?? []).filter((i) => i.unique);
|
|
1024
1024
|
}
|
|
1025
1025
|
);
|
|
1026
1026
|
Handlebars2.registerHelper(
|
|
@@ -1106,9 +1106,10 @@ var consumerPullCommand = new import_commander4.Command("pull").description("pul
|
|
|
1106
1106
|
|
|
1107
1107
|
// src/push/command.ts
|
|
1108
1108
|
var import_commander5 = require("commander");
|
|
1109
|
-
var
|
|
1109
|
+
var import_cli_color6 = __toESM(require("cli-color"), 1);
|
|
1110
1110
|
|
|
1111
1111
|
// src/lib/developer-api.ts
|
|
1112
|
+
var import_cli_color4 = __toESM(require("cli-color"), 1);
|
|
1112
1113
|
async function applyDefinition(env, projectDef) {
|
|
1113
1114
|
const client = createDeveloperAPIv2Client({
|
|
1114
1115
|
serverOrigin: env.ORIZM_BASE_URL,
|
|
@@ -1127,6 +1128,10 @@ async function applyDefinition(env, projectDef) {
|
|
|
1127
1128
|
"401 Unauthorized. Please check your Developer API key and try again."
|
|
1128
1129
|
);
|
|
1129
1130
|
}
|
|
1131
|
+
if (response.error.type === "bad-request") {
|
|
1132
|
+
console.log(import_cli_color4.default.red(response.error.detail));
|
|
1133
|
+
process.exit(1);
|
|
1134
|
+
}
|
|
1130
1135
|
throw new Error(
|
|
1131
1136
|
`${status} ${response.response.statusText}: Unexpected error occurred while applying schema.`
|
|
1132
1137
|
);
|
|
@@ -1162,7 +1167,7 @@ var getChangeEvents = async (env, projectDef) => {
|
|
|
1162
1167
|
};
|
|
1163
1168
|
|
|
1164
1169
|
// src/lib/display-change-events.ts
|
|
1165
|
-
var
|
|
1170
|
+
var import_cli_color5 = __toESM(require("cli-color"), 1);
|
|
1166
1171
|
|
|
1167
1172
|
// src/lib/cli-table.ts
|
|
1168
1173
|
var COLORS = {
|
|
@@ -1199,7 +1204,7 @@ var CliTable = class {
|
|
|
1199
1204
|
updateColumnWidths(row) {
|
|
1200
1205
|
for (let i = 0; i < row.length; i++) {
|
|
1201
1206
|
const cellLength = row[i].length;
|
|
1202
|
-
if (
|
|
1207
|
+
if (this.columnWidths[i] == null || cellLength > this.columnWidths[i]) {
|
|
1203
1208
|
this.columnWidths[i] = cellLength;
|
|
1204
1209
|
}
|
|
1205
1210
|
}
|
|
@@ -1263,7 +1268,7 @@ var CliTable = class {
|
|
|
1263
1268
|
};
|
|
1264
1269
|
|
|
1265
1270
|
// src/lib/display-change-events.ts
|
|
1266
|
-
|
|
1271
|
+
function displayChangeEvents(changeEvents) {
|
|
1267
1272
|
const {
|
|
1268
1273
|
tableChangeEvents = [],
|
|
1269
1274
|
bucketChangeEvents = [],
|
|
@@ -1271,7 +1276,7 @@ async function displayChangeEvents(changeEvents) {
|
|
|
1271
1276
|
} = changeEvents;
|
|
1272
1277
|
if (tableChangeEvents.length === 0 && bucketChangeEvents.length === 0 && authorityChangeEvents.length === 0) {
|
|
1273
1278
|
console.log();
|
|
1274
|
-
console.log(
|
|
1279
|
+
console.log(import_cli_color5.default.green("No changes."));
|
|
1275
1280
|
return;
|
|
1276
1281
|
}
|
|
1277
1282
|
displayTableChangeEvents(tableChangeEvents);
|
|
@@ -1416,6 +1421,18 @@ function displayTableChangeEvents(tableChangeEvents) {
|
|
|
1416
1421
|
});
|
|
1417
1422
|
break;
|
|
1418
1423
|
}
|
|
1424
|
+
case "draft:enable": {
|
|
1425
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
1426
|
+
color: "green"
|
|
1427
|
+
});
|
|
1428
|
+
break;
|
|
1429
|
+
}
|
|
1430
|
+
case "draft:disable": {
|
|
1431
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
1432
|
+
color: "red"
|
|
1433
|
+
});
|
|
1434
|
+
break;
|
|
1435
|
+
}
|
|
1419
1436
|
case "formSubmissions:create":
|
|
1420
1437
|
case "formSubmissions:update": {
|
|
1421
1438
|
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
@@ -1523,42 +1540,44 @@ async function input(prompt) {
|
|
|
1523
1540
|
|
|
1524
1541
|
// src/push/command.ts
|
|
1525
1542
|
var spinner5 = createSpinner();
|
|
1526
|
-
var pushCommand = new import_commander5.Command("push").description("apply schema to project.").option("-e, --env <path>", "env file path.").option("-c, --config <path>", "orizm config file path.", "orizm.config.ts").option("--dry-run", "display change-events without applying schema.", false).option("-y, --yes", "apply schema without confirmation.", false).action(
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
if (options.dryRun) {
|
|
1542
|
-
return;
|
|
1543
|
-
}
|
|
1544
|
-
if (!options.yes) {
|
|
1545
|
-
const confirm = await input("Do you want to apply schema? (y/N): ");
|
|
1546
|
-
if (confirm !== "y") {
|
|
1547
|
-
console.log(import_cli_color5.default.red("Canceled."));
|
|
1543
|
+
var pushCommand = new import_commander5.Command("push").description("apply schema to project.").option("-e, --env <path>", "env file path.").option("-c, --config <path>", "orizm config file path.", "orizm.config.ts").option("--dry-run", "display change-events without applying schema.", false).option("-y, --yes", "apply schema without confirmation.", false).action(
|
|
1544
|
+
async (options) => {
|
|
1545
|
+
try {
|
|
1546
|
+
spinner5.start("Loading environment variables...");
|
|
1547
|
+
const env = await loadEnv(options.env);
|
|
1548
|
+
spinner5.succeed("Loaded environment variables.");
|
|
1549
|
+
spinner5.start("Loading project config...");
|
|
1550
|
+
const projectDef = await loadConfig(options.config);
|
|
1551
|
+
spinner5.succeed("Loaded project config.");
|
|
1552
|
+
spinner5.start("Fetch schema change events...");
|
|
1553
|
+
const changeEvents = await getChangeEvents(env, projectDef);
|
|
1554
|
+
spinner5.succeed("Fetch schema change events.");
|
|
1555
|
+
await displayChangeEvents(changeEvents);
|
|
1556
|
+
if (changeEvents.tableChangeEvents.length === 0 && changeEvents.bucketChangeEvents.length === 0 && changeEvents.authorityChangeEvents.length === 0) {
|
|
1548
1557
|
return;
|
|
1549
1558
|
}
|
|
1559
|
+
if (options.dryRun) {
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (!options.yes) {
|
|
1563
|
+
const confirm = await input("Do you want to apply schema? (y/N): ");
|
|
1564
|
+
if (confirm !== "y") {
|
|
1565
|
+
console.log(import_cli_color6.default.red("Canceled."));
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
spinner5.start("Applying schema...");
|
|
1570
|
+
await applyDefinition(env, projectDef);
|
|
1571
|
+
spinner5.succeed("Schema applied.");
|
|
1572
|
+
} catch (error2) {
|
|
1573
|
+
handleError(error2);
|
|
1550
1574
|
}
|
|
1551
|
-
spinner5.start("Applying schema...");
|
|
1552
|
-
await applyDefinition(env, projectDef);
|
|
1553
|
-
spinner5.succeed("Schema applied.");
|
|
1554
|
-
} catch (error2) {
|
|
1555
|
-
handleError(error2);
|
|
1556
1575
|
}
|
|
1557
|
-
|
|
1576
|
+
);
|
|
1558
1577
|
|
|
1559
1578
|
// src/config/validate/command.ts
|
|
1560
1579
|
var import_commander6 = require("commander");
|
|
1561
|
-
var
|
|
1580
|
+
var import_cli_color7 = __toESM(require("cli-color"), 1);
|
|
1562
1581
|
var v5 = __toESM(require("valibot"), 1);
|
|
1563
1582
|
|
|
1564
1583
|
// src/config/validate/watcher.ts
|
|
@@ -1570,7 +1589,7 @@ function watchConfigFile(configPath, onFileChange) {
|
|
|
1570
1589
|
});
|
|
1571
1590
|
let isProcessing = false;
|
|
1572
1591
|
let timeoutId = null;
|
|
1573
|
-
const debouncedOnChange =
|
|
1592
|
+
const debouncedOnChange = () => {
|
|
1574
1593
|
if (isProcessing) return;
|
|
1575
1594
|
if (timeoutId) {
|
|
1576
1595
|
clearTimeout(timeoutId);
|
|
@@ -1614,10 +1633,10 @@ var validateConfigCommand = new import_commander6.Command("validate").descriptio
|
|
|
1614
1633
|
console.log();
|
|
1615
1634
|
}
|
|
1616
1635
|
await loadConfig(options.config);
|
|
1617
|
-
console.log(
|
|
1636
|
+
console.log(import_cli_color7.default.green("\u2705 Config is valid."));
|
|
1618
1637
|
} catch (error2) {
|
|
1619
1638
|
if (v5.isValiError(error2)) {
|
|
1620
|
-
console.error(
|
|
1639
|
+
console.error(import_cli_color7.default.red("\u274C Config validation failed:"));
|
|
1621
1640
|
displayValibotError(error2);
|
|
1622
1641
|
return;
|
|
1623
1642
|
}
|
|
@@ -1651,12 +1670,6 @@ function generate3(input2) {
|
|
|
1651
1670
|
|
|
1652
1671
|
// src/config/generate-erd/convert-to-input.ts
|
|
1653
1672
|
function convertToInput(config) {
|
|
1654
|
-
if (!config.tables) {
|
|
1655
|
-
return {
|
|
1656
|
-
tables: [],
|
|
1657
|
-
relations: []
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
1673
|
const tables = [];
|
|
1661
1674
|
const relations = [];
|
|
1662
1675
|
for (const table of config.tables) {
|
|
@@ -1689,11 +1702,11 @@ function convertToInput(config) {
|
|
|
1689
1702
|
const moduleTableName = `${table.name}_${column.name}_${column.moduleName}`;
|
|
1690
1703
|
modules.push({
|
|
1691
1704
|
name: moduleTableName,
|
|
1692
|
-
columns: module2
|
|
1705
|
+
columns: module2.columns.map((c) => ({
|
|
1693
1706
|
name: c.name,
|
|
1694
1707
|
type: c.type,
|
|
1695
1708
|
isForeignKey: c.type === "reference"
|
|
1696
|
-
}))
|
|
1709
|
+
}))
|
|
1697
1710
|
});
|
|
1698
1711
|
relations.push({
|
|
1699
1712
|
from: table.name,
|