Document utilities
Pure functions over NogginDocument. validateDocument and normalizeDocument are the input-boundary defence used by every serializer; documentsEqual / diffDocuments power the change-event pipeline; freezeDocument is what providers hand out so accessors can return references without worrying about consumer mutation.
validateDocument()
function validateDocument(doc: NogginDocument): void;
Validate a document's structural invariants. Throws NogginError with code 'invalid-document' on failure.
Parameters
| Parameter | Type |
|---|---|
doc | NogginDocument |
Returns
void
normalizeDocument()
function normalizeDocument(doc: NogginDocument): NogginDocument;
Normalize a parsed document in-place: stamp schemaVersion, normalize notes, strip legacy fields.
Parameters
| Parameter | Type |
|---|---|
doc | NogginDocument |
Returns
documentsEqual()
function documentsEqual(a: NogginDocument, b: NogginDocument): boolean;
Structural equality between two documents. Used by providers to decide whether an external change actually changed anything.
Parameters
| Parameter | Type |
|---|---|
a | NogginDocument |
b | NogginDocument |
Returns
boolean
diffDocuments()
function diffDocuments(prev: NogginDocument, next: NogginDocument): ItemChange[];
Compute the list of ItemChanges describing the differences between two document snapshots. Pure; doesn't mutate either input. Used by providers to fire onDidChange with a concrete payload.
Parameters
| Parameter | Type |
|---|---|
prev | NogginDocument |
next | NogginDocument |
Returns
freezeDocument()
function freezeDocument(doc: NogginDocument): NogginDocument;
Deep-freeze a document so accessors can return references without worrying about consumer mutation.
Parameters
| Parameter | Type |
|---|---|
doc | NogginDocument |