@orizm/cli 0.1.0 → 0.1.1
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.js +203 -216
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -36,10 +37,15 @@ async function loadConfig(configFile) {
|
|
|
36
37
|
entryPoints: [configFile],
|
|
37
38
|
bundle: true,
|
|
38
39
|
write: false,
|
|
39
|
-
format: "
|
|
40
|
-
target: "node16"
|
|
40
|
+
format: "esm",
|
|
41
|
+
target: "node16",
|
|
42
|
+
platform: "node"
|
|
41
43
|
});
|
|
42
|
-
|
|
44
|
+
const moduleURL = `data:text/javascript,${encodeURIComponent(
|
|
45
|
+
buildResult.outputFiles[0].text
|
|
46
|
+
)}`;
|
|
47
|
+
const { default: orizmConfigRaw } = await import(moduleURL);
|
|
48
|
+
return v.parse(import_config_validator.OrizmConfigDef, orizmConfigRaw);
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
// src/lib/cli-spinner.ts
|
|
@@ -271,7 +277,6 @@ var cmsGenerateCommand = new import_commander.Command("generate").description("g
|
|
|
271
277
|
|
|
272
278
|
// src/cms/pull/command.ts
|
|
273
279
|
var import_commander2 = require("commander");
|
|
274
|
-
var cliColor2 = __toESM(require("cli-color"));
|
|
275
280
|
|
|
276
281
|
// src/api/developer-api-client.ts
|
|
277
282
|
var import_openapi_fetch = __toESM(require("openapi-fetch"));
|
|
@@ -286,33 +291,48 @@ function createDeveloperAPIClient(baseUrl, apiKey) {
|
|
|
286
291
|
});
|
|
287
292
|
}
|
|
288
293
|
|
|
289
|
-
// src/
|
|
294
|
+
// src/lib/fetch-definition-reference.ts
|
|
290
295
|
async function fetchDefinitionReference(options) {
|
|
291
296
|
const client = createDeveloperAPIClient(options.baseUrl, options.apiKey);
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
297
|
+
const abortController = new AbortController();
|
|
298
|
+
const timeout = setTimeout(() => {
|
|
299
|
+
abortController.abort();
|
|
300
|
+
}, 1e4);
|
|
301
|
+
try {
|
|
302
|
+
const response = await client.GET(
|
|
303
|
+
"/projects/{projectName}/definitions/current/reference",
|
|
304
|
+
{
|
|
305
|
+
params: { path: { projectName: options.projectName } },
|
|
306
|
+
signal: abortController.signal
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
if (response.data) {
|
|
310
|
+
return response.data.content;
|
|
296
311
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
312
|
+
if (response.response.status === 404) {
|
|
313
|
+
throw new Error(`Project ${options.projectName} not found.`);
|
|
314
|
+
}
|
|
315
|
+
if (response.response.status === 401) {
|
|
316
|
+
throw new Error(`API Key is invalid.`);
|
|
317
|
+
}
|
|
318
|
+
throw new Error(
|
|
319
|
+
`Unknown error occurred when fetching definitions for project ${options.projectName}.`
|
|
320
|
+
);
|
|
321
|
+
} catch (error2) {
|
|
322
|
+
if (error2 instanceof Error && error2.name === "AbortError") {
|
|
323
|
+
throw new Error("Request timed out.");
|
|
324
|
+
}
|
|
325
|
+
throw error2;
|
|
326
|
+
} finally {
|
|
327
|
+
clearTimeout(timeout);
|
|
306
328
|
}
|
|
307
|
-
throw new Error(
|
|
308
|
-
`Unknown error occurred when fetching definitions for project ${options.projectName}.`
|
|
309
|
-
);
|
|
310
329
|
}
|
|
311
330
|
|
|
312
|
-
// src/
|
|
331
|
+
// src/lib/load-env.ts
|
|
313
332
|
var import_promises2 = __toESM(require("fs/promises"));
|
|
314
333
|
var v3 = __toESM(require("valibot"));
|
|
315
334
|
var import_dotenv = __toESM(require("dotenv"));
|
|
335
|
+
var DEFAULT_ENV_FILE_PATH = ".env";
|
|
316
336
|
var EnvSchema = v3.object({
|
|
317
337
|
ORIZM_PROJECT: v3.pipe(
|
|
318
338
|
v3.string(),
|
|
@@ -333,16 +353,33 @@ var EnvSchema = v3.object({
|
|
|
333
353
|
)
|
|
334
354
|
});
|
|
335
355
|
async function loadEnv(envPath) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
356
|
+
let envFileContent;
|
|
357
|
+
if (envPath) {
|
|
358
|
+
envFileContent = await import_promises2.default.readFile(envPath, "utf-8").catch(() => null);
|
|
359
|
+
if (!envFileContent) {
|
|
360
|
+
throw new Error(`Environment variables file: '${envPath}' is not found.`);
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
envFileContent = await import_promises2.default.readFile(DEFAULT_ENV_FILE_PATH, "utf-8").catch(() => null);
|
|
364
|
+
}
|
|
365
|
+
if (envFileContent !== null) {
|
|
366
|
+
const dotenvParsed = import_dotenv.default.parse(envFileContent);
|
|
367
|
+
const envParseResult = v3.safeParse(EnvSchema, dotenvParsed);
|
|
368
|
+
if (!envParseResult.success) {
|
|
369
|
+
throw new Error(
|
|
370
|
+
`Environment variables are not valid.
|
|
371
|
+
` + envParseResult.issues.map((issue) => issue.message).join("\n")
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
return envParseResult.output;
|
|
375
|
+
}
|
|
376
|
+
const processEnvParseResult = v3.safeParse(EnvSchema, process.env);
|
|
377
|
+
if (!processEnvParseResult.success) {
|
|
340
378
|
throw new Error(
|
|
341
|
-
|
|
379
|
+
"Environment variables are not valid. Put .env file or set environment variables in process.env.\n" + processEnvParseResult.issues.map((issue) => issue.message).join("\n")
|
|
342
380
|
);
|
|
343
381
|
}
|
|
344
|
-
|
|
345
|
-
return env;
|
|
382
|
+
return processEnvParseResult.output;
|
|
346
383
|
}
|
|
347
384
|
|
|
348
385
|
// src/cms/pull/action.ts
|
|
@@ -365,18 +402,14 @@ async function pullAction(options) {
|
|
|
365
402
|
}
|
|
366
403
|
|
|
367
404
|
// src/cms/pull/command.ts
|
|
368
|
-
var cmsPullCommand = new import_commander2.Command("pull").description("pull orizm schema and generate client and types.").option("-e, --env
|
|
405
|
+
var cmsPullCommand = new import_commander2.Command("pull").description("pull orizm schema and generate client and types.").option("-e, --env [path]", "env file path.").option("-o, --output <path>", "output directory.", "./src/orizm").action(async (options) => {
|
|
369
406
|
try {
|
|
370
407
|
await pullAction({
|
|
371
408
|
destination: options.output,
|
|
372
409
|
envPath: options.env
|
|
373
410
|
});
|
|
374
411
|
} catch (error2) {
|
|
375
|
-
|
|
376
|
-
console.error(cliColor2.red("Error:", error2.message));
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
console.error("An unexpected error occurred:", error2);
|
|
412
|
+
handleError(error2);
|
|
380
413
|
}
|
|
381
414
|
});
|
|
382
415
|
|
|
@@ -451,9 +484,12 @@ import_handlebars2.default.registerHelper("includeType", (column) => {
|
|
|
451
484
|
if (column.type === "module-array" && column.moduleName)
|
|
452
485
|
return `_ArrayModuleRef<${toCodeTypeName2(column.moduleName)}__Descriptor>`;
|
|
453
486
|
});
|
|
454
|
-
import_handlebars2.default.registerHelper(
|
|
455
|
-
|
|
456
|
-
|
|
487
|
+
import_handlebars2.default.registerHelper(
|
|
488
|
+
"filterUniqueIndexes",
|
|
489
|
+
(indexes) => {
|
|
490
|
+
return (indexes || []).filter((i) => i.unique);
|
|
491
|
+
}
|
|
492
|
+
);
|
|
457
493
|
import_handlebars2.default.registerHelper(
|
|
458
494
|
"getIndexColumns",
|
|
459
495
|
(table, index) => {
|
|
@@ -501,105 +537,27 @@ var consumerGenerateCommand = new import_commander3.Command("generate").descript
|
|
|
501
537
|
var import_commander4 = require("commander");
|
|
502
538
|
|
|
503
539
|
// src/consumer/pull/action.ts
|
|
504
|
-
var import_cli_color5 = __toESM(require("cli-color"));
|
|
505
|
-
|
|
506
|
-
// src/consumer/pull/pull.ts
|
|
507
540
|
var import_cli_color4 = __toESM(require("cli-color"));
|
|
508
|
-
async function pullDefinition(config) {
|
|
509
|
-
console.log("pull definition ....");
|
|
510
|
-
const abortController = new AbortController();
|
|
511
|
-
const abortTimer = setTimeout(() => {
|
|
512
|
-
abortController.abort();
|
|
513
|
-
}, 1e4);
|
|
514
|
-
try {
|
|
515
|
-
const url = new URL(config.baseUrl);
|
|
516
|
-
url.pathname = `/api/consumer/v1/${config.projectName}/definitions/current`;
|
|
517
|
-
const response = await fetch(url, {
|
|
518
|
-
headers: {
|
|
519
|
-
"x-consumer-key": config.consumerKey,
|
|
520
|
-
"User-Agent": "orizm-consumer-cli"
|
|
521
|
-
},
|
|
522
|
-
signal: abortController.signal
|
|
523
|
-
});
|
|
524
|
-
if (response.ok) {
|
|
525
|
-
const definition = await response.json().then((data) => data.content);
|
|
526
|
-
console.log(
|
|
527
|
-
`definitionVersion: ${definition.definitionVersion}`,
|
|
528
|
-
import_cli_color4.default.green("OK")
|
|
529
|
-
);
|
|
530
|
-
return definition;
|
|
531
|
-
} else {
|
|
532
|
-
throw new Error(
|
|
533
|
-
`Failed to pull definition : status code ${response.status}
|
|
534
|
-
${response.statusText}`
|
|
535
|
-
);
|
|
536
|
-
}
|
|
537
|
-
} catch (e) {
|
|
538
|
-
if (e instanceof TypeError || e instanceof DOMException && e.name === "AbortError") {
|
|
539
|
-
throw new Error("Failed to pull definition: " + String(e));
|
|
540
|
-
}
|
|
541
|
-
throw e;
|
|
542
|
-
} finally {
|
|
543
|
-
clearTimeout(abortTimer);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// src/consumer/pull/config.ts
|
|
548
|
-
var import_fs = require("fs");
|
|
549
|
-
var import_dotenv2 = require("dotenv");
|
|
550
|
-
async function loadConfig2(configPath) {
|
|
551
|
-
const config = (() => {
|
|
552
|
-
if ((0, import_fs.existsSync)(configPath)) {
|
|
553
|
-
const env = (0, import_fs.readFileSync)(configPath);
|
|
554
|
-
return (0, import_dotenv2.parse)(env);
|
|
555
|
-
} else {
|
|
556
|
-
return {};
|
|
557
|
-
}
|
|
558
|
-
})();
|
|
559
|
-
const projectName = config.ORIZM_PROJECT_NAME || process.env.ORIZM_PROJECT_NAME;
|
|
560
|
-
const consumerKey = config.ORIZM_CONSUMER_KEY || process.env.ORIZM_CONSUMER_KEY;
|
|
561
|
-
const baseUrl = config.ORIZM_BASE_URL || process.env.ORIZM_BASE_URL || "https://app.orizm.com";
|
|
562
|
-
console.log(`ORIZM_BASE_URL : ${baseUrl}`);
|
|
563
|
-
console.log(`ORIZM_PROJECT_NAME: ${projectName}`);
|
|
564
|
-
console.log(`ORIZM_CONSUMER_KEY: ${consumerKey ? "****" : void 0}`);
|
|
565
|
-
if (!projectName || !consumerKey) {
|
|
566
|
-
const errors = [];
|
|
567
|
-
if (!projectName) {
|
|
568
|
-
errors.push(
|
|
569
|
-
"ORIZM_CONSUMER_KEY is not set. Please set ORIZM_CONSUMER_KEY in .env.x-consumer-cli.local or environment variable."
|
|
570
|
-
);
|
|
571
|
-
}
|
|
572
|
-
if (!consumerKey) {
|
|
573
|
-
errors.push(
|
|
574
|
-
"ORIZM_PROJECT_NAME is not set. Please set ORIZM_PROJECT_NAME in .env.x-consumer-cli.local or environment variable."
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
throw new Error(errors.join("\n"));
|
|
578
|
-
}
|
|
579
|
-
return {
|
|
580
|
-
projectName,
|
|
581
|
-
consumerKey,
|
|
582
|
-
baseUrl
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// src/consumer/pull/action.ts
|
|
587
541
|
async function pullAction2(options) {
|
|
588
542
|
try {
|
|
589
|
-
const config = await
|
|
590
|
-
const definition = await
|
|
543
|
+
const config = await loadEnv(options.envPath);
|
|
544
|
+
const definition = await fetchDefinitionReference({
|
|
545
|
+
baseUrl: config.ORIZM_BASE_URL,
|
|
546
|
+
apiKey: config.ORIZM_API_KEY,
|
|
547
|
+
projectName: config.ORIZM_PROJECT
|
|
548
|
+
});
|
|
591
549
|
await generate2({
|
|
592
550
|
definition,
|
|
593
551
|
output: options.destination
|
|
594
552
|
});
|
|
595
553
|
} catch (e) {
|
|
596
|
-
console.error(
|
|
554
|
+
console.error(import_cli_color4.default.red(e));
|
|
597
555
|
process.exit(1);
|
|
598
556
|
}
|
|
599
557
|
}
|
|
600
558
|
|
|
601
559
|
// src/consumer/pull/command.ts
|
|
602
|
-
var consumerPullCommand = new import_commander4.Command("pull").description("pull orizm schema and generate client and types.").option("-e, --env
|
|
560
|
+
var consumerPullCommand = new import_commander4.Command("pull").description("pull orizm schema and generate client and types.").option("-e, --env [path]", "env file path.").option("-o, --output <path>", "output directory.", "./src/orizm").action(async (options) => {
|
|
603
561
|
await pullAction2({
|
|
604
562
|
destination: options.output,
|
|
605
563
|
envPath: options.env
|
|
@@ -608,116 +566,60 @@ var consumerPullCommand = new import_commander4.Command("pull").description("pul
|
|
|
608
566
|
|
|
609
567
|
// src/push/command.ts
|
|
610
568
|
var import_commander5 = require("commander");
|
|
611
|
-
var
|
|
612
|
-
|
|
613
|
-
// src/lib/env-manager.ts
|
|
614
|
-
var import_fs2 = __toESM(require("fs"));
|
|
615
|
-
var import_dotenv3 = __toESM(require("dotenv"));
|
|
616
|
-
var import_valibot = require("valibot");
|
|
617
|
-
var defaultEnvFilePath = ".env.x.local";
|
|
618
|
-
var schema = (0, import_valibot.object)({
|
|
619
|
-
ORIZM_PROJECT: (0, import_valibot.pipe)(
|
|
620
|
-
(0, import_valibot.string)(),
|
|
621
|
-
(0, import_valibot.minLength)(1, "ORIZM_PROJECT is required"),
|
|
622
|
-
(0, import_valibot.brand)("ORIZM_PROJECT")
|
|
623
|
-
),
|
|
624
|
-
ORIZM_BASE_URL: (0, import_valibot.pipe)(
|
|
625
|
-
(0, import_valibot.nullish)((0, import_valibot.string)(), "https://app.orizm.com"),
|
|
626
|
-
// if null, use default value
|
|
627
|
-
(0, import_valibot.transform)((v4) => v4.replace(/\/$/, "")),
|
|
628
|
-
// remove trailing slash
|
|
629
|
-
(0, import_valibot.brand)("ORIZM_BASE_URL")
|
|
630
|
-
),
|
|
631
|
-
ORIZM_API_KEY: (0, import_valibot.pipe)(
|
|
632
|
-
(0, import_valibot.string)(),
|
|
633
|
-
(0, import_valibot.minLength)(1, "ORIZM_API_KEY is required"),
|
|
634
|
-
(0, import_valibot.brand)("ORIZM_API_KEY")
|
|
635
|
-
)
|
|
636
|
-
});
|
|
637
|
-
var EnvManager = class {
|
|
638
|
-
parsed;
|
|
639
|
-
constructor(envFilePath) {
|
|
640
|
-
if (envFilePath && import_fs2.default.existsSync(envFilePath)) {
|
|
641
|
-
import_dotenv3.default.config({ path: envFilePath });
|
|
642
|
-
} else if (envFilePath !== defaultEnvFilePath) {
|
|
643
|
-
throw new Error(
|
|
644
|
-
`environment variables file: '${envFilePath}' is not found.`
|
|
645
|
-
);
|
|
646
|
-
} else {
|
|
647
|
-
import_dotenv3.default.config();
|
|
648
|
-
}
|
|
649
|
-
const result = (0, import_valibot.parse)(schema, process.env);
|
|
650
|
-
this.parsed = result;
|
|
651
|
-
}
|
|
652
|
-
get projectName() {
|
|
653
|
-
return this.parsed.ORIZM_PROJECT;
|
|
654
|
-
}
|
|
655
|
-
get baseUrl() {
|
|
656
|
-
return this.parsed.ORIZM_BASE_URL;
|
|
657
|
-
}
|
|
658
|
-
get apiKey() {
|
|
659
|
-
return this.parsed.ORIZM_API_KEY;
|
|
660
|
-
}
|
|
661
|
-
};
|
|
569
|
+
var import_cli_color6 = require("cli-color");
|
|
662
570
|
|
|
663
571
|
// src/lib/developer-api.ts
|
|
664
|
-
async function request(props) {
|
|
665
|
-
return await fetch(`${props.env.baseUrl}/api/dev/v1${props.path}`, {
|
|
666
|
-
method: props.method,
|
|
667
|
-
headers: {
|
|
668
|
-
"content-type": "application/json",
|
|
669
|
-
"x-api-key": props.env.apiKey
|
|
670
|
-
},
|
|
671
|
-
body: JSON.stringify(props.body)
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
572
|
async function applyDefinition(env, projectDef) {
|
|
675
|
-
const
|
|
676
|
-
env,
|
|
677
|
-
|
|
678
|
-
|
|
573
|
+
const client = createDeveloperAPIClient(
|
|
574
|
+
env.ORIZM_BASE_URL,
|
|
575
|
+
env.ORIZM_API_KEY
|
|
576
|
+
);
|
|
577
|
+
const response = await client.POST("/projects/{projectName}/definitions", {
|
|
578
|
+
params: { path: { projectName: env.ORIZM_PROJECT } },
|
|
579
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
679
580
|
body: { apply: true, project: projectDef }
|
|
680
581
|
});
|
|
681
|
-
if (!response.
|
|
682
|
-
const status = response.status;
|
|
582
|
+
if (!response.data) {
|
|
583
|
+
const status = response.response.status;
|
|
683
584
|
if (status === 401) {
|
|
684
585
|
throw new Error(
|
|
685
586
|
"401 Unauthorized. Please check your Developer API key and try again."
|
|
686
587
|
);
|
|
687
588
|
}
|
|
688
589
|
throw new Error(
|
|
689
|
-
`${status} ${response.statusText}:
|
|
590
|
+
`${status} ${response.response.statusText}: Unexpected error occurred while applying schema.`
|
|
690
591
|
);
|
|
691
592
|
}
|
|
692
593
|
}
|
|
693
594
|
var getChangeEvents = async (env, projectDef) => {
|
|
694
|
-
const
|
|
695
|
-
env,
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
throw new Error(`400 Bad Request:
|
|
705
|
-
${JSON.stringify(body, null, 2)}`);
|
|
595
|
+
const client = createDeveloperAPIClient(
|
|
596
|
+
env.ORIZM_BASE_URL,
|
|
597
|
+
env.ORIZM_API_KEY
|
|
598
|
+
);
|
|
599
|
+
const response = await client.POST(
|
|
600
|
+
"/projects/{projectName}/definitions/dry-run",
|
|
601
|
+
{
|
|
602
|
+
params: { path: { projectName: env.ORIZM_PROJECT } },
|
|
603
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
604
|
+
body: { project: projectDef }
|
|
706
605
|
}
|
|
606
|
+
);
|
|
607
|
+
if (!response.data) {
|
|
608
|
+
const status = response.response.status;
|
|
707
609
|
if (status === 401) {
|
|
708
610
|
throw new Error(
|
|
709
|
-
"401 Unauthorized
|
|
611
|
+
"401 Unauthorized. Please check your Developer API key and try again."
|
|
710
612
|
);
|
|
711
613
|
}
|
|
712
614
|
throw new Error(
|
|
713
|
-
`${status} ${response.statusText}:
|
|
615
|
+
`${status} ${response.response.statusText}: Unexpected error occurred while fetching schema change events.`
|
|
714
616
|
);
|
|
715
617
|
}
|
|
716
|
-
return
|
|
618
|
+
return response.data;
|
|
717
619
|
};
|
|
718
620
|
|
|
719
621
|
// src/lib/display-change-events.ts
|
|
720
|
-
var
|
|
622
|
+
var import_cli_color5 = require("cli-color");
|
|
721
623
|
|
|
722
624
|
// src/lib/cli-table.ts
|
|
723
625
|
var COLORS = {
|
|
@@ -819,10 +721,23 @@ var CliTable = class {
|
|
|
819
721
|
|
|
820
722
|
// src/lib/display-change-events.ts
|
|
821
723
|
async function displayChangeEvents(changeEvents) {
|
|
822
|
-
const
|
|
823
|
-
|
|
724
|
+
const {
|
|
725
|
+
tableChangeEvents = [],
|
|
726
|
+
bucketChangeEvents = [],
|
|
727
|
+
authorityChangeEvents = []
|
|
728
|
+
} = changeEvents;
|
|
729
|
+
if (tableChangeEvents.length === 0 && bucketChangeEvents.length === 0 && authorityChangeEvents.length === 0) {
|
|
824
730
|
console.log();
|
|
825
|
-
console.log((0,
|
|
731
|
+
console.log((0, import_cli_color5.green)("No changes."));
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
displayTableChangeEvents(tableChangeEvents);
|
|
735
|
+
displayBucketChangeEvents(bucketChangeEvents);
|
|
736
|
+
displayAuthorityChangeEvents(authorityChangeEvents);
|
|
737
|
+
console.log();
|
|
738
|
+
}
|
|
739
|
+
function displayTableChangeEvents(tableChangeEvents) {
|
|
740
|
+
if (tableChangeEvents.length === 0) {
|
|
826
741
|
return;
|
|
827
742
|
}
|
|
828
743
|
const eventsByTable = /* @__PURE__ */ new Map();
|
|
@@ -974,9 +889,81 @@ async function displayChangeEvents(changeEvents) {
|
|
|
974
889
|
}
|
|
975
890
|
}
|
|
976
891
|
table.print();
|
|
977
|
-
console.log();
|
|
978
892
|
}
|
|
979
893
|
}
|
|
894
|
+
function displayBucketChangeEvents(bucketChangeEvents) {
|
|
895
|
+
if (bucketChangeEvents.length === 0) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const eventsByBucket = /* @__PURE__ */ new Map();
|
|
899
|
+
for (const event of bucketChangeEvents) {
|
|
900
|
+
const bucketName = event.bucketDef.name;
|
|
901
|
+
const bucketEvents = eventsByBucket.get(bucketName) ?? [];
|
|
902
|
+
bucketEvents.push(event);
|
|
903
|
+
eventsByBucket.set(bucketName, bucketEvents);
|
|
904
|
+
}
|
|
905
|
+
const table = new CliTable(["Type", "Name", "Event", "Detail"]);
|
|
906
|
+
console.log();
|
|
907
|
+
console.log("\u26AB\uFE0EBuckets");
|
|
908
|
+
for (const [_, events] of eventsByBucket.entries()) {
|
|
909
|
+
for (const event of events) {
|
|
910
|
+
const eventName = event.event;
|
|
911
|
+
switch (eventName) {
|
|
912
|
+
case "bucket:create":
|
|
913
|
+
case "bucket:update": {
|
|
914
|
+
table.addRow(
|
|
915
|
+
[
|
|
916
|
+
"bucket",
|
|
917
|
+
event.bucketDef.name,
|
|
918
|
+
eventName,
|
|
919
|
+
JSON.stringify(event.bucketDef)
|
|
920
|
+
],
|
|
921
|
+
{
|
|
922
|
+
color: "green"
|
|
923
|
+
}
|
|
924
|
+
);
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
case "bucket:delete": {
|
|
928
|
+
table.addRow(
|
|
929
|
+
[
|
|
930
|
+
"bucket",
|
|
931
|
+
event.bucketDef.name,
|
|
932
|
+
eventName,
|
|
933
|
+
JSON.stringify(event.bucketDef)
|
|
934
|
+
],
|
|
935
|
+
{
|
|
936
|
+
color: "red"
|
|
937
|
+
}
|
|
938
|
+
);
|
|
939
|
+
break;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
table.print();
|
|
945
|
+
}
|
|
946
|
+
function displayAuthorityChangeEvents(authorityChangeEvents) {
|
|
947
|
+
if (authorityChangeEvents.length === 0) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const table = new CliTable(["Type", "Event", "Detail"]);
|
|
951
|
+
console.log();
|
|
952
|
+
console.log("\u26AB\uFE0EAuthorities");
|
|
953
|
+
for (const event of authorityChangeEvents) {
|
|
954
|
+
const eventName = event.event;
|
|
955
|
+
switch (eventName) {
|
|
956
|
+
case "authority:update": {
|
|
957
|
+
table.addRow(
|
|
958
|
+
["authority", eventName, JSON.stringify(event.authorityDef)],
|
|
959
|
+
{ color: "green" }
|
|
960
|
+
);
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
table.print();
|
|
966
|
+
}
|
|
980
967
|
|
|
981
968
|
// src/lib/cli-input.ts
|
|
982
969
|
var import_promises4 = require("readline/promises");
|
|
@@ -993,10 +980,10 @@ async function input(prompt) {
|
|
|
993
980
|
|
|
994
981
|
// src/push/command.ts
|
|
995
982
|
var spinner3 = createSpinner();
|
|
996
|
-
var pushCommand = new import_commander5.Command("push").description("apply schema to project.").option("-e, --env <path>", "env file path."
|
|
983
|
+
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(async (options) => {
|
|
997
984
|
try {
|
|
998
985
|
spinner3.start("Loading environment variables...");
|
|
999
|
-
const env =
|
|
986
|
+
const env = await loadEnv(options.env);
|
|
1000
987
|
spinner3.succeed("Loaded environment variables.");
|
|
1001
988
|
spinner3.start("Loading project schema...");
|
|
1002
989
|
const projectDef = await loadConfig(options.config);
|
|
@@ -1005,7 +992,7 @@ var pushCommand = new import_commander5.Command("push").description("apply schem
|
|
|
1005
992
|
const changeEvents = await getChangeEvents(env, projectDef);
|
|
1006
993
|
spinner3.succeed("Fetch schema change events.");
|
|
1007
994
|
await displayChangeEvents(changeEvents);
|
|
1008
|
-
if (changeEvents.tableChangeEvents.length === 0) {
|
|
995
|
+
if (changeEvents.tableChangeEvents.length === 0 && changeEvents.bucketChangeEvents.length === 0 && changeEvents.authorityChangeEvents.length === 0) {
|
|
1009
996
|
return;
|
|
1010
997
|
}
|
|
1011
998
|
if (options.dryRun) {
|
|
@@ -1014,7 +1001,7 @@ var pushCommand = new import_commander5.Command("push").description("apply schem
|
|
|
1014
1001
|
if (!options.yes) {
|
|
1015
1002
|
const confirm = await input("Do you want to apply schema? (y/N): ");
|
|
1016
1003
|
if (confirm !== "y") {
|
|
1017
|
-
console.log((0,
|
|
1004
|
+
console.log((0, import_cli_color6.red)("Canceled."));
|
|
1018
1005
|
return;
|
|
1019
1006
|
}
|
|
1020
1007
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orizm/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Orizm CLI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"handlebars": "^4.7.7",
|
|
20
20
|
"openapi-fetch": "^0.12.2",
|
|
21
21
|
"valibot": "^1.0.0",
|
|
22
|
-
"@orizm/common": "1.
|
|
22
|
+
"@orizm/common": "1.12.0"
|
|
23
23
|
},
|
|
24
24
|
"bin": {
|
|
25
25
|
"orizm": "bin/index.js"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {
|
|
34
|
+
"dev": "tsup --watch",
|
|
34
35
|
"build": "tsup",
|
|
35
36
|
"typecheck": "tsc --noEmit",
|
|
36
37
|
"generate": "openapi-typescript ../../apps/server/openapi/developerAPI.yaml --output src/api/developer-api.d.ts"
|