@orizm/cli 2.1.1 → 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 +75 -62
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +72 -59
- 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 +7 -4
package/dist/cli.js
CHANGED
|
@@ -139,7 +139,7 @@ function getPath(issue) {
|
|
|
139
139
|
for (let j = pathInfoIndex; j < pathInfo.length; j++) {
|
|
140
140
|
const pathItem = pathInfo[j];
|
|
141
141
|
if (pathItem.type === "array" && pathItem.key === index) {
|
|
142
|
-
if (pathItem.value && typeof pathItem.value === "object" && "name" in pathItem.value) {
|
|
142
|
+
if (pathItem.value != null && typeof pathItem.value === "object" && "name" in pathItem.value) {
|
|
143
143
|
pathParts[i] = String(pathItem.value.name);
|
|
144
144
|
pathInfoIndex = j + 1;
|
|
145
145
|
break;
|
|
@@ -189,7 +189,7 @@ var client_ts_default = '// This file was automatically generated and should no
|
|
|
189
189
|
import * as prettier from "prettier/standalone";
|
|
190
190
|
import prettierPluginEstree from "prettier/plugins/estree.js";
|
|
191
191
|
import prettierPluginTypeScript from "prettier/plugins/typescript.js";
|
|
192
|
-
|
|
192
|
+
function formatTsWithPrettier(code) {
|
|
193
193
|
return prettier.format(code, {
|
|
194
194
|
parser: "typescript",
|
|
195
195
|
plugins: [prettierPluginEstree, prettierPluginTypeScript]
|
|
@@ -216,7 +216,7 @@ Handlebars.registerHelper(
|
|
|
216
216
|
return toCodeTypeName(column.moduleName) + moduleSuffix;
|
|
217
217
|
} else if (column.type === "module-array") {
|
|
218
218
|
return toCodeTypeName(column.moduleName) + moduleSuffix + "[]";
|
|
219
|
-
} else if (column.type
|
|
219
|
+
} else if (column.type === "json") {
|
|
220
220
|
return "unknown";
|
|
221
221
|
} else if (column.type === "storage") {
|
|
222
222
|
return "StorageItemType";
|
|
@@ -228,7 +228,7 @@ Handlebars.registerHelper(
|
|
|
228
228
|
Handlebars.registerHelper(
|
|
229
229
|
"filterRefColumn",
|
|
230
230
|
(columns) => {
|
|
231
|
-
return (columns
|
|
231
|
+
return (columns ?? []).filter(
|
|
232
232
|
(c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
|
|
233
233
|
);
|
|
234
234
|
}
|
|
@@ -255,7 +255,7 @@ Handlebars.registerHelper(
|
|
|
255
255
|
Handlebars.registerHelper(
|
|
256
256
|
"filterUniqueIndexes",
|
|
257
257
|
(indexes) => {
|
|
258
|
-
return (indexes
|
|
258
|
+
return (indexes ?? []).filter((i) => i.unique);
|
|
259
259
|
}
|
|
260
260
|
);
|
|
261
261
|
Handlebars.registerHelper(
|
|
@@ -328,6 +328,14 @@ var cmsGenerateCommand = new Command("generate").description("generate orizm cli
|
|
|
328
328
|
// src/cms/pull/command.ts
|
|
329
329
|
import { Command as Command2 } from "commander";
|
|
330
330
|
|
|
331
|
+
// ../internal-shared/dist/chunk-7BJEISQZ.js
|
|
332
|
+
function assertValidUrlOrigin(origin) {
|
|
333
|
+
const url = new URL(origin);
|
|
334
|
+
if (url.origin !== origin) {
|
|
335
|
+
throw new Error(`${origin} is not a valid URL origin`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
331
339
|
// ../../node_modules/.pnpm/openapi-fetch@0.13.5/node_modules/openapi-fetch/dist/index.js
|
|
332
340
|
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
333
341
|
var supportsRequestInitExt = () => {
|
|
@@ -769,15 +777,7 @@ function removeTrailingSlash(url) {
|
|
|
769
777
|
return url;
|
|
770
778
|
}
|
|
771
779
|
|
|
772
|
-
// ../
|
|
773
|
-
function assertValidUrlOrigin(origin) {
|
|
774
|
-
const url = new URL(origin);
|
|
775
|
-
if (url.origin !== origin) {
|
|
776
|
-
throw new Error(`${origin} is not a valid URL origin`);
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
// ../private-api-clients/src/dev-v2-api-client.ts
|
|
780
|
+
// ../internal-shared/dist/api-clients/dev-v2-api-client.js
|
|
781
781
|
function createDeveloperAPIv2Client({
|
|
782
782
|
serverOrigin = "",
|
|
783
783
|
fetch,
|
|
@@ -956,7 +956,7 @@ Handlebars2.registerHelper("toCodeTypeName", toCodeTypeName2);
|
|
|
956
956
|
Handlebars2.registerHelper("typeName", (column) => {
|
|
957
957
|
if (column.type === "reference") {
|
|
958
958
|
return "string";
|
|
959
|
-
} else if (column.type
|
|
959
|
+
} else if (column.type === "json") {
|
|
960
960
|
return "unknown";
|
|
961
961
|
} else if (column.type === "module") {
|
|
962
962
|
if (!column.moduleName) {
|
|
@@ -977,7 +977,7 @@ Handlebars2.registerHelper("typeName", (column) => {
|
|
|
977
977
|
Handlebars2.registerHelper(
|
|
978
978
|
"filterRefColumn",
|
|
979
979
|
(columns) => {
|
|
980
|
-
return (columns
|
|
980
|
+
return (columns ?? []).filter(
|
|
981
981
|
(c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
|
|
982
982
|
);
|
|
983
983
|
}
|
|
@@ -996,7 +996,7 @@ Handlebars2.registerHelper("includeType", (column) => {
|
|
|
996
996
|
Handlebars2.registerHelper(
|
|
997
997
|
"filterUniqueIndexes",
|
|
998
998
|
(indexes) => {
|
|
999
|
-
return (indexes
|
|
999
|
+
return (indexes ?? []).filter((i) => i.unique);
|
|
1000
1000
|
}
|
|
1001
1001
|
);
|
|
1002
1002
|
Handlebars2.registerHelper(
|
|
@@ -1082,9 +1082,10 @@ var consumerPullCommand = new Command4("pull").description("pull orizm schema an
|
|
|
1082
1082
|
|
|
1083
1083
|
// src/push/command.ts
|
|
1084
1084
|
import { Command as Command5 } from "commander";
|
|
1085
|
-
import
|
|
1085
|
+
import cliColor6 from "cli-color";
|
|
1086
1086
|
|
|
1087
1087
|
// src/lib/developer-api.ts
|
|
1088
|
+
import cliColor4 from "cli-color";
|
|
1088
1089
|
async function applyDefinition(env, projectDef) {
|
|
1089
1090
|
const client = createDeveloperAPIv2Client({
|
|
1090
1091
|
serverOrigin: env.ORIZM_BASE_URL,
|
|
@@ -1103,6 +1104,10 @@ async function applyDefinition(env, projectDef) {
|
|
|
1103
1104
|
"401 Unauthorized. Please check your Developer API key and try again."
|
|
1104
1105
|
);
|
|
1105
1106
|
}
|
|
1107
|
+
if (response.error.type === "bad-request") {
|
|
1108
|
+
console.log(cliColor4.red(response.error.detail));
|
|
1109
|
+
process.exit(1);
|
|
1110
|
+
}
|
|
1106
1111
|
throw new Error(
|
|
1107
1112
|
`${status} ${response.response.statusText}: Unexpected error occurred while applying schema.`
|
|
1108
1113
|
);
|
|
@@ -1138,7 +1143,7 @@ var getChangeEvents = async (env, projectDef) => {
|
|
|
1138
1143
|
};
|
|
1139
1144
|
|
|
1140
1145
|
// src/lib/display-change-events.ts
|
|
1141
|
-
import
|
|
1146
|
+
import cliColor5 from "cli-color";
|
|
1142
1147
|
|
|
1143
1148
|
// src/lib/cli-table.ts
|
|
1144
1149
|
var COLORS = {
|
|
@@ -1175,7 +1180,7 @@ var CliTable = class {
|
|
|
1175
1180
|
updateColumnWidths(row) {
|
|
1176
1181
|
for (let i = 0; i < row.length; i++) {
|
|
1177
1182
|
const cellLength = row[i].length;
|
|
1178
|
-
if (
|
|
1183
|
+
if (this.columnWidths[i] == null || cellLength > this.columnWidths[i]) {
|
|
1179
1184
|
this.columnWidths[i] = cellLength;
|
|
1180
1185
|
}
|
|
1181
1186
|
}
|
|
@@ -1239,7 +1244,7 @@ var CliTable = class {
|
|
|
1239
1244
|
};
|
|
1240
1245
|
|
|
1241
1246
|
// src/lib/display-change-events.ts
|
|
1242
|
-
|
|
1247
|
+
function displayChangeEvents(changeEvents) {
|
|
1243
1248
|
const {
|
|
1244
1249
|
tableChangeEvents = [],
|
|
1245
1250
|
bucketChangeEvents = [],
|
|
@@ -1247,7 +1252,7 @@ async function displayChangeEvents(changeEvents) {
|
|
|
1247
1252
|
} = changeEvents;
|
|
1248
1253
|
if (tableChangeEvents.length === 0 && bucketChangeEvents.length === 0 && authorityChangeEvents.length === 0) {
|
|
1249
1254
|
console.log();
|
|
1250
|
-
console.log(
|
|
1255
|
+
console.log(cliColor5.green("No changes."));
|
|
1251
1256
|
return;
|
|
1252
1257
|
}
|
|
1253
1258
|
displayTableChangeEvents(tableChangeEvents);
|
|
@@ -1392,6 +1397,18 @@ function displayTableChangeEvents(tableChangeEvents) {
|
|
|
1392
1397
|
});
|
|
1393
1398
|
break;
|
|
1394
1399
|
}
|
|
1400
|
+
case "draft:enable": {
|
|
1401
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
1402
|
+
color: "green"
|
|
1403
|
+
});
|
|
1404
|
+
break;
|
|
1405
|
+
}
|
|
1406
|
+
case "draft:disable": {
|
|
1407
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
1408
|
+
color: "red"
|
|
1409
|
+
});
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1395
1412
|
case "formSubmissions:create":
|
|
1396
1413
|
case "formSubmissions:update": {
|
|
1397
1414
|
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
@@ -1499,38 +1516,40 @@ async function input(prompt) {
|
|
|
1499
1516
|
|
|
1500
1517
|
// src/push/command.ts
|
|
1501
1518
|
var spinner5 = createSpinner();
|
|
1502
|
-
var pushCommand = new Command5("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(
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
}
|
|
1517
|
-
if (options.dryRun) {
|
|
1518
|
-
return;
|
|
1519
|
-
}
|
|
1520
|
-
if (!options.yes) {
|
|
1521
|
-
const confirm = await input("Do you want to apply schema? (y/N): ");
|
|
1522
|
-
if (confirm !== "y") {
|
|
1523
|
-
console.log(cliColor5.red("Canceled."));
|
|
1519
|
+
var pushCommand = new Command5("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(
|
|
1520
|
+
async (options) => {
|
|
1521
|
+
try {
|
|
1522
|
+
spinner5.start("Loading environment variables...");
|
|
1523
|
+
const env = await loadEnv(options.env);
|
|
1524
|
+
spinner5.succeed("Loaded environment variables.");
|
|
1525
|
+
spinner5.start("Loading project config...");
|
|
1526
|
+
const projectDef = await loadConfig(options.config);
|
|
1527
|
+
spinner5.succeed("Loaded project config.");
|
|
1528
|
+
spinner5.start("Fetch schema change events...");
|
|
1529
|
+
const changeEvents = await getChangeEvents(env, projectDef);
|
|
1530
|
+
spinner5.succeed("Fetch schema change events.");
|
|
1531
|
+
await displayChangeEvents(changeEvents);
|
|
1532
|
+
if (changeEvents.tableChangeEvents.length === 0 && changeEvents.bucketChangeEvents.length === 0 && changeEvents.authorityChangeEvents.length === 0) {
|
|
1524
1533
|
return;
|
|
1525
1534
|
}
|
|
1535
|
+
if (options.dryRun) {
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
if (!options.yes) {
|
|
1539
|
+
const confirm = await input("Do you want to apply schema? (y/N): ");
|
|
1540
|
+
if (confirm !== "y") {
|
|
1541
|
+
console.log(cliColor6.red("Canceled."));
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
spinner5.start("Applying schema...");
|
|
1546
|
+
await applyDefinition(env, projectDef);
|
|
1547
|
+
spinner5.succeed("Schema applied.");
|
|
1548
|
+
} catch (error2) {
|
|
1549
|
+
handleError(error2);
|
|
1526
1550
|
}
|
|
1527
|
-
spinner5.start("Applying schema...");
|
|
1528
|
-
await applyDefinition(env, projectDef);
|
|
1529
|
-
spinner5.succeed("Schema applied.");
|
|
1530
|
-
} catch (error2) {
|
|
1531
|
-
handleError(error2);
|
|
1532
1551
|
}
|
|
1533
|
-
|
|
1552
|
+
);
|
|
1534
1553
|
|
|
1535
1554
|
// src/config/validate/command.ts
|
|
1536
1555
|
import { Command as Command6 } from "commander";
|
|
@@ -1546,7 +1565,7 @@ function watchConfigFile(configPath, onFileChange) {
|
|
|
1546
1565
|
});
|
|
1547
1566
|
let isProcessing = false;
|
|
1548
1567
|
let timeoutId = null;
|
|
1549
|
-
const debouncedOnChange =
|
|
1568
|
+
const debouncedOnChange = () => {
|
|
1550
1569
|
if (isProcessing) return;
|
|
1551
1570
|
if (timeoutId) {
|
|
1552
1571
|
clearTimeout(timeoutId);
|
|
@@ -1627,12 +1646,6 @@ function generate3(input2) {
|
|
|
1627
1646
|
|
|
1628
1647
|
// src/config/generate-erd/convert-to-input.ts
|
|
1629
1648
|
function convertToInput(config) {
|
|
1630
|
-
if (!config.tables) {
|
|
1631
|
-
return {
|
|
1632
|
-
tables: [],
|
|
1633
|
-
relations: []
|
|
1634
|
-
};
|
|
1635
|
-
}
|
|
1636
1649
|
const tables = [];
|
|
1637
1650
|
const relations = [];
|
|
1638
1651
|
for (const table of config.tables) {
|
|
@@ -1665,11 +1678,11 @@ function convertToInput(config) {
|
|
|
1665
1678
|
const moduleTableName = `${table.name}_${column.name}_${column.moduleName}`;
|
|
1666
1679
|
modules.push({
|
|
1667
1680
|
name: moduleTableName,
|
|
1668
|
-
columns: module
|
|
1681
|
+
columns: module.columns.map((c) => ({
|
|
1669
1682
|
name: c.name,
|
|
1670
1683
|
type: c.type,
|
|
1671
1684
|
isForeignKey: c.type === "reference"
|
|
1672
|
-
}))
|
|
1685
|
+
}))
|
|
1673
1686
|
});
|
|
1674
1687
|
relations.push({
|
|
1675
1688
|
from: table.name,
|