State diagram
Read this page in the documentation
State diagram The states an instance moves through, including the soft-deleted one a paranoid model adds. The code What it produces Generated by running the snippet above — this is the generator's real output, rebuilt by scripts/build-diagram-examples.mjs, not a picture of it. <div class="diagram-example"> <!-- Generated by ts-prorm-orm StateDiagram --> <svg xmlns="http://www.w3.org/2000/svg" width="950" height="364" viewBox="0 0 950 364"><defs><marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M 0 0 L 10 5 L 0 10 z" fill="#000000"/></marker></defs><rect width="950" height="364" fill="#ffffff"/><text x="40" y="48" font-family="ui-sans-serif, -apple-system, Segoe UI, Helvetica, Arial, sans-serif" font-size="22" font-weight="bold" fill="#000000">Instance lifecycle</text><line x1="129" y1="154" x2="280" y2="154" stroke="#000000" stroke-width="2" marker-end="url(#arrow)"/><rect x="163.5" y="135" width="82" height="18" fill="#ffffff" stroke="#000000" stroke-width="1"/><text x="204.5" y="147" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="11" font-weight="bold" fill="#000000" text-anchor="middle">validate()</text><line x1="430" y1="154" x2="520" y2="154" stroke="#000000" stroke-width="2" marker-end="url(#arrow)"/><rect x="448" y="135" width="54" height="18" fill="#ffffff" stroke="#000000" stroke-width="1"/><text x="475" y="147" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="11" font-weight="bold" fill="#000000" text-anchor="middle">save()</text><path d="M565,124 C545,90 645,90 625,124" fill="none" stroke="#000000" stroke-width="2" marker-end="url(#arrow)"/><rect x="561" y="73" width="68" height="18" fill="#ffffff" stroke="#000000" stroke-width="1"/><text x="595" y="85" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="11" font-weight="bold" fill="#000000" text-anchor="middle">update()</text><line x1="670" y1="154" x2="760" y2="154" stroke="#000000" stroke-width="2" marker-end="url(#arrow)"/><rect x="677.5" y="135" width="75" height="18" fill="#ffffff" stroke="#000000" stroke-width="1"/><text x="715" y="147" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="11" font-weight="bold" fill="#000000" text-anchor="middle">destroy()</text><line x1="760" y1="154" x2="670" y2="154" stroke="#000000" stroke-width="2" marker-end="url(#arrow)"/><rect x="677.5" y="135" width="75" height="18" fill="#ffffff" stroke="#000000" stroke-width="1"/><text x="715" y="147" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="11" font-weight="bold" fill="#000000" text-anchor="middle">restore()</text><line x1="760" y1="168.58333333333334" x2="129" y2="291.27777777777777" stroke="#000000" stroke-width="2" marker-end="url(#arrow)"/><rect x="354.5" y="210.93055555555554" width="180" height="18" fill="#ffffff" stroke="#000000" stroke-width="1"/><text x="444.5" y="222.93055555555554" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="11" font-weight="bold" fill="#000000" text-anchor="middle">destroy({ force: true })</text><circle cx="115" cy="154" r="14" fill="#000000" stroke="#000000" stroke-width="1"/><text x="115" y="184" font-family="ui-sans-serif, -apple-system, Segoe UI, Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#666666" text-anchor="middle">new</text><rect x="280" y="124" width="150" height="60" fill="#f0f0f0" stroke="#000000" stroke-width="1"/><text x="355" y="159" font-family="ui-sans-serif, -apple-system, Segoe UI, Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#000000" text-anchor="middle">validated</text><rect x="520" y="124" width="150" height="60" fill="#f0f0f0" stroke="#000000" stroke-width="1"/><text x="595" y="159" font-family="ui-sans-serif, -apple-system, Segoe UI, Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#000000" text-anchor="middle">persisted</text><rect x="760" y="124" width="150" height="60" fill="#f0f0f0" stroke="#000000" stroke-width="1"/><text x="835" y="159" font-family="ui-sans-serif, -apple-system, Segoe UI, Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#000000" text-anchor="middle">soft-deleted</text><circle cx="115" cy="294" r="14" fill="none" stroke="#000000" stroke-width="2"/><circle cx="115" cy="294" r="8" fill="#000000"/><text x="115" y="324" font-family="ui-sans-serif, -apple-system, Segoe UI, Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#666666" text-anchor="middle">gone</text></svg> </div> On a model that is not paranoid, destroy() goes straight to the final state — there is no soft-deleted step to come back from. Saving it generate() returns the SVG as a string; save(path) writes it straight to disk. Related reading Diagram generators — every generator and its options Models — the definitions these are drawn from