Docs
Storage & versions
DocEngine separates template design (layout + schemas + mapping) from filled documents (values). Hosts choose how to persist JSON; Salesforce adds immutable template versions so completed docs keep the layout they were filled against.
Principles
- Template JSON —
exportTemplate():kind: "template", blocks,fieldSchemas, optionalfieldMapping, page setup. Values reset to defaults. This is also your config — do not keep a parallel schema object beside it. - Values JSON —
exportFields():kind: "field", usuallyversion: 2with nestedsections(section name → field name). Small enough to store and re-merge onto a pinned template. Do not key by internal field ids or embed full blocks. - Full document —
exportDoc():kind: "document"when you need a self-contained snapshot (blocks + values). Prefer template + values for long-lived storage. - Pin layout on fill — when a user starts or completes a document, bind it to a specific template version so later design edits don’t rewrite history.
Common poor shapes (filled templates, id-keyed values, off-template Mapping) are called out on the Builder & integrator guide.
Salesforce model (versioned)
Production pattern in the managed package:
DocEngine_Template__c— mutable head: name, object API, denormalized currentTemplate_JSON__c,Version__c, lookupCurrent_Version__c.DocEngine_Template_Version__c— immutable snapshots:Version__c+ frozenTemplate_JSON__c. Each Save in the builder inserts a new version and updates Current; old rows are never overwritten.DocEngine_Document__c— filled instance: lookup Template + pinnedTemplate_Version__c,Record_Id__c,Document_JSON__c(values-only preferred), status Draft/Completed.- PDF/HTML files —
ContentVersionlinked to the document and source record (not stored inside the Long Text Area).
First save of a document pins the current version (lazy snapshot if needed). Later saves keep that pin so reopen/PDF use the same layout and Mapping.
Self-hosted website
MVP storage is a local JSON database (data/db.json):
- Templates — one row per template;
dataholds the latest template export (including Mapping). No separate version table yet. - Documents — optional drafts with
templateId+data.
For production parity with Salesforce, add immutable template versions (or content-addressed snapshots) and pin them on documents and API render jobs so Mapping/layout can’t drift under a live token.
IO format versions
- Template / document exports carry
version(IO format; fields export v2 = nestedsections). fieldMappinguseskind: "fieldMapping",version: 1.- Hosts should treat unknown future IO versions carefully; prefer values-only + pinned template over mutating historical full documents.
Related: Mapping · API & hosts · Field types