MCPcopy Create free account
hub / github.com/chhoumann/quickadd / onExportIsObject

Method onExportIsObject

src/engine/MacroChoiceEngine.ts:473–528  ·  view source on GitHub ↗
(obj: Record<string, unknown>)

Source from the content-addressed store, hash-verified

471 }
472
473 protected async onExportIsObject(obj: Record<string, unknown>) {
474 if (Object.keys(obj).length === 0) {
475 throw new Error(
476 `user script in macro for '${this.choice.name}' is an empty object`
477 );
478 }
479
480 if (this.userScriptCommand && typeof obj.entry === "function") {
481 await this.runScriptWithSettings(
482 obj as {
483 entry: (
484 params: typeof this.params,
485 settings: Record<string, unknown>
486 ) => Promise<void>;
487 },
488 this.userScriptCommand
489 );
490 return;
491 }
492
493 // Non-interactive run (CLI without `ui`): a user script that exports an object
494 // of MULTIPLE named members opens a picker to choose which to run, which has
495 // no one to answer it headlessly. A single-member export is unambiguous, so
496 // run it directly (the interactive path keeps its existing picker behaviour).
497 if (this.choiceExecutor.interactive === false) {
498 const keys = Object.keys(obj);
499 if (keys.length === 1) {
500 await this.userScriptDelegator(obj[keys[0]]);
501 return;
502 }
503 throw new ChoiceAbortError(
504 "This macro's user script exports multiple members and needs to ask which one to run, but this run is non-interactive. " +
505 "Reference a single member (e.g. myScript::start), or re-run with the ui flag.",
506 );
507 }
508
509 try {
510 const keys = Object.keys(obj);
511 const selected: string = await GenericSuggester.Suggest(
512 this.app,
513 keys,
514 keys,
515 this.promptLabel,
516 );
517
518 await this.userScriptDelegator(obj[selected]);
519 } catch (err) {
520 if (err instanceof MacroAbortError) {
521 throw err;
522 }
523 if (isCancellationError(err)) {
524 throw new UserCancelError("Input cancelled by user");
525 }
526 throw err;
527 }
528 }
529
530 protected executeObsidianCommand(command: IObsidianCommand) {

Callers 1

userScriptDelegatorMethod · 0.95

Calls 4

runScriptWithSettingsMethod · 0.95
userScriptDelegatorMethod · 0.95
isCancellationErrorFunction · 0.90
SuggestMethod · 0.45

Tested by

no test coverage detected