Registry / web-framework / carmi
library1.0.342jsnpmunverified

CARMI (Compiler for Automatic Reactive Modelling of Inference) is an experimental DSL+compiler for reactive state derivation. Current version 1.0.342. It generates JavaScript source code that automatically handles cache invalidation by analyzing which model paths are read/written at compile time, avoiding overhead of traditional FRP or immutable approaches. Key differentiators: zero-overhead conditional dependency tracking, hoisted shared sub-expressions, no tracking when no setters exist, fully incremental computation. Stable but low release cadence (last major update years ago). Ships TypeScript types.

npm install carmi
INSTALL
IMPORT
SIG · CARMI
C
carmi
web-frameworkjavascriptv1.0.342
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
import { compile } from 'carmi'
const compile = require('carmi')
Package supports both ESM and CJS; this is the named import.
root
import { root } from 'carmi'
const root = require('carmi').root
Named import, not default.
setter
import { setter } from 'carmi'
const setter = require('carmi/setter')
setter is exported from main package, not a subpath.
splice
import { splice } from 'carmi'
const { splice } = require('carmi')
Correct both ways; no wrong pattern for named import.

Defines a reactive model for a todo list: derived display text, any-not-done flag, and a setter action using compile/eval.

import { compile, root, arg0, setter, splice } from 'carmi'; const todosByIdx = root.keyBy('idx'); const anyTodoNotDone = todosByIdx.anyValues(todo => todo.get('done').not()); const todosDisplayByIdx = todosByIdx.mapValues(todo => todo.get('task').plus(todo.get('done').ternary(' - done', ' - not done')) ); const todosDisplay = root.map(todo => todosDisplayByIdx.get(todo.get('idx'))); const modelDefinition = { todosDisplay, anyTodoNotDone, setTodoDone: setter(arg0, 'done'), spliceTodos: splice(), }; const todosModel = eval(compile(modelDefinition)); const initialData = [ { idx: '1', done: false, task: 'write a blog post about carmi' }, { idx: '2', done: true, task: 'publish to npm' }, { idx: '3', done: false, task: 'write a demo for carmi' }, ]; const todos = todosModel(initialData); console.log(todos.todosDisplay); // outputs array with tasks marked done/not done sorted by idx descending
carmi --version
Debug
Known issues
gotchacompile() returns a string; you must eval() it to get the model function.
fix
Use eval(compile(modelDefinition)) as shown in docs.
affects: *
gotchaThe DSL uses method chaining on root; forgetting .get() on properties returns a Path object, not a value.
fix
Always use .get('key') to access model properties if you need the value.
affects: *
deprecatedThe Babel macro approach (require('carmi/macro')) is no longer recommended; use compile() directly.
fix
Replace import { compile } from 'carmi/macro' with import { compile } from 'carmi'.
affects: >=1.0.0
gotchaSetters generated by setter() expect arguments in model index order; mismatch causes silent failures.
fix
Ensure that the number and order of args match the paths used in setter(arg0, ...).
affects: *
Errors
Common errors & fixes
TypeError: model is not a function
compile() returns a string, not a function. You forgot to eval() it.
fix
Change const model = compile(definition); to const model = eval(compile(definition));
Cannot read property 'get' of undefined
Attempting to chain .get() on a model accessor that returned undefined in eval context.
fix
Ensure your model definition uses root and paths correctly; verify that the compiled code runs inside eval.
ReferenceError: root is not defined
Forgetting to import or destructure root from carmi in the compile scope.
fix
Add import { root } from 'carmi' at top of the file where compile() is called.
Error: setter requires at least one path argument
setter() called without any arguments or with non-function arguments.
fix
Use setter(arg0, 'pathToSet') or setter(arg0, arg1) depending on your model depth.
Upgrade
Version history
1.0.342latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
carmi — npm install carmi · libregistry