@settlemint/sdk-cli 1.2.2-pr549e8ff1 → 1.2.2-pr65e8d754

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.
Files changed (3) hide show
  1. package/dist/cli.js +1014 -1013
  2. package/dist/cli.js.map +13 -13
  3. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -259517,7 +259517,7 @@ function pruneCurrentEnv(currentEnv, env2) {
259517
259517
  var package_default = {
259518
259518
  name: "@settlemint/sdk-cli",
259519
259519
  description: "Command-line interface for SettleMint SDK, providing development tools and project management capabilities",
259520
- version: "1.2.2-pr549e8ff1",
259520
+ version: "1.2.2-pr65e8d754",
259521
259521
  type: "module",
259522
259522
  private: false,
259523
259523
  license: "FSL-1.1-MIT",
@@ -259563,11 +259563,11 @@ var package_default = {
259563
259563
  "@commander-js/extra-typings": "11.1.0",
259564
259564
  commander: "11.1.0",
259565
259565
  "@inquirer/confirm": "5.1.7",
259566
- "@inquirer/input": "4.1.7",
259567
- "@inquirer/password": "4.0.11",
259566
+ "@inquirer/input": "4.1.8",
259567
+ "@inquirer/password": "4.0.10",
259568
259568
  "@inquirer/select": "4.0.10",
259569
- "@settlemint/sdk-js": "1.2.2-pr549e8ff1",
259570
- "@settlemint/sdk-utils": "1.2.2-pr549e8ff1",
259569
+ "@settlemint/sdk-js": "1.2.2-pr65e8d754",
259570
+ "@settlemint/sdk-utils": "1.2.2-pr65e8d754",
259571
259571
  "@types/node": "22.13.10",
259572
259572
  "@types/semver": "7.5.8",
259573
259573
  "@types/which": "3.0.4",
@@ -265042,1116 +265042,1117 @@ function sanitizeName(value4, length = 35) {
265042
265042
  }).slice(0, length).replaceAll(/(^\d*)/g, "").replaceAll(/(-$)/g, "").replaceAll(/(^-)/g, "");
265043
265043
  }
265044
265044
 
265045
- // ../../node_modules/@inquirer/input/dist/esm/index.js
265046
- var inputTheme = {
265047
- validationFailureMode: "keep"
265048
- };
265049
- var esm_default2 = createPrompt((config3, done) => {
265050
- const { required, validate: validate3 = () => true } = config3;
265051
- const theme = makeTheme(inputTheme, config3.theme);
265052
- const [status, setStatus] = useState("idle");
265053
- const [defaultValue = "", setDefaultValue] = useState(config3.default);
265054
- const [errorMsg, setError] = useState();
265055
- const [value4, setValue] = useState("");
265056
- const prefix = usePrefix({ status, theme });
265057
- useKeypress(async (key2, rl) => {
265058
- if (status !== "idle") {
265059
- return;
265060
- }
265061
- if (isEnterKey(key2)) {
265062
- const answer = value4 || defaultValue;
265063
- setStatus("loading");
265064
- const isValid2 = required && !answer ? "You must provide a value" : await validate3(answer);
265065
- if (isValid2 === true) {
265066
- setValue(answer);
265067
- setStatus("done");
265068
- done(answer);
265069
- } else {
265070
- if (theme.validationFailureMode === "clear") {
265071
- setValue("");
265072
- } else {
265073
- rl.write(value4);
265074
- }
265075
- setError(isValid2 || "You must provide a valid value");
265076
- setStatus("idle");
265077
- }
265078
- } else if (isBackspaceKey(key2) && !value4) {
265079
- setDefaultValue(undefined);
265080
- } else if (key2.name === "tab" && !value4) {
265081
- setDefaultValue(undefined);
265082
- rl.clearLine(0);
265083
- rl.write(defaultValue);
265084
- setValue(defaultValue);
265085
- } else {
265086
- setValue(rl.line);
265087
- setError(undefined);
265088
- }
265089
- });
265090
- const message = theme.style.message(config3.message, status);
265091
- let formattedValue = value4;
265092
- if (typeof config3.transformer === "function") {
265093
- formattedValue = config3.transformer(value4, { isFinal: status === "done" });
265094
- } else if (status === "done") {
265095
- formattedValue = theme.style.answer(value4);
265096
- }
265097
- let defaultStr;
265098
- if (defaultValue && status !== "done" && !value4) {
265099
- defaultStr = theme.style.defaultAnswer(defaultValue);
265100
- }
265101
- let error5 = "";
265102
- if (errorMsg) {
265103
- error5 = theme.style.error(errorMsg);
265045
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/key.js
265046
+ var isBackspaceKey2 = (key2) => key2.name === "backspace";
265047
+ var isEnterKey2 = (key2) => key2.name === "enter" || key2.name === "return";
265048
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/errors.js
265049
+ class AbortPromptError2 extends Error {
265050
+ name = "AbortPromptError";
265051
+ message = "Prompt was aborted";
265052
+ constructor(options) {
265053
+ super();
265054
+ this.cause = options?.cause;
265104
265055
  }
265105
- return [
265106
- [prefix, message, defaultStr, formattedValue].filter((v6) => v6 !== undefined).join(" "),
265107
- error5
265108
- ];
265109
- });
265056
+ }
265110
265057
 
265111
- // src/prompts/smart-contract-set/subgraph-name.prompt.ts
265112
- async function subgraphNamePrompt({
265113
- defaultName,
265114
- env: env2,
265115
- accept
265116
- }) {
265117
- const defaultSubgraphName = defaultName ? sanitizeName(defaultName) : undefined;
265118
- if (accept) {
265119
- return defaultSubgraphName ?? env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH;
265120
- }
265121
- const subgraphName = await esm_default2({
265122
- message: "What is the name of your subgraph?",
265123
- default: defaultSubgraphName,
265124
- required: true
265125
- });
265126
- return sanitizeName(subgraphName);
265058
+ class CancelPromptError2 extends Error {
265059
+ name = "CancelPromptError";
265060
+ message = "Prompt was canceled";
265127
265061
  }
265128
265062
 
265129
- // ../../node_modules/@inquirer/select/dist/esm/index.js
265130
- var import_yoctocolors_cjs3 = __toESM(require_yoctocolors_cjs(), 1);
265131
- var import_ansi_escapes2 = __toESM(require_ansi_escapes(), 1);
265132
- var selectTheme = {
265133
- icon: { cursor: esm_default.pointer },
265134
- style: {
265135
- disabled: (text2) => import_yoctocolors_cjs3.default.dim(`- ${text2}`),
265136
- description: (text2) => import_yoctocolors_cjs3.default.cyan(text2)
265137
- },
265138
- helpMode: "auto"
265139
- };
265140
- function isSelectable(item) {
265141
- return !Separator.isSeparator(item) && !item.disabled;
265063
+ class ExitPromptError2 extends Error {
265064
+ name = "ExitPromptError";
265142
265065
  }
265143
- function normalizeChoices(choices) {
265144
- return choices.map((choice) => {
265145
- if (Separator.isSeparator(choice))
265146
- return choice;
265147
- if (typeof choice === "string") {
265148
- return {
265149
- value: choice,
265150
- name: choice,
265151
- short: choice,
265152
- disabled: false
265066
+
265067
+ class HookError2 extends Error {
265068
+ name = "HookError";
265069
+ }
265070
+
265071
+ class ValidationError2 extends Error {
265072
+ name = "ValidationError";
265073
+ }
265074
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/use-prefix.js
265075
+ import { AsyncResource as AsyncResource5 } from "node:async_hooks";
265076
+
265077
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/hook-engine.js
265078
+ import { AsyncLocalStorage as AsyncLocalStorage2, AsyncResource as AsyncResource4 } from "node:async_hooks";
265079
+ var hookStorage2 = new AsyncLocalStorage2;
265080
+ function createStore2(rl) {
265081
+ const store = {
265082
+ rl,
265083
+ hooks: [],
265084
+ hooksCleanup: [],
265085
+ hooksEffect: [],
265086
+ index: 0,
265087
+ handleChange() {}
265088
+ };
265089
+ return store;
265090
+ }
265091
+ function withHooks2(rl, cb) {
265092
+ const store = createStore2(rl);
265093
+ return hookStorage2.run(store, () => {
265094
+ function cycle(render) {
265095
+ store.handleChange = () => {
265096
+ store.index = 0;
265097
+ render();
265153
265098
  };
265099
+ store.handleChange();
265154
265100
  }
265155
- const name3 = choice.name ?? String(choice.value);
265156
- return {
265157
- value: choice.value,
265158
- name: name3,
265159
- description: choice.description,
265160
- short: choice.short ?? name3,
265161
- disabled: choice.disabled ?? false
265162
- };
265101
+ return cb(cycle);
265163
265102
  });
265164
265103
  }
265165
- var esm_default3 = createPrompt((config3, done) => {
265166
- const { loop = true, pageSize = 7 } = config3;
265167
- const firstRender = useRef(true);
265168
- const theme = makeTheme(selectTheme, config3.theme);
265169
- const [status, setStatus] = useState("idle");
265170
- const prefix = usePrefix({ status, theme });
265171
- const searchTimeoutRef = useRef();
265172
- const items = useMemo(() => normalizeChoices(config3.choices), [config3.choices]);
265173
- const bounds = useMemo(() => {
265174
- const first = items.findIndex(isSelectable);
265175
- const last = items.findLastIndex(isSelectable);
265176
- if (first === -1) {
265177
- throw new ValidationError("[select prompt] No selectable choices. All choices are disabled.");
265104
+ function getStore2() {
265105
+ const store = hookStorage2.getStore();
265106
+ if (!store) {
265107
+ throw new HookError2("[Inquirer] Hook functions can only be called from within a prompt");
265108
+ }
265109
+ return store;
265110
+ }
265111
+ function readline3() {
265112
+ return getStore2().rl;
265113
+ }
265114
+ function withUpdates2(fn) {
265115
+ const wrapped = (...args) => {
265116
+ const store = getStore2();
265117
+ let shouldUpdate = false;
265118
+ const oldHandleChange = store.handleChange;
265119
+ store.handleChange = () => {
265120
+ shouldUpdate = true;
265121
+ };
265122
+ const returnValue = fn(...args);
265123
+ if (shouldUpdate) {
265124
+ oldHandleChange();
265178
265125
  }
265179
- return { first, last };
265180
- }, [items]);
265181
- const defaultItemIndex = useMemo(() => {
265182
- if (!("default" in config3))
265183
- return -1;
265184
- return items.findIndex((item) => isSelectable(item) && item.value === config3.default);
265185
- }, [config3.default, items]);
265186
- const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
265187
- const selectedChoice = items[active];
265188
- useKeypress((key2, rl) => {
265189
- clearTimeout(searchTimeoutRef.current);
265190
- if (isEnterKey(key2)) {
265191
- setStatus("done");
265192
- done(selectedChoice.value);
265193
- } else if (isUpKey(key2) || isDownKey(key2)) {
265194
- rl.clearLine(0);
265195
- if (loop || isUpKey(key2) && active !== bounds.first || isDownKey(key2) && active !== bounds.last) {
265196
- const offset = isUpKey(key2) ? -1 : 1;
265197
- let next = active;
265198
- do {
265199
- next = (next + offset + items.length) % items.length;
265200
- } while (!isSelectable(items[next]));
265201
- setActive(next);
265202
- }
265203
- } else if (isNumberKey(key2)) {
265204
- rl.clearLine(0);
265205
- const position = Number(key2.name) - 1;
265206
- const item = items[position];
265207
- if (item != null && isSelectable(item)) {
265208
- setActive(position);
265126
+ store.handleChange = oldHandleChange;
265127
+ return returnValue;
265128
+ };
265129
+ return AsyncResource4.bind(wrapped);
265130
+ }
265131
+ function withPointer2(cb) {
265132
+ const store = getStore2();
265133
+ const { index } = store;
265134
+ const pointer = {
265135
+ get() {
265136
+ return store.hooks[index];
265137
+ },
265138
+ set(value4) {
265139
+ store.hooks[index] = value4;
265140
+ },
265141
+ initialized: index in store.hooks
265142
+ };
265143
+ const returnValue = cb(pointer);
265144
+ store.index++;
265145
+ return returnValue;
265146
+ }
265147
+ function handleChange2() {
265148
+ getStore2().handleChange();
265149
+ }
265150
+ var effectScheduler2 = {
265151
+ queue(cb) {
265152
+ const store = getStore2();
265153
+ const { index } = store;
265154
+ store.hooksEffect.push(() => {
265155
+ store.hooksCleanup[index]?.();
265156
+ const cleanFn = cb(readline3());
265157
+ if (cleanFn != null && typeof cleanFn !== "function") {
265158
+ throw new ValidationError2("useEffect return value must be a cleanup function or nothing.");
265209
265159
  }
265210
- } else if (isBackspaceKey(key2)) {
265211
- rl.clearLine(0);
265212
- } else {
265213
- const searchTerm = rl.line.toLowerCase();
265214
- const matchIndex = items.findIndex((item) => {
265215
- if (Separator.isSeparator(item) || !isSelectable(item))
265216
- return false;
265217
- return item.name.toLowerCase().startsWith(searchTerm);
265160
+ store.hooksCleanup[index] = cleanFn;
265161
+ });
265162
+ },
265163
+ run() {
265164
+ const store = getStore2();
265165
+ withUpdates2(() => {
265166
+ store.hooksEffect.forEach((effect) => {
265167
+ effect();
265218
265168
  });
265219
- if (matchIndex !== -1) {
265220
- setActive(matchIndex);
265221
- }
265222
- searchTimeoutRef.current = setTimeout(() => {
265223
- rl.clearLine(0);
265224
- }, 700);
265169
+ store.hooksEffect.length = 0;
265170
+ })();
265171
+ },
265172
+ clearAll() {
265173
+ const store = getStore2();
265174
+ store.hooksCleanup.forEach((cleanFn) => {
265175
+ cleanFn?.();
265176
+ });
265177
+ store.hooksEffect.length = 0;
265178
+ store.hooksCleanup.length = 0;
265179
+ }
265180
+ };
265181
+
265182
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/use-state.js
265183
+ function useState2(defaultValue) {
265184
+ return withPointer2((pointer) => {
265185
+ const setFn = (newValue) => {
265186
+ if (pointer.get() !== newValue) {
265187
+ pointer.set(newValue);
265188
+ handleChange2();
265189
+ }
265190
+ };
265191
+ if (pointer.initialized) {
265192
+ return [pointer.get(), setFn];
265225
265193
  }
265194
+ const value4 = typeof defaultValue === "function" ? defaultValue() : defaultValue;
265195
+ pointer.set(value4);
265196
+ return [value4, setFn];
265226
265197
  });
265227
- useEffect(() => () => {
265228
- clearTimeout(searchTimeoutRef.current);
265229
- }, []);
265230
- const message = theme.style.message(config3.message, status);
265231
- let helpTipTop = "";
265232
- let helpTipBottom = "";
265233
- if (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current) {
265234
- firstRender.current = false;
265235
- if (items.length > pageSize) {
265236
- helpTipBottom = `
265237
- ${theme.style.help("(Use arrow keys to reveal more choices)")}`;
265238
- } else {
265239
- helpTipTop = theme.style.help("(Use arrow keys)");
265198
+ }
265199
+
265200
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/use-effect.js
265201
+ function useEffect2(cb, depArray) {
265202
+ withPointer2((pointer) => {
265203
+ const oldDeps = pointer.get();
265204
+ const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i6) => !Object.is(dep, oldDeps[i6]));
265205
+ if (hasChanged) {
265206
+ effectScheduler2.queue(cb);
265240
265207
  }
265241
- }
265242
- const page = usePagination({
265243
- items,
265244
- active,
265245
- renderItem({ item, isActive }) {
265246
- if (Separator.isSeparator(item)) {
265247
- return ` ${item.separator}`;
265248
- }
265249
- if (item.disabled) {
265250
- const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
265251
- return theme.style.disabled(`${item.name} ${disabledLabel}`);
265252
- }
265253
- const color = isActive ? theme.style.highlight : (x6) => x6;
265254
- const cursor = isActive ? theme.icon.cursor : ` `;
265255
- return color(`${cursor} ${item.name}`);
265256
- },
265257
- pageSize,
265258
- loop
265208
+ pointer.set(depArray);
265259
265209
  });
265260
- if (status === "done") {
265261
- return `${prefix} ${message} ${theme.style.answer(selectedChoice.short)}`;
265210
+ }
265211
+
265212
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/theme.js
265213
+ var import_yoctocolors_cjs3 = __toESM(require_yoctocolors_cjs(), 1);
265214
+ var defaultTheme2 = {
265215
+ prefix: {
265216
+ idle: import_yoctocolors_cjs3.default.blue("?"),
265217
+ done: import_yoctocolors_cjs3.default.green(esm_default.tick)
265218
+ },
265219
+ spinner: {
265220
+ interval: 80,
265221
+ frames: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"].map((frame) => import_yoctocolors_cjs3.default.yellow(frame))
265222
+ },
265223
+ style: {
265224
+ answer: import_yoctocolors_cjs3.default.cyan,
265225
+ message: import_yoctocolors_cjs3.default.bold,
265226
+ error: (text2) => import_yoctocolors_cjs3.default.red(`> ${text2}`),
265227
+ defaultAnswer: (text2) => import_yoctocolors_cjs3.default.dim(`(${text2})`),
265228
+ help: import_yoctocolors_cjs3.default.dim,
265229
+ highlight: import_yoctocolors_cjs3.default.cyan,
265230
+ key: (text2) => import_yoctocolors_cjs3.default.cyan(import_yoctocolors_cjs3.default.bold(`<${text2}>`))
265262
265231
  }
265263
- const choiceDescription = selectedChoice.description ? `
265264
- ${theme.style.description(selectedChoice.description)}` : ``;
265265
- return `${[prefix, message, helpTipTop].filter(Boolean).join(" ")}
265266
- ${page}${helpTipBottom}${choiceDescription}${import_ansi_escapes2.default.cursorHide}`;
265267
- });
265232
+ };
265268
265233
 
265269
- // src/prompts/smart-contract-set/subgraph.prompt.ts
265270
- var ALL = "All";
265271
- var NEW = "New subgraph";
265272
- async function subgraphPrompt({
265273
- env: env2,
265274
- accept,
265275
- message,
265276
- allowAll = false,
265277
- allowNew = false,
265278
- isCi = is_in_ci_default
265279
- }) {
265280
- const autoAccept = isCi || !!accept;
265281
- const subgraphNames = env2.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS?.map((endpoint) => endpoint.split("/").pop()).filter(Boolean) ?? [];
265282
- if (autoAccept) {
265283
- if (allowAll) {
265284
- return subgraphNames;
265285
- }
265286
- if (env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH) {
265287
- return [env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH];
265288
- }
265289
- return subgraphNames.length === 1 ? subgraphNames : [];
265234
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/make-theme.js
265235
+ function isPlainObject3(value4) {
265236
+ if (typeof value4 !== "object" || value4 === null)
265237
+ return false;
265238
+ let proto = value4;
265239
+ while (Object.getPrototypeOf(proto) !== null) {
265240
+ proto = Object.getPrototypeOf(proto);
265290
265241
  }
265291
- if (!allowNew) {
265292
- if (subgraphNames.length === 0) {
265293
- cancel2("No subgraphs found");
265294
- }
265295
- if (subgraphNames.length === 1) {
265296
- return subgraphNames;
265242
+ return Object.getPrototypeOf(value4) === proto;
265243
+ }
265244
+ function deepMerge3(...objects) {
265245
+ const output = {};
265246
+ for (const obj of objects) {
265247
+ for (const [key2, value4] of Object.entries(obj)) {
265248
+ const prevValue = output[key2];
265249
+ output[key2] = isPlainObject3(prevValue) && isPlainObject3(value4) ? deepMerge3(prevValue, value4) : value4;
265297
265250
  }
265298
265251
  }
265299
- const choices = subgraphNames.slice().sort();
265300
- if (allowAll) {
265301
- choices.unshift(ALL);
265302
- }
265303
- if (allowNew) {
265304
- choices.unshift(NEW);
265305
- }
265306
- let defaultChoice;
265307
- if (allowAll) {
265308
- defaultChoice = ALL;
265309
- } else if (allowNew) {
265310
- defaultChoice = env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH ?? NEW;
265311
- } else {
265312
- defaultChoice = env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH ?? subgraphNames[0];
265313
- }
265314
- const subgraphName = choices.length === 1 && choices[0] === NEW ? NEW : await esm_default3({
265315
- message,
265316
- choices: choices.map((name3) => ({
265317
- name: name3,
265318
- value: name3
265319
- })),
265320
- default: defaultChoice
265321
- });
265322
- if (!subgraphName) {
265323
- cancel2("No subgraph selected");
265324
- }
265325
- if (subgraphName === NEW) {
265326
- const newSubgraphName = await subgraphNamePrompt({
265327
- defaultName: "",
265328
- env: env2,
265329
- accept: autoAccept
265330
- });
265331
- if (!newSubgraphName) {
265332
- return [];
265252
+ return output;
265253
+ }
265254
+ function makeTheme2(...themes) {
265255
+ const themesToMerge = [
265256
+ defaultTheme2,
265257
+ ...themes.filter((theme) => theme != null)
265258
+ ];
265259
+ return deepMerge3(...themesToMerge);
265260
+ }
265261
+
265262
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/use-prefix.js
265263
+ function usePrefix2({ status = "idle", theme }) {
265264
+ const [showLoader, setShowLoader] = useState2(false);
265265
+ const [tick, setTick] = useState2(0);
265266
+ const { prefix, spinner: spinner2 } = makeTheme2(theme);
265267
+ useEffect2(() => {
265268
+ if (status === "loading") {
265269
+ let tickInterval;
265270
+ let inc = -1;
265271
+ const delayTimeout = setTimeout(AsyncResource5.bind(() => {
265272
+ setShowLoader(true);
265273
+ tickInterval = setInterval(AsyncResource5.bind(() => {
265274
+ inc = inc + 1;
265275
+ setTick(inc % spinner2.frames.length);
265276
+ }), spinner2.interval);
265277
+ }), 300);
265278
+ return () => {
265279
+ clearTimeout(delayTimeout);
265280
+ clearInterval(tickInterval);
265281
+ };
265282
+ } else {
265283
+ setShowLoader(false);
265333
265284
  }
265334
- return [newSubgraphName];
265285
+ }, [status]);
265286
+ if (showLoader) {
265287
+ return spinner2.frames[tick];
265335
265288
  }
265336
- return subgraphName === ALL ? subgraphNames : [subgraphName];
265289
+ const iconName = status === "loading" ? "idle" : status;
265290
+ return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix["idle"];
265291
+ }
265292
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/use-ref.js
265293
+ function useRef2(val) {
265294
+ return useState2({ current: val })[0];
265337
265295
  }
265338
265296
 
265339
- // src/utils/commands/create-examples.ts
265340
- function createExamples(examples) {
265341
- return `
265342
- Examples:
265297
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/use-keypress.js
265298
+ function useKeypress2(userHandler) {
265299
+ const signal = useRef2(userHandler);
265300
+ signal.current = userHandler;
265301
+ useEffect2((rl) => {
265302
+ let ignore = false;
265303
+ const handler = withUpdates2((_input, event) => {
265304
+ if (ignore)
265305
+ return;
265306
+ signal.current(event, rl);
265307
+ });
265308
+ rl.input.on("keypress", handler);
265309
+ return () => {
265310
+ ignore = true;
265311
+ rl.input.removeListener("keypress", handler);
265312
+ };
265313
+ }, []);
265314
+ }
265315
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/utils.js
265316
+ var import_cli_width2 = __toESM(require_cli_width(), 1);
265317
+ var import_wrap_ansi2 = __toESM(require_wrap_ansi(), 1);
265318
+ function breakLines2(content, width) {
265319
+ return content.split(`
265320
+ `).flatMap((line) => import_wrap_ansi2.default(line, width, { trim: false, hard: true }).split(`
265321
+ `).map((str) => str.trimEnd())).join(`
265322
+ `);
265323
+ }
265324
+ function readlineWidth2() {
265325
+ return import_cli_width2.default({ defaultWidth: 80, output: readline3().output });
265326
+ }
265343
265327
 
265344
- ${examples.map(({ description, command, commandPrefix }) => {
265345
- return ` # ${description}
265346
- $ ${commandPrefix ?? ""}settlemint ${command}`;
265347
- }).join(`
265328
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/create-prompt.js
265329
+ var import_mute_stream2 = __toESM(require_lib(), 1);
265330
+ import * as readline4 from "node:readline";
265331
+ import { AsyncResource as AsyncResource6 } from "node:async_hooks";
265348
265332
 
265349
- `)}`;
265333
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/screen-manager.js
265334
+ var import_ansi_escapes2 = __toESM(require_ansi_escapes(), 1);
265335
+ import { stripVTControlCharacters as stripVTControlCharacters3 } from "node:util";
265336
+ var height2 = (content) => content.split(`
265337
+ `).length;
265338
+ var lastLine2 = (content) => content.split(`
265339
+ `).pop() ?? "";
265340
+ function cursorDown2(n6) {
265341
+ return n6 > 0 ? import_ansi_escapes2.default.cursorDown(n6) : "";
265350
265342
  }
265351
265343
 
265352
- // src/commands/codegen/codegen-blockscout.ts
265353
- import { rm as rm2, writeFile as writeFile6 } from "node:fs/promises";
265354
- import { basename, resolve as resolve5 } from "node:path";
265355
- var PACKAGE_NAME4 = "@settlemint/sdk-blockscout";
265356
- async function codegenBlockscout(env2) {
265357
- const endpoint = env2.SETTLEMINT_BLOCKSCOUT_GRAPHQL_ENDPOINT;
265358
- if (!endpoint) {
265359
- return;
265344
+ class ScreenManager2 {
265345
+ height = 0;
265346
+ extraLinesUnderPrompt = 0;
265347
+ cursorPos;
265348
+ rl;
265349
+ constructor(rl) {
265350
+ this.rl = rl;
265351
+ this.cursorPos = rl.getCursorPos();
265360
265352
  }
265361
- const accessToken = await getApplicationOrPersonalAccessToken({
265362
- env: env2,
265363
- instance: env2.SETTLEMINT_INSTANCE,
265364
- prefer: "application"
265365
- });
265366
- if (!accessToken) {
265367
- return;
265353
+ write(content) {
265354
+ this.rl.output.unmute();
265355
+ this.rl.output.write(content);
265356
+ this.rl.output.mute();
265368
265357
  }
265369
- const introspectionJsonPath = resolve5(process.cwd(), "__blockscout-introspection__.json");
265370
- try {
265371
- const data = await graphqlFetchWithRetry(endpoint, {
265372
- method: "POST",
265373
- headers: {
265374
- "x-auth-token": accessToken,
265375
- "Content-Type": "application/json"
265376
- },
265377
- body: JSON.stringify({
265378
- query: `
265379
- query IntrospectionQuery {
265380
- __schema {
265381
- queryType { name }
265382
- mutationType { name }
265383
- types {
265384
- ...FullType
265385
- }
265386
- directives {
265387
- name
265388
- description
265389
- locations
265390
- args {
265391
- ...InputValue
265392
- }
265393
- }
265394
- }
265395
- }
265396
-
265397
- fragment FullType on __Type {
265398
- kind
265399
- name
265400
- description
265401
- fields(includeDeprecated: true) {
265402
- name
265403
- description
265404
- args {
265405
- ...InputValue
265406
- }
265407
- type {
265408
- ...TypeRef
265409
- }
265410
- isDeprecated
265411
- deprecationReason
265412
- }
265413
- inputFields {
265414
- ...InputValue
265415
- }
265416
- interfaces {
265417
- ...TypeRef
265418
- }
265419
- enumValues(includeDeprecated: true) {
265420
- name
265421
- description
265422
- isDeprecated
265423
- deprecationReason
265424
- }
265425
- possibleTypes {
265426
- ...TypeRef
265427
- }
265428
- }
265429
-
265430
- fragment InputValue on __InputValue {
265431
- name
265432
- description
265433
- type { ...TypeRef }
265434
- defaultValue
265435
- }
265436
-
265437
- fragment TypeRef on __Type {
265438
- kind
265439
- name
265440
- ofType {
265441
- kind
265442
- name
265443
- ofType {
265444
- kind
265445
- name
265446
- ofType {
265447
- kind
265448
- name
265449
- ofType {
265450
- kind
265451
- name
265452
- ofType {
265453
- kind
265454
- name
265455
- ofType {
265456
- kind
265457
- name
265458
- ofType {
265459
- kind
265460
- name
265461
- ofType {
265462
- kind
265463
- name
265464
- ofType {
265465
- kind
265466
- name
265467
- }
265468
- }
265469
- }
265470
- }
265471
- }
265472
- }
265473
- }
265474
- }
265475
- }
265476
- }
265477
- `
265478
- })
265479
- });
265480
- await writeFile6(introspectionJsonPath, JSON.stringify(data));
265481
- } catch (err) {
265482
- const error5 = err;
265483
- note(`GraphQL endpoint '${endpoint}' is not reachable: ${error5.message}`, "warn");
265484
- return;
265358
+ render(content, bottomContent = "") {
265359
+ const promptLine = lastLine2(content);
265360
+ const rawPromptLine = stripVTControlCharacters3(promptLine);
265361
+ let prompt = rawPromptLine;
265362
+ if (this.rl.line.length > 0) {
265363
+ prompt = prompt.slice(0, -this.rl.line.length);
265364
+ }
265365
+ this.rl.setPrompt(prompt);
265366
+ this.cursorPos = this.rl.getCursorPos();
265367
+ const width = readlineWidth2();
265368
+ content = breakLines2(content, width);
265369
+ bottomContent = breakLines2(bottomContent, width);
265370
+ if (rawPromptLine.length % width === 0) {
265371
+ content += `
265372
+ `;
265373
+ }
265374
+ let output = content + (bottomContent ? `
265375
+ ` + bottomContent : "");
265376
+ const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
265377
+ const bottomContentHeight = promptLineUpDiff + (bottomContent ? height2(bottomContent) : 0);
265378
+ if (bottomContentHeight > 0)
265379
+ output += import_ansi_escapes2.default.cursorUp(bottomContentHeight);
265380
+ output += import_ansi_escapes2.default.cursorTo(this.cursorPos.cols);
265381
+ this.write(cursorDown2(this.extraLinesUnderPrompt) + import_ansi_escapes2.default.eraseLines(this.height) + output);
265382
+ this.extraLinesUnderPrompt = bottomContentHeight;
265383
+ this.height = height2(output);
265485
265384
  }
265486
- try {
265487
- await generateSchema({
265488
- input: basename(introspectionJsonPath),
265489
- output: "blockscout-schema.graphql",
265490
- tsconfig: undefined,
265491
- headers: undefined
265492
- });
265493
- } finally {
265494
- await rm2(introspectionJsonPath);
265385
+ checkCursorPos() {
265386
+ const cursorPos = this.rl.getCursorPos();
265387
+ if (cursorPos.cols !== this.cursorPos.cols) {
265388
+ this.write(import_ansi_escapes2.default.cursorTo(cursorPos.cols));
265389
+ this.cursorPos = cursorPos;
265390
+ }
265495
265391
  }
265496
- const template = `import { createBlockscoutClient } from "${PACKAGE_NAME4}";
265497
- import type { introspection } from "@schemas/blockscout-env";
265498
-
265499
- export const { client: blockscoutClient, graphql: blockscoutGraphql } = createBlockscoutClient<{
265500
- introspection: introspection;
265501
- disableMasking: true;
265502
- scalars: {
265503
- /** 40 hex characters (160 bits/20 bytes) derived from the public key, prefixed with 0x */
265504
- AddressHash: string;
265505
- /** Unpadded big-endian hexadecimal number where each byte pair maps to underlying binary */
265506
- Data: string;
265507
- /** ISO8601 formatted UTC datetime string */
265508
- DateTime: string;
265509
- /** String representation of a signed double-precision decimal value */
265510
- Decimal: string;
265511
- /** 32-byte KECCAK-256 hash */
265512
- FullHash: string;
265513
- /** Arbitrary JSON string data as UTF-8 */
265514
- Json: string;
265515
- /** 16 hex character (128 bits/8 bytes) nonce from Proof-of-Work */
265516
- NonceHash: string;
265517
- /** Smallest fractional unit of Ether, represented as a string for integer math */
265518
- Wei: string;
265519
- };
265520
- }>({
265521
- instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT!,
265522
- accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!, // undefined in browser, by design to not leak the secrets
265523
- });
265524
-
265525
- export const blockscoutUiEndpoint = process.env.SETTLEMINT_BLOCKSCOUT_UI_ENDPOINT!;`;
265526
- await writeTemplate(template, "/lib/settlemint", "blockscout.ts");
265527
- const projectDir = await projectRoot3();
265528
- if (!await isPackageInstalled(PACKAGE_NAME4, projectDir)) {
265529
- await installDependencies(PACKAGE_NAME4, projectDir);
265392
+ done({ clearContent }) {
265393
+ this.rl.setPrompt("");
265394
+ let output = cursorDown2(this.extraLinesUnderPrompt);
265395
+ output += clearContent ? import_ansi_escapes2.default.eraseLines(this.height) : `
265396
+ `;
265397
+ output += import_ansi_escapes2.default.cursorShow;
265398
+ this.write(output);
265399
+ this.rl.close();
265530
265400
  }
265531
265401
  }
265532
265402
 
265533
- // src/commands/codegen/codegen-ipfs.ts
265534
- var PACKAGE_NAME5 = "@settlemint/sdk-ipfs";
265535
- function shouldCodegenIpfs(env2) {
265536
- return !!env2.SETTLEMINT_IPFS_API_ENDPOINT;
265537
- }
265538
- async function codegenIpfs(env2) {
265539
- const endpoint = env2.SETTLEMINT_IPFS_API_ENDPOINT;
265540
- if (!endpoint) {
265541
- return;
265403
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/promise-polyfill.js
265404
+ class PromisePolyfill2 extends Promise {
265405
+ static withResolver() {
265406
+ let resolve5;
265407
+ let reject;
265408
+ const promise = new Promise((res, rej) => {
265409
+ resolve5 = res;
265410
+ reject = rej;
265411
+ });
265412
+ return { promise, resolve: resolve5, reject };
265542
265413
  }
265543
- const clientTemplate = `import { createServerIpfsClient } from "${PACKAGE_NAME5}";
265414
+ }
265544
265415
 
265545
- export const { client } = createServerIpfsClient({
265546
- instance: process.env.SETTLEMINT_IPFS_API_ENDPOINT!,
265547
- accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
265548
- });`;
265549
- await writeTemplate(clientTemplate, "/lib/settlemint", "ipfs.ts");
265550
- const projectDir = await projectRoot3();
265551
- if (!await isPackageInstalled(PACKAGE_NAME5, projectDir)) {
265552
- await installDependencies(PACKAGE_NAME5, projectDir);
265416
+ // ../../node_modules/@inquirer/input/node_modules/@inquirer/core/dist/esm/lib/create-prompt.js
265417
+ function getCallSites2() {
265418
+ const _prepareStackTrace = Error.prepareStackTrace;
265419
+ let result = [];
265420
+ try {
265421
+ Error.prepareStackTrace = (_5, callSites) => {
265422
+ const callSitesWithoutCurrent = callSites.slice(1);
265423
+ result = callSitesWithoutCurrent;
265424
+ return callSitesWithoutCurrent;
265425
+ };
265426
+ new Error().stack;
265427
+ } catch {
265428
+ return result;
265553
265429
  }
265430
+ Error.prepareStackTrace = _prepareStackTrace;
265431
+ return result;
265554
265432
  }
265555
-
265556
- // src/commands/codegen/codegen-minio.ts
265557
- var PACKAGE_NAME6 = "@settlemint/sdk-minio";
265558
- function shouldCodegenMinio(env2) {
265559
- return !!(env2.SETTLEMINT_MINIO_ENDPOINT && env2.SETTLEMINT_MINIO_ACCESS_KEY && env2.SETTLEMINT_MINIO_SECRET_KEY);
265560
- }
265561
- async function codegenMinio(env2) {
265562
- const endpoint = env2.SETTLEMINT_MINIO_ENDPOINT;
265563
- if (!endpoint) {
265564
- return;
265565
- }
265566
- const clientTemplate = `import { createServerMinioClient } from "${PACKAGE_NAME6}";
265567
-
265568
- export const { client } = createServerMinioClient({
265569
- instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
265570
- accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
265571
- accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
265572
- secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
265573
- });`;
265574
- await writeTemplate(clientTemplate, "/lib/settlemint", "minio.ts");
265575
- const projectDir = await projectRoot3();
265576
- if (!await isPackageInstalled(PACKAGE_NAME6, projectDir)) {
265577
- await installDependencies(PACKAGE_NAME6, projectDir);
265578
- }
265579
- }
265580
-
265581
- // src/commands/codegen.ts
265582
- function codegenCommand() {
265583
- return new Command("codegen").option("--prod", "Connect to your production environment").option("--thegraph-subgraph-names <subgraph-names...>", "The name(s) of the TheGraph subgraph(s) to generate (skip if you want to generate all)").description("Generate GraphQL and REST types and queries").usage(createExamples([
265584
- {
265585
- description: "Generate GraphQL types and queries for your dApp",
265586
- command: "codegen"
265587
- },
265588
- {
265589
- description: "Generate GraphQL types and queries for specific TheGraph subgraphs",
265590
- command: "codegen --thegraph-subgraph-names subgraph1 subgraph2"
265591
- }
265592
- ])).action(async ({ prod, thegraphSubgraphNames }) => {
265593
- intro("Generating GraphQL types and queries for your dApp");
265594
- const env2 = await loadEnv(true, !!prod);
265595
- if (!Array.isArray(thegraphSubgraphNames)) {
265596
- thegraphSubgraphNames = await subgraphPrompt({
265597
- env: env2,
265598
- accept: true,
265599
- message: "Which The Graph subgraph do you want to generate types for?",
265600
- allowAll: true
265601
- });
265602
- }
265603
- const { hasura, portal, thegraph, blockscout } = await spinner({
265604
- startMessage: "Testing configured GraphQL schema",
265605
- task: async () => {
265606
- return codegenTsconfig(env2, thegraphSubgraphNames);
265607
- },
265608
- stopMessage: "Tested GraphQL schemas"
265433
+ function createPrompt2(view) {
265434
+ const callSites = getCallSites2();
265435
+ const prompt = (config3, context = {}) => {
265436
+ const { input = process.stdin, signal } = context;
265437
+ const cleanups = new Set;
265438
+ const output = new import_mute_stream2.default;
265439
+ output.pipe(context.output ?? process.stdout);
265440
+ const rl = readline4.createInterface({
265441
+ terminal: true,
265442
+ input,
265443
+ output
265609
265444
  });
265610
- if (hasura) {
265611
- note("Generating Hasura resources");
265612
- await codegenHasura(env2);
265613
- }
265614
- if (portal) {
265615
- note("Generating Portal resources");
265616
- await codegenPortal(env2);
265617
- }
265618
- if (thegraph) {
265619
- note("Generating TheGraph resources");
265620
- await codegenTheGraph(env2, thegraphSubgraphNames);
265621
- }
265622
- if (blockscout) {
265623
- note("Generating Blockscout resources");
265624
- await codegenBlockscout(env2);
265625
- }
265626
- if (shouldCodegenMinio(env2)) {
265627
- note("Generating Minio resources");
265628
- await codegenMinio(env2);
265629
- }
265630
- if (shouldCodegenIpfs(env2)) {
265631
- note("Generating IPFS resources");
265632
- await codegenIpfs(env2);
265445
+ const screen = new ScreenManager2(rl);
265446
+ const { promise, resolve: resolve5, reject } = PromisePolyfill2.withResolver();
265447
+ const cancel3 = () => reject(new CancelPromptError2);
265448
+ if (signal) {
265449
+ const abort = () => reject(new AbortPromptError2({ cause: signal.reason }));
265450
+ if (signal.aborted) {
265451
+ abort();
265452
+ return Object.assign(promise, { cancel: cancel3 });
265453
+ }
265454
+ signal.addEventListener("abort", abort);
265455
+ cleanups.add(() => signal.removeEventListener("abort", abort));
265633
265456
  }
265634
- if (hasura || portal || thegraph || blockscout) {
265635
- await generateOutput({
265636
- output: undefined,
265637
- tsconfig: undefined
265457
+ cleanups.add(onExit((code2, signal2) => {
265458
+ reject(new ExitPromptError2(`User force closed the prompt with ${code2} ${signal2}`));
265459
+ }));
265460
+ const checkCursorPos = () => screen.checkCursorPos();
265461
+ rl.input.on("keypress", checkCursorPos);
265462
+ cleanups.add(() => rl.input.removeListener("keypress", checkCursorPos));
265463
+ return withHooks2(rl, (cycle) => {
265464
+ const hooksCleanup = AsyncResource6.bind(() => effectScheduler2.clearAll());
265465
+ rl.on("close", hooksCleanup);
265466
+ cleanups.add(() => rl.removeListener("close", hooksCleanup));
265467
+ cycle(() => {
265468
+ try {
265469
+ const nextView = view(config3, (value4) => {
265470
+ setImmediate(() => resolve5(value4));
265471
+ });
265472
+ if (nextView === undefined) {
265473
+ const callerFilename = callSites[1]?.getFileName?.();
265474
+ throw new Error(`Prompt functions must return a string.
265475
+ at ${callerFilename}`);
265476
+ }
265477
+ const [content, bottomContent] = typeof nextView === "string" ? [nextView] : nextView;
265478
+ screen.render(content, bottomContent);
265479
+ effectScheduler2.run();
265480
+ } catch (error5) {
265481
+ reject(error5);
265482
+ }
265638
265483
  });
265639
- }
265640
- outro("Codegen complete");
265641
- });
265642
- }
265643
-
265644
- // ../../node_modules/@inquirer/confirm/dist/esm/index.js
265645
- function getBooleanValue(value4, defaultValue) {
265646
- let answer = defaultValue !== false;
265647
- if (/^(y|yes)/i.test(value4))
265648
- answer = true;
265649
- else if (/^(n|no)/i.test(value4))
265650
- answer = false;
265651
- return answer;
265652
- }
265653
- function boolToString(value4) {
265654
- return value4 ? "Yes" : "No";
265484
+ return Object.assign(promise.then((answer) => {
265485
+ effectScheduler2.clearAll();
265486
+ return answer;
265487
+ }, (error5) => {
265488
+ effectScheduler2.clearAll();
265489
+ throw error5;
265490
+ }).finally(() => {
265491
+ cleanups.forEach((cleanup) => cleanup());
265492
+ screen.done({ clearContent: Boolean(context.clearPromptOnDone) });
265493
+ output.end();
265494
+ }).then(() => promise), { cancel: cancel3 });
265495
+ });
265496
+ };
265497
+ return prompt;
265655
265498
  }
265656
- var esm_default4 = createPrompt((config3, done) => {
265657
- const { transformer = boolToString } = config3;
265658
- const [status, setStatus] = useState("idle");
265659
- const [value4, setValue] = useState("");
265660
- const theme = makeTheme(config3.theme);
265661
- const prefix = usePrefix({ status, theme });
265662
- useKeypress((key2, rl) => {
265663
- if (isEnterKey(key2)) {
265664
- const answer = getBooleanValue(value4, config3.default);
265665
- setValue(transformer(answer));
265666
- setStatus("done");
265667
- done(answer);
265668
- } else if (key2.name === "tab") {
265669
- const answer = boolToString(!getBooleanValue(value4, config3.default));
265499
+ // ../../node_modules/@inquirer/input/dist/esm/index.js
265500
+ var inputTheme = {
265501
+ validationFailureMode: "keep"
265502
+ };
265503
+ var esm_default2 = createPrompt2((config3, done) => {
265504
+ const { required, validate: validate3 = () => true } = config3;
265505
+ const theme = makeTheme2(inputTheme, config3.theme);
265506
+ const [status, setStatus] = useState2("idle");
265507
+ const [defaultValue = "", setDefaultValue] = useState2(config3.default);
265508
+ const [errorMsg, setError] = useState2();
265509
+ const [value4, setValue] = useState2("");
265510
+ const prefix = usePrefix2({ status, theme });
265511
+ useKeypress2(async (key3, rl) => {
265512
+ if (status !== "idle") {
265513
+ return;
265514
+ }
265515
+ if (isEnterKey2(key3)) {
265516
+ const answer = value4 || defaultValue;
265517
+ setStatus("loading");
265518
+ const isValid2 = required && !answer ? "You must provide a value" : await validate3(answer);
265519
+ if (isValid2 === true) {
265520
+ setValue(answer);
265521
+ setStatus("done");
265522
+ done(answer);
265523
+ } else {
265524
+ if (theme.validationFailureMode === "clear") {
265525
+ setValue("");
265526
+ } else {
265527
+ rl.write(value4);
265528
+ }
265529
+ setError(isValid2 || "You must provide a valid value");
265530
+ setStatus("idle");
265531
+ }
265532
+ } else if (isBackspaceKey2(key3) && !value4) {
265533
+ setDefaultValue(undefined);
265534
+ } else if (key3.name === "tab" && !value4) {
265535
+ setDefaultValue(undefined);
265670
265536
  rl.clearLine(0);
265671
- rl.write(answer);
265672
- setValue(answer);
265537
+ rl.write(defaultValue);
265538
+ setValue(defaultValue);
265673
265539
  } else {
265674
265540
  setValue(rl.line);
265541
+ setError(undefined);
265675
265542
  }
265676
265543
  });
265544
+ const message = theme.style.message(config3.message, status);
265677
265545
  let formattedValue = value4;
265678
- let defaultValue = "";
265679
- if (status === "done") {
265546
+ if (typeof config3.transformer === "function") {
265547
+ formattedValue = config3.transformer(value4, { isFinal: status === "done" });
265548
+ } else if (status === "done") {
265680
265549
  formattedValue = theme.style.answer(value4);
265681
- } else {
265682
- defaultValue = ` ${theme.style.defaultAnswer(config3.default === false ? "y/N" : "Y/n")}`;
265683
265550
  }
265684
- const message = theme.style.message(config3.message, status);
265685
- return `${prefix} ${message}${defaultValue} ${formattedValue}`;
265551
+ let defaultStr;
265552
+ if (defaultValue && status !== "done" && !value4) {
265553
+ defaultStr = theme.style.defaultAnswer(defaultValue);
265554
+ }
265555
+ let error5 = "";
265556
+ if (errorMsg) {
265557
+ error5 = theme.style.error(errorMsg);
265558
+ }
265559
+ return [
265560
+ [prefix, message, defaultStr, formattedValue].filter((v6) => v6 !== undefined).join(" "),
265561
+ error5
265562
+ ];
265686
265563
  });
265687
265564
 
265688
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/key.js
265689
- var isEnterKey2 = (key2) => key2.name === "enter" || key2.name === "return";
265690
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/errors.js
265691
- class AbortPromptError2 extends Error {
265692
- name = "AbortPromptError";
265693
- message = "Prompt was aborted";
265694
- constructor(options) {
265695
- super();
265696
- this.cause = options?.cause;
265565
+ // src/prompts/smart-contract-set/subgraph-name.prompt.ts
265566
+ async function subgraphNamePrompt({
265567
+ defaultName,
265568
+ env: env2,
265569
+ accept
265570
+ }) {
265571
+ const defaultSubgraphName = defaultName ? sanitizeName(defaultName) : undefined;
265572
+ if (accept) {
265573
+ return defaultSubgraphName ?? env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH;
265697
265574
  }
265575
+ const subgraphName = await esm_default2({
265576
+ message: "What is the name of your subgraph?",
265577
+ default: defaultSubgraphName,
265578
+ required: true
265579
+ });
265580
+ return sanitizeName(subgraphName);
265698
265581
  }
265699
265582
 
265700
- class CancelPromptError2 extends Error {
265701
- name = "CancelPromptError";
265702
- message = "Prompt was canceled";
265703
- }
265704
-
265705
- class ExitPromptError2 extends Error {
265706
- name = "ExitPromptError";
265707
- }
265708
-
265709
- class HookError2 extends Error {
265710
- name = "HookError";
265711
- }
265712
-
265713
- class ValidationError2 extends Error {
265714
- name = "ValidationError";
265715
- }
265716
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/use-prefix.js
265717
- import { AsyncResource as AsyncResource5 } from "node:async_hooks";
265718
-
265719
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/hook-engine.js
265720
- import { AsyncLocalStorage as AsyncLocalStorage2, AsyncResource as AsyncResource4 } from "node:async_hooks";
265721
- var hookStorage2 = new AsyncLocalStorage2;
265722
- function createStore2(rl) {
265723
- const store = {
265724
- rl,
265725
- hooks: [],
265726
- hooksCleanup: [],
265727
- hooksEffect: [],
265728
- index: 0,
265729
- handleChange() {}
265730
- };
265731
- return store;
265583
+ // ../../node_modules/@inquirer/select/dist/esm/index.js
265584
+ var import_yoctocolors_cjs4 = __toESM(require_yoctocolors_cjs(), 1);
265585
+ var import_ansi_escapes3 = __toESM(require_ansi_escapes(), 1);
265586
+ var selectTheme = {
265587
+ icon: { cursor: esm_default.pointer },
265588
+ style: {
265589
+ disabled: (text2) => import_yoctocolors_cjs4.default.dim(`- ${text2}`),
265590
+ description: (text2) => import_yoctocolors_cjs4.default.cyan(text2)
265591
+ },
265592
+ helpMode: "auto"
265593
+ };
265594
+ function isSelectable(item) {
265595
+ return !Separator.isSeparator(item) && !item.disabled;
265732
265596
  }
265733
- function withHooks2(rl, cb) {
265734
- const store = createStore2(rl);
265735
- return hookStorage2.run(store, () => {
265736
- function cycle(render) {
265737
- store.handleChange = () => {
265738
- store.index = 0;
265739
- render();
265597
+ function normalizeChoices(choices) {
265598
+ return choices.map((choice) => {
265599
+ if (Separator.isSeparator(choice))
265600
+ return choice;
265601
+ if (typeof choice === "string") {
265602
+ return {
265603
+ value: choice,
265604
+ name: choice,
265605
+ short: choice,
265606
+ disabled: false
265740
265607
  };
265741
- store.handleChange();
265742
265608
  }
265743
- return cb(cycle);
265609
+ const name3 = choice.name ?? String(choice.value);
265610
+ return {
265611
+ value: choice.value,
265612
+ name: name3,
265613
+ description: choice.description,
265614
+ short: choice.short ?? name3,
265615
+ disabled: choice.disabled ?? false
265616
+ };
265744
265617
  });
265745
265618
  }
265746
- function getStore2() {
265747
- const store = hookStorage2.getStore();
265748
- if (!store) {
265749
- throw new HookError2("[Inquirer] Hook functions can only be called from within a prompt");
265750
- }
265751
- return store;
265752
- }
265753
- function readline3() {
265754
- return getStore2().rl;
265755
- }
265756
- function withUpdates2(fn) {
265757
- const wrapped = (...args) => {
265758
- const store = getStore2();
265759
- let shouldUpdate = false;
265760
- const oldHandleChange = store.handleChange;
265761
- store.handleChange = () => {
265762
- shouldUpdate = true;
265763
- };
265764
- const returnValue = fn(...args);
265765
- if (shouldUpdate) {
265766
- oldHandleChange();
265619
+ var esm_default3 = createPrompt((config3, done) => {
265620
+ const { loop = true, pageSize = 7 } = config3;
265621
+ const firstRender = useRef(true);
265622
+ const theme = makeTheme(selectTheme, config3.theme);
265623
+ const [status, setStatus] = useState("idle");
265624
+ const prefix = usePrefix({ status, theme });
265625
+ const searchTimeoutRef = useRef();
265626
+ const items = useMemo(() => normalizeChoices(config3.choices), [config3.choices]);
265627
+ const bounds = useMemo(() => {
265628
+ const first = items.findIndex(isSelectable);
265629
+ const last = items.findLastIndex(isSelectable);
265630
+ if (first === -1) {
265631
+ throw new ValidationError("[select prompt] No selectable choices. All choices are disabled.");
265767
265632
  }
265768
- store.handleChange = oldHandleChange;
265769
- return returnValue;
265770
- };
265771
- return AsyncResource4.bind(wrapped);
265772
- }
265773
- function withPointer2(cb) {
265774
- const store = getStore2();
265775
- const { index } = store;
265776
- const pointer = {
265777
- get() {
265778
- return store.hooks[index];
265779
- },
265780
- set(value4) {
265781
- store.hooks[index] = value4;
265782
- },
265783
- initialized: index in store.hooks
265784
- };
265785
- const returnValue = cb(pointer);
265786
- store.index++;
265787
- return returnValue;
265788
- }
265789
- function handleChange2() {
265790
- getStore2().handleChange();
265791
- }
265792
- var effectScheduler2 = {
265793
- queue(cb) {
265794
- const store = getStore2();
265795
- const { index } = store;
265796
- store.hooksEffect.push(() => {
265797
- store.hooksCleanup[index]?.();
265798
- const cleanFn = cb(readline3());
265799
- if (cleanFn != null && typeof cleanFn !== "function") {
265800
- throw new ValidationError2("useEffect return value must be a cleanup function or nothing.");
265633
+ return { first, last };
265634
+ }, [items]);
265635
+ const defaultItemIndex = useMemo(() => {
265636
+ if (!("default" in config3))
265637
+ return -1;
265638
+ return items.findIndex((item) => isSelectable(item) && item.value === config3.default);
265639
+ }, [config3.default, items]);
265640
+ const [active, setActive] = useState(defaultItemIndex === -1 ? bounds.first : defaultItemIndex);
265641
+ const selectedChoice = items[active];
265642
+ useKeypress((key3, rl) => {
265643
+ clearTimeout(searchTimeoutRef.current);
265644
+ if (isEnterKey(key3)) {
265645
+ setStatus("done");
265646
+ done(selectedChoice.value);
265647
+ } else if (isUpKey(key3) || isDownKey(key3)) {
265648
+ rl.clearLine(0);
265649
+ if (loop || isUpKey(key3) && active !== bounds.first || isDownKey(key3) && active !== bounds.last) {
265650
+ const offset = isUpKey(key3) ? -1 : 1;
265651
+ let next = active;
265652
+ do {
265653
+ next = (next + offset + items.length) % items.length;
265654
+ } while (!isSelectable(items[next]));
265655
+ setActive(next);
265801
265656
  }
265802
- store.hooksCleanup[index] = cleanFn;
265803
- });
265804
- },
265805
- run() {
265806
- const store = getStore2();
265807
- withUpdates2(() => {
265808
- store.hooksEffect.forEach((effect) => {
265809
- effect();
265657
+ } else if (isNumberKey(key3)) {
265658
+ rl.clearLine(0);
265659
+ const position = Number(key3.name) - 1;
265660
+ const item = items[position];
265661
+ if (item != null && isSelectable(item)) {
265662
+ setActive(position);
265663
+ }
265664
+ } else if (isBackspaceKey(key3)) {
265665
+ rl.clearLine(0);
265666
+ } else {
265667
+ const searchTerm = rl.line.toLowerCase();
265668
+ const matchIndex = items.findIndex((item) => {
265669
+ if (Separator.isSeparator(item) || !isSelectable(item))
265670
+ return false;
265671
+ return item.name.toLowerCase().startsWith(searchTerm);
265810
265672
  });
265811
- store.hooksEffect.length = 0;
265812
- })();
265813
- },
265814
- clearAll() {
265815
- const store = getStore2();
265816
- store.hooksCleanup.forEach((cleanFn) => {
265817
- cleanFn?.();
265818
- });
265819
- store.hooksEffect.length = 0;
265820
- store.hooksCleanup.length = 0;
265821
- }
265822
- };
265823
-
265824
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/use-state.js
265825
- function useState2(defaultValue) {
265826
- return withPointer2((pointer) => {
265827
- const setFn = (newValue) => {
265828
- if (pointer.get() !== newValue) {
265829
- pointer.set(newValue);
265830
- handleChange2();
265673
+ if (matchIndex !== -1) {
265674
+ setActive(matchIndex);
265831
265675
  }
265832
- };
265833
- if (pointer.initialized) {
265834
- return [pointer.get(), setFn];
265676
+ searchTimeoutRef.current = setTimeout(() => {
265677
+ rl.clearLine(0);
265678
+ }, 700);
265835
265679
  }
265836
- const value4 = typeof defaultValue === "function" ? defaultValue() : defaultValue;
265837
- pointer.set(value4);
265838
- return [value4, setFn];
265839
265680
  });
265840
- }
265841
-
265842
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/use-effect.js
265843
- function useEffect2(cb, depArray) {
265844
- withPointer2((pointer) => {
265845
- const oldDeps = pointer.get();
265846
- const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i6) => !Object.is(dep, oldDeps[i6]));
265847
- if (hasChanged) {
265848
- effectScheduler2.queue(cb);
265681
+ useEffect(() => () => {
265682
+ clearTimeout(searchTimeoutRef.current);
265683
+ }, []);
265684
+ const message = theme.style.message(config3.message, status);
265685
+ let helpTipTop = "";
265686
+ let helpTipBottom = "";
265687
+ if (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current) {
265688
+ firstRender.current = false;
265689
+ if (items.length > pageSize) {
265690
+ helpTipBottom = `
265691
+ ${theme.style.help("(Use arrow keys to reveal more choices)")}`;
265692
+ } else {
265693
+ helpTipTop = theme.style.help("(Use arrow keys)");
265849
265694
  }
265850
- pointer.set(depArray);
265695
+ }
265696
+ const page = usePagination({
265697
+ items,
265698
+ active,
265699
+ renderItem({ item, isActive }) {
265700
+ if (Separator.isSeparator(item)) {
265701
+ return ` ${item.separator}`;
265702
+ }
265703
+ if (item.disabled) {
265704
+ const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
265705
+ return theme.style.disabled(`${item.name} ${disabledLabel}`);
265706
+ }
265707
+ const color = isActive ? theme.style.highlight : (x6) => x6;
265708
+ const cursor = isActive ? theme.icon.cursor : ` `;
265709
+ return color(`${cursor} ${item.name}`);
265710
+ },
265711
+ pageSize,
265712
+ loop
265851
265713
  });
265852
- }
265853
-
265854
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/theme.js
265855
- var import_yoctocolors_cjs4 = __toESM(require_yoctocolors_cjs(), 1);
265856
- var defaultTheme2 = {
265857
- prefix: {
265858
- idle: import_yoctocolors_cjs4.default.blue("?"),
265859
- done: import_yoctocolors_cjs4.default.green(esm_default.tick)
265860
- },
265861
- spinner: {
265862
- interval: 80,
265863
- frames: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"].map((frame) => import_yoctocolors_cjs4.default.yellow(frame))
265864
- },
265865
- style: {
265866
- answer: import_yoctocolors_cjs4.default.cyan,
265867
- message: import_yoctocolors_cjs4.default.bold,
265868
- error: (text2) => import_yoctocolors_cjs4.default.red(`> ${text2}`),
265869
- defaultAnswer: (text2) => import_yoctocolors_cjs4.default.dim(`(${text2})`),
265870
- help: import_yoctocolors_cjs4.default.dim,
265871
- highlight: import_yoctocolors_cjs4.default.cyan,
265872
- key: (text2) => import_yoctocolors_cjs4.default.cyan(import_yoctocolors_cjs4.default.bold(`<${text2}>`))
265714
+ if (status === "done") {
265715
+ return `${prefix} ${message} ${theme.style.answer(selectedChoice.short)}`;
265873
265716
  }
265874
- };
265717
+ const choiceDescription = selectedChoice.description ? `
265718
+ ${theme.style.description(selectedChoice.description)}` : ``;
265719
+ return `${[prefix, message, helpTipTop].filter(Boolean).join(" ")}
265720
+ ${page}${helpTipBottom}${choiceDescription}${import_ansi_escapes3.default.cursorHide}`;
265721
+ });
265875
265722
 
265876
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/make-theme.js
265877
- function isPlainObject3(value4) {
265878
- if (typeof value4 !== "object" || value4 === null)
265879
- return false;
265880
- let proto = value4;
265881
- while (Object.getPrototypeOf(proto) !== null) {
265882
- proto = Object.getPrototypeOf(proto);
265883
- }
265884
- return Object.getPrototypeOf(value4) === proto;
265885
- }
265886
- function deepMerge3(...objects) {
265887
- const output = {};
265888
- for (const obj of objects) {
265889
- for (const [key2, value4] of Object.entries(obj)) {
265890
- const prevValue = output[key2];
265891
- output[key2] = isPlainObject3(prevValue) && isPlainObject3(value4) ? deepMerge3(prevValue, value4) : value4;
265723
+ // src/prompts/smart-contract-set/subgraph.prompt.ts
265724
+ var ALL = "All";
265725
+ var NEW = "New subgraph";
265726
+ async function subgraphPrompt({
265727
+ env: env2,
265728
+ accept,
265729
+ message,
265730
+ allowAll = false,
265731
+ allowNew = false,
265732
+ isCi = is_in_ci_default
265733
+ }) {
265734
+ const autoAccept = isCi || !!accept;
265735
+ const subgraphNames = env2.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS?.map((endpoint) => endpoint.split("/").pop()).filter(Boolean) ?? [];
265736
+ if (autoAccept) {
265737
+ if (allowAll) {
265738
+ return subgraphNames;
265892
265739
  }
265740
+ if (env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH) {
265741
+ return [env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH];
265742
+ }
265743
+ return subgraphNames.length === 1 ? subgraphNames : [];
265893
265744
  }
265894
- return output;
265895
- }
265896
- function makeTheme2(...themes) {
265897
- const themesToMerge = [
265898
- defaultTheme2,
265899
- ...themes.filter((theme) => theme != null)
265900
- ];
265901
- return deepMerge3(...themesToMerge);
265902
- }
265903
-
265904
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/use-prefix.js
265905
- function usePrefix2({ status = "idle", theme }) {
265906
- const [showLoader, setShowLoader] = useState2(false);
265907
- const [tick, setTick] = useState2(0);
265908
- const { prefix, spinner: spinner2 } = makeTheme2(theme);
265909
- useEffect2(() => {
265910
- if (status === "loading") {
265911
- let tickInterval;
265912
- let inc = -1;
265913
- const delayTimeout = setTimeout(AsyncResource5.bind(() => {
265914
- setShowLoader(true);
265915
- tickInterval = setInterval(AsyncResource5.bind(() => {
265916
- inc = inc + 1;
265917
- setTick(inc % spinner2.frames.length);
265918
- }), spinner2.interval);
265919
- }), 300);
265920
- return () => {
265921
- clearTimeout(delayTimeout);
265922
- clearInterval(tickInterval);
265923
- };
265924
- } else {
265925
- setShowLoader(false);
265745
+ if (!allowNew) {
265746
+ if (subgraphNames.length === 0) {
265747
+ cancel2("No subgraphs found");
265748
+ }
265749
+ if (subgraphNames.length === 1) {
265750
+ return subgraphNames;
265926
265751
  }
265927
- }, [status]);
265928
- if (showLoader) {
265929
- return spinner2.frames[tick];
265930
265752
  }
265931
- const iconName = status === "loading" ? "idle" : status;
265932
- return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix["idle"];
265933
- }
265934
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/use-ref.js
265935
- function useRef2(val) {
265936
- return useState2({ current: val })[0];
265937
- }
265938
-
265939
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/use-keypress.js
265940
- function useKeypress2(userHandler) {
265941
- const signal = useRef2(userHandler);
265942
- signal.current = userHandler;
265943
- useEffect2((rl) => {
265944
- let ignore = false;
265945
- const handler = withUpdates2((_input, event) => {
265946
- if (ignore)
265947
- return;
265948
- signal.current(event, rl);
265753
+ const choices = subgraphNames.slice().sort();
265754
+ if (allowAll) {
265755
+ choices.unshift(ALL);
265756
+ }
265757
+ if (allowNew) {
265758
+ choices.unshift(NEW);
265759
+ }
265760
+ let defaultChoice;
265761
+ if (allowAll) {
265762
+ defaultChoice = ALL;
265763
+ } else if (allowNew) {
265764
+ defaultChoice = env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH ?? NEW;
265765
+ } else {
265766
+ defaultChoice = env2.SETTLEMINT_THEGRAPH_DEFAULT_SUBGRAPH ?? subgraphNames[0];
265767
+ }
265768
+ const subgraphName = choices.length === 1 && choices[0] === NEW ? NEW : await esm_default3({
265769
+ message,
265770
+ choices: choices.map((name3) => ({
265771
+ name: name3,
265772
+ value: name3
265773
+ })),
265774
+ default: defaultChoice
265775
+ });
265776
+ if (!subgraphName) {
265777
+ cancel2("No subgraph selected");
265778
+ }
265779
+ if (subgraphName === NEW) {
265780
+ const newSubgraphName = await subgraphNamePrompt({
265781
+ defaultName: "",
265782
+ env: env2,
265783
+ accept: autoAccept
265949
265784
  });
265950
- rl.input.on("keypress", handler);
265951
- return () => {
265952
- ignore = true;
265953
- rl.input.removeListener("keypress", handler);
265954
- };
265955
- }, []);
265956
- }
265957
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/utils.js
265958
- var import_cli_width2 = __toESM(require_cli_width(), 1);
265959
- var import_wrap_ansi2 = __toESM(require_wrap_ansi(), 1);
265960
- function breakLines2(content, width) {
265961
- return content.split(`
265962
- `).flatMap((line) => import_wrap_ansi2.default(line, width, { trim: false, hard: true }).split(`
265963
- `).map((str) => str.trimEnd())).join(`
265964
- `);
265965
- }
265966
- function readlineWidth2() {
265967
- return import_cli_width2.default({ defaultWidth: 80, output: readline3().output });
265785
+ if (!newSubgraphName) {
265786
+ return [];
265787
+ }
265788
+ return [newSubgraphName];
265789
+ }
265790
+ return subgraphName === ALL ? subgraphNames : [subgraphName];
265968
265791
  }
265969
265792
 
265970
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/create-prompt.js
265971
- var import_mute_stream2 = __toESM(require_lib(), 1);
265972
- import * as readline4 from "node:readline";
265973
- import { AsyncResource as AsyncResource6 } from "node:async_hooks";
265793
+ // src/utils/commands/create-examples.ts
265794
+ function createExamples(examples) {
265795
+ return `
265796
+ Examples:
265974
265797
 
265975
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/screen-manager.js
265976
- var import_ansi_escapes3 = __toESM(require_ansi_escapes(), 1);
265977
- import { stripVTControlCharacters as stripVTControlCharacters3 } from "node:util";
265978
- var height2 = (content) => content.split(`
265979
- `).length;
265980
- var lastLine2 = (content) => content.split(`
265981
- `).pop() ?? "";
265982
- function cursorDown2(n6) {
265983
- return n6 > 0 ? import_ansi_escapes3.default.cursorDown(n6) : "";
265798
+ ${examples.map(({ description, command, commandPrefix }) => {
265799
+ return ` # ${description}
265800
+ $ ${commandPrefix ?? ""}settlemint ${command}`;
265801
+ }).join(`
265802
+
265803
+ `)}`;
265984
265804
  }
265985
265805
 
265986
- class ScreenManager2 {
265987
- height = 0;
265988
- extraLinesUnderPrompt = 0;
265989
- cursorPos;
265990
- rl;
265991
- constructor(rl) {
265992
- this.rl = rl;
265993
- this.cursorPos = rl.getCursorPos();
265806
+ // src/commands/codegen/codegen-blockscout.ts
265807
+ import { rm as rm2, writeFile as writeFile6 } from "node:fs/promises";
265808
+ import { basename, resolve as resolve5 } from "node:path";
265809
+ var PACKAGE_NAME4 = "@settlemint/sdk-blockscout";
265810
+ async function codegenBlockscout(env2) {
265811
+ const endpoint = env2.SETTLEMINT_BLOCKSCOUT_GRAPHQL_ENDPOINT;
265812
+ if (!endpoint) {
265813
+ return;
265994
265814
  }
265995
- write(content) {
265996
- this.rl.output.unmute();
265997
- this.rl.output.write(content);
265998
- this.rl.output.mute();
265815
+ const accessToken = await getApplicationOrPersonalAccessToken({
265816
+ env: env2,
265817
+ instance: env2.SETTLEMINT_INSTANCE,
265818
+ prefer: "application"
265819
+ });
265820
+ if (!accessToken) {
265821
+ return;
265999
265822
  }
266000
- render(content, bottomContent = "") {
266001
- const promptLine = lastLine2(content);
266002
- const rawPromptLine = stripVTControlCharacters3(promptLine);
266003
- let prompt = rawPromptLine;
266004
- if (this.rl.line.length > 0) {
266005
- prompt = prompt.slice(0, -this.rl.line.length);
266006
- }
266007
- this.rl.setPrompt(prompt);
266008
- this.cursorPos = this.rl.getCursorPos();
266009
- const width = readlineWidth2();
266010
- content = breakLines2(content, width);
266011
- bottomContent = breakLines2(bottomContent, width);
266012
- if (rawPromptLine.length % width === 0) {
266013
- content += `
266014
- `;
266015
- }
266016
- let output = content + (bottomContent ? `
266017
- ` + bottomContent : "");
266018
- const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
266019
- const bottomContentHeight = promptLineUpDiff + (bottomContent ? height2(bottomContent) : 0);
266020
- if (bottomContentHeight > 0)
266021
- output += import_ansi_escapes3.default.cursorUp(bottomContentHeight);
266022
- output += import_ansi_escapes3.default.cursorTo(this.cursorPos.cols);
266023
- this.write(cursorDown2(this.extraLinesUnderPrompt) + import_ansi_escapes3.default.eraseLines(this.height) + output);
266024
- this.extraLinesUnderPrompt = bottomContentHeight;
266025
- this.height = height2(output);
265823
+ const introspectionJsonPath = resolve5(process.cwd(), "__blockscout-introspection__.json");
265824
+ try {
265825
+ const data = await graphqlFetchWithRetry(endpoint, {
265826
+ method: "POST",
265827
+ headers: {
265828
+ "x-auth-token": accessToken,
265829
+ "Content-Type": "application/json"
265830
+ },
265831
+ body: JSON.stringify({
265832
+ query: `
265833
+ query IntrospectionQuery {
265834
+ __schema {
265835
+ queryType { name }
265836
+ mutationType { name }
265837
+ types {
265838
+ ...FullType
265839
+ }
265840
+ directives {
265841
+ name
265842
+ description
265843
+ locations
265844
+ args {
265845
+ ...InputValue
265846
+ }
265847
+ }
265848
+ }
265849
+ }
265850
+
265851
+ fragment FullType on __Type {
265852
+ kind
265853
+ name
265854
+ description
265855
+ fields(includeDeprecated: true) {
265856
+ name
265857
+ description
265858
+ args {
265859
+ ...InputValue
265860
+ }
265861
+ type {
265862
+ ...TypeRef
265863
+ }
265864
+ isDeprecated
265865
+ deprecationReason
265866
+ }
265867
+ inputFields {
265868
+ ...InputValue
265869
+ }
265870
+ interfaces {
265871
+ ...TypeRef
265872
+ }
265873
+ enumValues(includeDeprecated: true) {
265874
+ name
265875
+ description
265876
+ isDeprecated
265877
+ deprecationReason
265878
+ }
265879
+ possibleTypes {
265880
+ ...TypeRef
265881
+ }
265882
+ }
265883
+
265884
+ fragment InputValue on __InputValue {
265885
+ name
265886
+ description
265887
+ type { ...TypeRef }
265888
+ defaultValue
265889
+ }
265890
+
265891
+ fragment TypeRef on __Type {
265892
+ kind
265893
+ name
265894
+ ofType {
265895
+ kind
265896
+ name
265897
+ ofType {
265898
+ kind
265899
+ name
265900
+ ofType {
265901
+ kind
265902
+ name
265903
+ ofType {
265904
+ kind
265905
+ name
265906
+ ofType {
265907
+ kind
265908
+ name
265909
+ ofType {
265910
+ kind
265911
+ name
265912
+ ofType {
265913
+ kind
265914
+ name
265915
+ ofType {
265916
+ kind
265917
+ name
265918
+ ofType {
265919
+ kind
265920
+ name
265921
+ }
265922
+ }
265923
+ }
265924
+ }
265925
+ }
265926
+ }
265927
+ }
265928
+ }
265929
+ }
265930
+ }
265931
+ `
265932
+ })
265933
+ });
265934
+ await writeFile6(introspectionJsonPath, JSON.stringify(data));
265935
+ } catch (err) {
265936
+ const error5 = err;
265937
+ note(`GraphQL endpoint '${endpoint}' is not reachable: ${error5.message}`, "warn");
265938
+ return;
265939
+ }
265940
+ try {
265941
+ await generateSchema({
265942
+ input: basename(introspectionJsonPath),
265943
+ output: "blockscout-schema.graphql",
265944
+ tsconfig: undefined,
265945
+ headers: undefined
265946
+ });
265947
+ } finally {
265948
+ await rm2(introspectionJsonPath);
265949
+ }
265950
+ const template = `import { createBlockscoutClient } from "${PACKAGE_NAME4}";
265951
+ import type { introspection } from "@schemas/blockscout-env";
265952
+
265953
+ export const { client: blockscoutClient, graphql: blockscoutGraphql } = createBlockscoutClient<{
265954
+ introspection: introspection;
265955
+ disableMasking: true;
265956
+ scalars: {
265957
+ /** 40 hex characters (160 bits/20 bytes) derived from the public key, prefixed with 0x */
265958
+ AddressHash: string;
265959
+ /** Unpadded big-endian hexadecimal number where each byte pair maps to underlying binary */
265960
+ Data: string;
265961
+ /** ISO8601 formatted UTC datetime string */
265962
+ DateTime: string;
265963
+ /** String representation of a signed double-precision decimal value */
265964
+ Decimal: string;
265965
+ /** 32-byte KECCAK-256 hash */
265966
+ FullHash: string;
265967
+ /** Arbitrary JSON string data as UTF-8 */
265968
+ Json: string;
265969
+ /** 16 hex character (128 bits/8 bytes) nonce from Proof-of-Work */
265970
+ NonceHash: string;
265971
+ /** Smallest fractional unit of Ether, represented as a string for integer math */
265972
+ Wei: string;
265973
+ };
265974
+ }>({
265975
+ instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT!,
265976
+ accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!, // undefined in browser, by design to not leak the secrets
265977
+ });
265978
+
265979
+ export const blockscoutUiEndpoint = process.env.SETTLEMINT_BLOCKSCOUT_UI_ENDPOINT!;`;
265980
+ await writeTemplate(template, "/lib/settlemint", "blockscout.ts");
265981
+ const projectDir = await projectRoot3();
265982
+ if (!await isPackageInstalled(PACKAGE_NAME4, projectDir)) {
265983
+ await installDependencies(PACKAGE_NAME4, projectDir);
266026
265984
  }
266027
- checkCursorPos() {
266028
- const cursorPos = this.rl.getCursorPos();
266029
- if (cursorPos.cols !== this.cursorPos.cols) {
266030
- this.write(import_ansi_escapes3.default.cursorTo(cursorPos.cols));
266031
- this.cursorPos = cursorPos;
266032
- }
265985
+ }
265986
+
265987
+ // src/commands/codegen/codegen-ipfs.ts
265988
+ var PACKAGE_NAME5 = "@settlemint/sdk-ipfs";
265989
+ function shouldCodegenIpfs(env2) {
265990
+ return !!env2.SETTLEMINT_IPFS_API_ENDPOINT;
265991
+ }
265992
+ async function codegenIpfs(env2) {
265993
+ const endpoint = env2.SETTLEMINT_IPFS_API_ENDPOINT;
265994
+ if (!endpoint) {
265995
+ return;
266033
265996
  }
266034
- done({ clearContent }) {
266035
- this.rl.setPrompt("");
266036
- let output = cursorDown2(this.extraLinesUnderPrompt);
266037
- output += clearContent ? import_ansi_escapes3.default.eraseLines(this.height) : `
266038
- `;
266039
- output += import_ansi_escapes3.default.cursorShow;
266040
- this.write(output);
266041
- this.rl.close();
265997
+ const clientTemplate = `import { createServerIpfsClient } from "${PACKAGE_NAME5}";
265998
+
265999
+ export const { client } = createServerIpfsClient({
266000
+ instance: process.env.SETTLEMINT_IPFS_API_ENDPOINT!,
266001
+ accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
266002
+ });`;
266003
+ await writeTemplate(clientTemplate, "/lib/settlemint", "ipfs.ts");
266004
+ const projectDir = await projectRoot3();
266005
+ if (!await isPackageInstalled(PACKAGE_NAME5, projectDir)) {
266006
+ await installDependencies(PACKAGE_NAME5, projectDir);
266042
266007
  }
266043
266008
  }
266044
266009
 
266045
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/promise-polyfill.js
266046
- class PromisePolyfill2 extends Promise {
266047
- static withResolver() {
266048
- let resolve6;
266049
- let reject;
266050
- const promise = new Promise((res, rej) => {
266051
- resolve6 = res;
266052
- reject = rej;
266053
- });
266054
- return { promise, resolve: resolve6, reject };
266055
- }
266010
+ // src/commands/codegen/codegen-minio.ts
266011
+ var PACKAGE_NAME6 = "@settlemint/sdk-minio";
266012
+ function shouldCodegenMinio(env2) {
266013
+ return !!(env2.SETTLEMINT_MINIO_ENDPOINT && env2.SETTLEMINT_MINIO_ACCESS_KEY && env2.SETTLEMINT_MINIO_SECRET_KEY);
266056
266014
  }
266015
+ async function codegenMinio(env2) {
266016
+ const endpoint = env2.SETTLEMINT_MINIO_ENDPOINT;
266017
+ if (!endpoint) {
266018
+ return;
266019
+ }
266020
+ const clientTemplate = `import { createServerMinioClient } from "${PACKAGE_NAME6}";
266057
266021
 
266058
- // ../../node_modules/@inquirer/password/node_modules/@inquirer/core/dist/esm/lib/create-prompt.js
266059
- function getCallSites2() {
266060
- const _prepareStackTrace = Error.prepareStackTrace;
266061
- let result = [];
266062
- try {
266063
- Error.prepareStackTrace = (_5, callSites) => {
266064
- const callSitesWithoutCurrent = callSites.slice(1);
266065
- result = callSitesWithoutCurrent;
266066
- return callSitesWithoutCurrent;
266067
- };
266068
- new Error().stack;
266069
- } catch {
266070
- return result;
266022
+ export const { client } = createServerMinioClient({
266023
+ instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
266024
+ accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
266025
+ accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
266026
+ secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
266027
+ });`;
266028
+ await writeTemplate(clientTemplate, "/lib/settlemint", "minio.ts");
266029
+ const projectDir = await projectRoot3();
266030
+ if (!await isPackageInstalled(PACKAGE_NAME6, projectDir)) {
266031
+ await installDependencies(PACKAGE_NAME6, projectDir);
266071
266032
  }
266072
- Error.prepareStackTrace = _prepareStackTrace;
266073
- return result;
266074
266033
  }
266075
- function createPrompt2(view) {
266076
- const callSites = getCallSites2();
266077
- const prompt = (config3, context = {}) => {
266078
- const { input = process.stdin, signal } = context;
266079
- const cleanups = new Set;
266080
- const output = new import_mute_stream2.default;
266081
- output.pipe(context.output ?? process.stdout);
266082
- const rl = readline4.createInterface({
266083
- terminal: true,
266084
- input,
266085
- output
266086
- });
266087
- const screen = new ScreenManager2(rl);
266088
- const { promise, resolve: resolve6, reject } = PromisePolyfill2.withResolver();
266089
- const cancel3 = () => reject(new CancelPromptError2);
266090
- if (signal) {
266091
- const abort = () => reject(new AbortPromptError2({ cause: signal.reason }));
266092
- if (signal.aborted) {
266093
- abort();
266094
- return Object.assign(promise, { cancel: cancel3 });
266095
- }
266096
- signal.addEventListener("abort", abort);
266097
- cleanups.add(() => signal.removeEventListener("abort", abort));
266034
+
266035
+ // src/commands/codegen.ts
266036
+ function codegenCommand() {
266037
+ return new Command("codegen").option("--prod", "Connect to your production environment").option("--thegraph-subgraph-names <subgraph-names...>", "The name(s) of the TheGraph subgraph(s) to generate (skip if you want to generate all)").description("Generate GraphQL and REST types and queries").usage(createExamples([
266038
+ {
266039
+ description: "Generate GraphQL types and queries for your dApp",
266040
+ command: "codegen"
266041
+ },
266042
+ {
266043
+ description: "Generate GraphQL types and queries for specific TheGraph subgraphs",
266044
+ command: "codegen --thegraph-subgraph-names subgraph1 subgraph2"
266098
266045
  }
266099
- cleanups.add(onExit((code2, signal2) => {
266100
- reject(new ExitPromptError2(`User force closed the prompt with ${code2} ${signal2}`));
266101
- }));
266102
- const checkCursorPos = () => screen.checkCursorPos();
266103
- rl.input.on("keypress", checkCursorPos);
266104
- cleanups.add(() => rl.input.removeListener("keypress", checkCursorPos));
266105
- return withHooks2(rl, (cycle) => {
266106
- const hooksCleanup = AsyncResource6.bind(() => effectScheduler2.clearAll());
266107
- rl.on("close", hooksCleanup);
266108
- cleanups.add(() => rl.removeListener("close", hooksCleanup));
266109
- cycle(() => {
266110
- try {
266111
- const nextView = view(config3, (value4) => {
266112
- setImmediate(() => resolve6(value4));
266113
- });
266114
- if (nextView === undefined) {
266115
- const callerFilename = callSites[1]?.getFileName?.();
266116
- throw new Error(`Prompt functions must return a string.
266117
- at ${callerFilename}`);
266118
- }
266119
- const [content, bottomContent] = typeof nextView === "string" ? [nextView] : nextView;
266120
- screen.render(content, bottomContent);
266121
- effectScheduler2.run();
266122
- } catch (error5) {
266123
- reject(error5);
266124
- }
266046
+ ])).action(async ({ prod, thegraphSubgraphNames }) => {
266047
+ intro("Generating GraphQL types and queries for your dApp");
266048
+ const env2 = await loadEnv(true, !!prod);
266049
+ if (!Array.isArray(thegraphSubgraphNames)) {
266050
+ thegraphSubgraphNames = await subgraphPrompt({
266051
+ env: env2,
266052
+ accept: true,
266053
+ message: "Which The Graph subgraph do you want to generate types for?",
266054
+ allowAll: true
266125
266055
  });
266126
- return Object.assign(promise.then((answer) => {
266127
- effectScheduler2.clearAll();
266128
- return answer;
266129
- }, (error5) => {
266130
- effectScheduler2.clearAll();
266131
- throw error5;
266132
- }).finally(() => {
266133
- cleanups.forEach((cleanup) => cleanup());
266134
- screen.done({ clearContent: Boolean(context.clearPromptOnDone) });
266135
- output.end();
266136
- }).then(() => promise), { cancel: cancel3 });
266056
+ }
266057
+ const { hasura, portal, thegraph, blockscout } = await spinner({
266058
+ startMessage: "Testing configured GraphQL schema",
266059
+ task: async () => {
266060
+ return codegenTsconfig(env2, thegraphSubgraphNames);
266061
+ },
266062
+ stopMessage: "Tested GraphQL schemas"
266137
266063
  });
266138
- };
266139
- return prompt;
266064
+ if (hasura) {
266065
+ note("Generating Hasura resources");
266066
+ await codegenHasura(env2);
266067
+ }
266068
+ if (portal) {
266069
+ note("Generating Portal resources");
266070
+ await codegenPortal(env2);
266071
+ }
266072
+ if (thegraph) {
266073
+ note("Generating TheGraph resources");
266074
+ await codegenTheGraph(env2, thegraphSubgraphNames);
266075
+ }
266076
+ if (blockscout) {
266077
+ note("Generating Blockscout resources");
266078
+ await codegenBlockscout(env2);
266079
+ }
266080
+ if (shouldCodegenMinio(env2)) {
266081
+ note("Generating Minio resources");
266082
+ await codegenMinio(env2);
266083
+ }
266084
+ if (shouldCodegenIpfs(env2)) {
266085
+ note("Generating IPFS resources");
266086
+ await codegenIpfs(env2);
266087
+ }
266088
+ if (hasura || portal || thegraph || blockscout) {
266089
+ await generateOutput({
266090
+ output: undefined,
266091
+ tsconfig: undefined
266092
+ });
266093
+ }
266094
+ outro("Codegen complete");
266095
+ });
266096
+ }
266097
+
266098
+ // ../../node_modules/@inquirer/confirm/dist/esm/index.js
266099
+ function getBooleanValue(value4, defaultValue) {
266100
+ let answer = defaultValue !== false;
266101
+ if (/^(y|yes)/i.test(value4))
266102
+ answer = true;
266103
+ else if (/^(n|no)/i.test(value4))
266104
+ answer = false;
266105
+ return answer;
266106
+ }
266107
+ function boolToString(value4) {
266108
+ return value4 ? "Yes" : "No";
266140
266109
  }
266110
+ var esm_default4 = createPrompt((config3, done) => {
266111
+ const { transformer = boolToString } = config3;
266112
+ const [status, setStatus] = useState("idle");
266113
+ const [value4, setValue] = useState("");
266114
+ const theme = makeTheme(config3.theme);
266115
+ const prefix = usePrefix({ status, theme });
266116
+ useKeypress((key3, rl) => {
266117
+ if (isEnterKey(key3)) {
266118
+ const answer = getBooleanValue(value4, config3.default);
266119
+ setValue(transformer(answer));
266120
+ setStatus("done");
266121
+ done(answer);
266122
+ } else if (key3.name === "tab") {
266123
+ const answer = boolToString(!getBooleanValue(value4, config3.default));
266124
+ rl.clearLine(0);
266125
+ rl.write(answer);
266126
+ setValue(answer);
266127
+ } else {
266128
+ setValue(rl.line);
266129
+ }
266130
+ });
266131
+ let formattedValue = value4;
266132
+ let defaultValue = "";
266133
+ if (status === "done") {
266134
+ formattedValue = theme.style.answer(value4);
266135
+ } else {
266136
+ defaultValue = ` ${theme.style.defaultAnswer(config3.default === false ? "y/N" : "Y/n")}`;
266137
+ }
266138
+ const message = theme.style.message(config3.message, status);
266139
+ return `${prefix} ${message}${defaultValue} ${formattedValue}`;
266140
+ });
266141
+
266141
266142
  // ../../node_modules/@inquirer/password/dist/esm/index.js
266142
266143
  var import_ansi_escapes4 = __toESM(require_ansi_escapes(), 1);
266143
- var esm_default5 = createPrompt2((config3, done) => {
266144
+ var esm_default5 = createPrompt((config3, done) => {
266144
266145
  const { validate: validate3 = () => true } = config3;
266145
- const theme = makeTheme2(config3.theme);
266146
- const [status, setStatus] = useState2("idle");
266147
- const [errorMsg, setError] = useState2();
266148
- const [value4, setValue] = useState2("");
266149
- const prefix = usePrefix2({ status, theme });
266150
- useKeypress2(async (key3, rl) => {
266146
+ const theme = makeTheme(config3.theme);
266147
+ const [status, setStatus] = useState("idle");
266148
+ const [errorMsg, setError] = useState();
266149
+ const [value4, setValue] = useState("");
266150
+ const prefix = usePrefix({ status, theme });
266151
+ useKeypress(async (key3, rl) => {
266151
266152
  if (status !== "idle") {
266152
266153
  return;
266153
266154
  }
266154
- if (isEnterKey2(key3)) {
266155
+ if (isEnterKey(key3)) {
266155
266156
  const answer = value4;
266156
266157
  setStatus("loading");
266157
266158
  const isValid2 = await validate3(answer);
@@ -273875,4 +273876,4 @@ async function sdkCliCommand(argv = process.argv) {
273875
273876
  // src/cli.ts
273876
273877
  sdkCliCommand();
273877
273878
 
273878
- //# debugId=841133EB0FF0E44E64756E2164756E21
273879
+ //# debugId=C1EDC86A987761F564756E2164756E21