Schema agnostic empty document creation

What’s the safest/cleanest way to create an empty document for any given schema without any “intimate” knowledge of the schema? E.g. we use multiple schemas in our system, and although many are simple/common doc -> block+ we also have some more specific schemas like a text only schema, or a more complex structure like doc -> section+ -> block+. I’m looking for a schema-agnostic way to create an empty document given a schema instance. Something like a createAndFill() that will work at the doc’s root level. Is it ok to use schema.nodes.doc.createAndFill() (because technically even the root’s doc is not a hardcoded/required node name from what I understand. Also, what is the difference between schema.node("nodeName") to schema.nodes.nodeName.create()?

You can do schema.topNodeType.createAndFill().

Nothing.

1 Like