'use strict'; // src/codes.ts var KINOBI_ERROR__UNRECOGNIZED_NODE_KIND = 1; var KINOBI_ERROR__UNEXPECTED_NODE_KIND = 2; var KINOBI_ERROR__UNEXPECTED_NESTED_NODE_KIND = 3; var KINOBI_ERROR__LINKED_NODE_NOT_FOUND = 4; var KINOBI_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE = 5; var KINOBI_ERROR__VERSION_MISMATCH = 6; var KINOBI_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES = 12e5; var KINOBI_ERROR__VISITORS__INVALID_PDA_SEED_VALUES = 1200001; var KINOBI_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES = 1200002; var KINOBI_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE = 1200003; var KINOBI_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY = 1200004; var KINOBI_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND = 1200005; var KINOBI_ERROR__VISITORS__INVALID_NUMBER_WRAPPER = 1200006; var KINOBI_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION = 1200007; var KINOBI_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE = 1200008; var KINOBI_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND = 1200009; var KINOBI_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES = 1200010; var KINOBI_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND = 1200011; var KINOBI_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE = 21e5; var KINOBI_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING = 2100001; var KINOBI_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING = 2100002; var KINOBI_ERROR__ANCHOR__TYPE_PATH_MISSING = 2100003; var KINOBI_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED = 2100004; var KINOBI_ERROR__RENDERERS__UNSUPPORTED_NODE = 28e5; // src/context.ts function encodeValue(value) { if (Array.isArray(value)) { const commaSeparatedValues = value.map(encodeValue).join( "%2C%20" /* ", " */ ); return "%5B" + commaSeparatedValues + /* "]" */ "%5D"; } else if (typeof value === "bigint") { return `${value}n`; } else { return encodeURIComponent( String( value != null && Object.getPrototypeOf(value) === null ? ( // Plain objects with no protoype don't have a `toString` method. // Convert them before stringifying them. { ...value } ) : value ) ); } } function encodeObjectContextEntry([key, value]) { return `${key}=${encodeValue(value)}`; } function encodeContextObject(context) { const searchParamsString = Object.entries(context).map(encodeObjectContextEntry).join("&"); return Buffer.from(searchParamsString, "utf8").toString("base64") ; } // src/messages.ts var KinobiErrorMessages = { [KINOBI_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING]: "Account type [$name] is missing from the IDL types.", [KINOBI_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING]: "Argument name [$name] is missing from the instruction definition.", [KINOBI_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED]: "Seed kind [$kind] is not implemented.", [KINOBI_ERROR__ANCHOR__TYPE_PATH_MISSING]: "Field type is missing for path [$path] in [$idlType].", [KINOBI_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE]: "Unrecognized Anchor IDL type [$idlType].", [KINOBI_ERROR__LINKED_NODE_NOT_FOUND]: "Could not find linked node [$name] from [$kind].", [KINOBI_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]: "Node.js filesystem function [$fsFunction] is not available in your environment.", [KINOBI_ERROR__RENDERERS__UNSUPPORTED_NODE]: "Cannot render the encountered node of kind [$kind].", [KINOBI_ERROR__UNEXPECTED_NESTED_NODE_KIND]: "Expected nested node of kind [$expectedKinds], got [$kind]", [KINOBI_ERROR__UNEXPECTED_NODE_KIND]: "Expected node of kind [$expectedKinds], got [$kind].", [KINOBI_ERROR__UNRECOGNIZED_NODE_KIND]: "Unrecognized node kind [$kind].", [KINOBI_ERROR__VERSION_MISMATCH]: "The provided RootNode version [$rootVersion] is not compatible with the installed Kinobi version [$kinobiVersion].", [KINOBI_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND]: "Account [$name] does not have a field named [$missingField].", [KINOBI_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES]: "Cannot add PDAs to program [$programName] because the following PDA names already exist [$duplicatedPdaNames].", [KINOBI_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION]: "Cannot extend visitor with function [$visitFunction] as the base visitor does not support it.", [KINOBI_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES]: "Cannot flatten struct since this would cause the following attributes to conflict [$conflictingAttributes].", [KINOBI_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE]: "Cannot use optional account [$seedValueName] as the [$seedName] PDA seed for the [$instructionAccountName] account of the [$instructionName] instruction.", [KINOBI_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES]: "Circular dependency detected when resolving the accounts and arguments' default values of the [$instructionName] instruction. Got the following dependency cycle [$formattedCycle].", [KINOBI_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE]: "Failed to validate the given node [$formattedHistogram].", [KINOBI_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND]: "Could not find an enum argument named [$argumentName] for instruction [$instructionName].", [KINOBI_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY]: "Dependency [$dependencyName] of kind [$dependencyKind] is not a valid dependency of [$parentName] of kind [$parentKind] in the [$instructionName] instruction.", [KINOBI_ERROR__VISITORS__INVALID_NUMBER_WRAPPER]: "Invalid number wrapper kind [$wrapper].", [KINOBI_ERROR__VISITORS__INVALID_PDA_SEED_VALUES]: "Invalid seed values for PDA [$pdaName] in instruction [$instructionName].", [KINOBI_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND]: "Cannot find key [$key] in RenderMap." }; // src/message-formatter.ts function getHumanReadableErrorMessage(code, context = {}) { const messageFormatString = KinobiErrorMessages[code]; const message = messageFormatString.replace( /(? variableName in context ? `${context[variableName]}` : substring ); return message; } function getErrorMessage(code, context = {}) { if (process.env.NODE_ENV !== "production") { return getHumanReadableErrorMessage(code, context); } else { let decodingAdviceMessage = `Kinobi error #${code}; Decode this error by running \`npx @kinobi-so/errors decode -- ${code}`; if (Object.keys(context).length) { decodingAdviceMessage += ` '${encodeContextObject(context)}'`; } return `${decodingAdviceMessage}\``; } } // src/error.ts function isKinobiError(e, code) { const isKinobiError2 = e instanceof Error && e.name === "KinobiError"; if (isKinobiError2) { if (code !== void 0) { return e.context.__code === code; } return true; } return false; } var KinobiError = class extends Error { context; constructor(...[code, contextAndErrorOptions]) { let context; let errorOptions; if (contextAndErrorOptions) { const { cause, ...contextRest } = contextAndErrorOptions; if (cause) { errorOptions = { cause }; } if (Object.keys(contextRest).length > 0) { context = contextRest; } } const message = getErrorMessage(code, context); super(message, errorOptions); this.context = { __code: code, ...context }; this.name = "KinobiError"; } }; // src/logs.ts function logError(message) { console.error(message); } function logWarn(message) { console.warn(message); } function logInfo(message) { console.log(message); } // src/stack-trace.ts function safeCaptureStackTrace(...args) { if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") { Error.captureStackTrace(...args); } } exports.KINOBI_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING = KINOBI_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING; exports.KINOBI_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING = KINOBI_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING; exports.KINOBI_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED = KINOBI_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED; exports.KINOBI_ERROR__ANCHOR__TYPE_PATH_MISSING = KINOBI_ERROR__ANCHOR__TYPE_PATH_MISSING; exports.KINOBI_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE = KINOBI_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE; exports.KINOBI_ERROR__LINKED_NODE_NOT_FOUND = KINOBI_ERROR__LINKED_NODE_NOT_FOUND; exports.KINOBI_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE = KINOBI_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE; exports.KINOBI_ERROR__RENDERERS__UNSUPPORTED_NODE = KINOBI_ERROR__RENDERERS__UNSUPPORTED_NODE; exports.KINOBI_ERROR__UNEXPECTED_NESTED_NODE_KIND = KINOBI_ERROR__UNEXPECTED_NESTED_NODE_KIND; exports.KINOBI_ERROR__UNEXPECTED_NODE_KIND = KINOBI_ERROR__UNEXPECTED_NODE_KIND; exports.KINOBI_ERROR__UNRECOGNIZED_NODE_KIND = KINOBI_ERROR__UNRECOGNIZED_NODE_KIND; exports.KINOBI_ERROR__VERSION_MISMATCH = KINOBI_ERROR__VERSION_MISMATCH; exports.KINOBI_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND = KINOBI_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND; exports.KINOBI_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES = KINOBI_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES; exports.KINOBI_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION = KINOBI_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION; exports.KINOBI_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES = KINOBI_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES; exports.KINOBI_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE = KINOBI_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE; exports.KINOBI_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES = KINOBI_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES; exports.KINOBI_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE = KINOBI_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE; exports.KINOBI_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND = KINOBI_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND; exports.KINOBI_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY = KINOBI_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY; exports.KINOBI_ERROR__VISITORS__INVALID_NUMBER_WRAPPER = KINOBI_ERROR__VISITORS__INVALID_NUMBER_WRAPPER; exports.KINOBI_ERROR__VISITORS__INVALID_PDA_SEED_VALUES = KINOBI_ERROR__VISITORS__INVALID_PDA_SEED_VALUES; exports.KINOBI_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND = KINOBI_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND; exports.KinobiError = KinobiError; exports.isKinobiError = isKinobiError; exports.logError = logError; exports.logInfo = logInfo; exports.logWarn = logWarn; exports.safeCaptureStackTrace = safeCaptureStackTrace; //# sourceMappingURL=index.node.cjs.map //# sourceMappingURL=index.node.cjs.map