codama
Version:
A Solana framework for building standardised programs
53 lines (52 loc) • 1.6 kB
JavaScript
// src/index.ts
export * from "@codama/errors";
export * from "@codama/nodes";
export * from "@codama/validators";
export * from "@codama/visitors";
// src/codama.ts
import { CODAMA_ERROR__VERSION_MISMATCH } from "@codama/errors";
import { CodamaError } from "@codama/errors";
import { assertIsNode } from "@codama/nodes";
import { visit } from "@codama/visitors";
function createFromRoot(root) {
let currentRoot = root;
validateCodamaVersion(currentRoot.version);
return {
accept(visitor) {
return visit(currentRoot, visitor);
},
clone() {
return createFromRoot({ ...currentRoot });
},
getJson() {
return JSON.stringify(currentRoot);
},
getRoot() {
return currentRoot;
},
update(visitor) {
const newRoot = visit(currentRoot, visitor);
assertIsNode(newRoot, "rootNode");
currentRoot = newRoot;
}
};
}
function createFromJson(json) {
return createFromRoot(JSON.parse(json));
}
function validateCodamaVersion(rootVersion) {
const codamaVersion = "1.3.1";
if (rootVersion === codamaVersion) return;
const [rootMajor, rootMinor] = rootVersion.split(".").map(Number);
const [CodamaMajor, CodamaMinor] = codamaVersion.split(".").map(Number);
const isZeroMajor = rootMajor === 0 && CodamaMajor === 0;
if (isZeroMajor && rootMinor === CodamaMinor) return;
if (rootMajor === CodamaMajor) return;
throw new CodamaError(CODAMA_ERROR__VERSION_MISMATCH, { codamaVersion, rootVersion });
}
export {
createFromJson,
createFromRoot,
validateCodamaVersion
};
//# sourceMappingURL=index.react-native.mjs.map