@gearbox-protocol/cli-utils 5.68.3 → 5.69.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/Zommand.d.ts +4 -0
- package/dist/Zommand.js +14 -2
- package/dist/compressedConfig.d.ts +9 -0
- package/dist/compressedConfig.js +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/Zommand.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export interface ZommandOptions<T extends z4.$ZodTypes> {
|
|
|
13
13
|
* If value is string, it's used as default value for config file
|
|
14
14
|
*/
|
|
15
15
|
configFile?: boolean | string;
|
|
16
|
+
/**
|
|
17
|
+
* If true, allows to pass config zlib compressed config as --inline-config=... or INLINE_CONFIG env var
|
|
18
|
+
*/
|
|
19
|
+
inlineConfig?: boolean;
|
|
16
20
|
}
|
|
17
21
|
export declare class Zommand<T extends z4.$ZodTypes, Args extends any[] = []> extends Command<Args, z4.output<T>> {
|
|
18
22
|
#private;
|
package/dist/Zommand.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Command, Option } from "@commander-js/extra-typings";
|
|
2
2
|
import * as z4 from "zod/v4/core";
|
|
3
|
+
import { decompressObject } from "./compressedConfig.js";
|
|
3
4
|
import { resolveYamlFiles } from "./resolveYamlFiles.js";
|
|
4
5
|
export const zommandRegistry = z4.registry();
|
|
5
6
|
export class Zommand extends Command {
|
|
@@ -8,7 +9,7 @@ export class Zommand extends Command {
|
|
|
8
9
|
#envToObjectKeys = {};
|
|
9
10
|
constructor(name, opts) {
|
|
10
11
|
super(name);
|
|
11
|
-
const { schema, templateData, configFile = true } = opts;
|
|
12
|
+
const { schema, templateData, configFile = true, inlineConfig = true, } = opts;
|
|
12
13
|
this.#schema = schema;
|
|
13
14
|
this.#templatedData = templateData;
|
|
14
15
|
const def = this.#schema._zod.def;
|
|
@@ -33,6 +34,9 @@ export class Zommand extends Command {
|
|
|
33
34
|
}
|
|
34
35
|
this.addOption(opt);
|
|
35
36
|
}
|
|
37
|
+
if (inlineConfig) {
|
|
38
|
+
this.addOption(new Option("--inline-config [config]", "inline config"));
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
#addOptionsFromObject(def) {
|
|
38
42
|
const shape = def.shape;
|
|
@@ -59,7 +63,7 @@ export class Zommand extends Command {
|
|
|
59
63
|
return super.action(async (...args) => {
|
|
60
64
|
const argz = args;
|
|
61
65
|
const _cmd = argz.splice(-1);
|
|
62
|
-
const [{ config, ...opts }] = argz.splice(-1);
|
|
66
|
+
const [{ config, inlineConfig, ...opts }] = argz.splice(-1);
|
|
63
67
|
let fromYaml = {};
|
|
64
68
|
if (config) {
|
|
65
69
|
fromYaml = await resolveYamlFiles(config, {
|
|
@@ -67,6 +71,13 @@ export class Zommand extends Command {
|
|
|
67
71
|
...this.#templatedData,
|
|
68
72
|
});
|
|
69
73
|
}
|
|
74
|
+
let fromInlineConfig = {};
|
|
75
|
+
if (inlineConfig) {
|
|
76
|
+
fromInlineConfig = decompressObject(inlineConfig);
|
|
77
|
+
}
|
|
78
|
+
else if (process.env.INLINE_CONFIG) {
|
|
79
|
+
fromInlineConfig = decompressObject(process.env.INLINE_CONFIG);
|
|
80
|
+
}
|
|
70
81
|
const schemaFromEnv = {};
|
|
71
82
|
for (const [env, key] of Object.entries(this.#envToObjectKeys)) {
|
|
72
83
|
if (process.env[env]) {
|
|
@@ -77,6 +88,7 @@ export class Zommand extends Command {
|
|
|
77
88
|
const combined = {
|
|
78
89
|
...schemaFromEnv,
|
|
79
90
|
...fromYaml,
|
|
91
|
+
...fromInlineConfig,
|
|
80
92
|
...opts,
|
|
81
93
|
};
|
|
82
94
|
const data = z4.parse(this.#schema, combined);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compress a plain JS object into a base64url string
|
|
3
|
+
* suitable for env vars.
|
|
4
|
+
*/
|
|
5
|
+
export declare function compressObject(obj: unknown): string;
|
|
6
|
+
/**
|
|
7
|
+
* Decompress a base64url string back into a JS object
|
|
8
|
+
*/
|
|
9
|
+
export declare function decompressObject<T = unknown>(value: string): T;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { deflateSync, inflateSync } from "node:zlib";
|
|
2
|
+
/**
|
|
3
|
+
* Compress a plain JS object into a base64url string
|
|
4
|
+
* suitable for env vars.
|
|
5
|
+
*/
|
|
6
|
+
export function compressObject(obj) {
|
|
7
|
+
const json = JSON.stringify(obj);
|
|
8
|
+
const compressed = deflateSync(Buffer.from(json, "utf8"));
|
|
9
|
+
return compressed.toString("base64url");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Decompress a base64url string back into a JS object
|
|
13
|
+
*/
|
|
14
|
+
export function decompressObject(value) {
|
|
15
|
+
const compressed = Buffer.from(value, "base64url");
|
|
16
|
+
const json = inflateSync(compressed).toString("utf8");
|
|
17
|
+
return JSON.parse(json);
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED