Build a pack
Use definePack() to group reusable declarations. Its extract function receives the model and an API object containing the engine's public declaration factories.
import { cashflow, currencies, defineModel, definePack, entity, extractPacks, inflow, periods, schedule } from "deccf";
const building = entity.asset();
const rent = cashflow({ owner: building, direction: inflow, schedule: schedule.monthly(), amount: 2_000 });
const model = defineModel({
name: "service-fee-example",
currency: currencies.SEK,
timeline: periods.monthly({ from: "2026-01", count: 12 }),
entities: { building },
flows: { rent },
});
const servicePack = definePack({
name: "service-fee",
version: "1.0.0",
extract: ({ api }) => ({
flows: {
serviceFee: api.cashflow({
direction: api.outflow,
category: api.category("service.expense"),
schedule: api.schedule.monthly(),
amount: 100,
}),
},
}),
});
const extractedModel = extractPacks(model, [servicePack]);
const result = run(extractedModel);
return extractedModel;The returned contribution can contain declaration maps such as accounts, flows, preconditions, and metrics. A pack cannot change the model's name, currency, or timeline. Existing names cannot be replaced.
Extraction maps a higher-level domain abstraction into declarations on the underlying model. The extraction function must be synchronous and deterministic. The engine invokes it twice and compares the contributions. A lightweight source scan rejects common global clock, random, and I/O APIs. See the Pack reference.