codama
Version:
A Solana framework for building standardised programs
49 lines (47 loc) • 1.6 kB
JavaScript
import { CodamaError, CODAMA_ERROR__VERSION_MISMATCH } from '@codama/errors';
export * from '@codama/errors';
import { assertIsNode } from '@codama/nodes';
export * from '@codama/nodes';
export * from '@codama/validators';
import { visit } from '@codama/visitors';
export * from '@codama/visitors';
// src/index.ts
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.5.0";
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
//# sourceMappingURL=index.react-native.mjs.map