Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export function createStructon(BaseClass) {
constructor(options = {}) {
super(options);

// Honor maxOwnStructures for the typed-struct path: bounds the per-encoder typed-structure
// dictionary (+ transition trie). Once reached, novel shapes fall back to plain encoding
// instead of growing the dictionary without limit. Default: uncapped (no behavior change).
if (options?.maxOwnStructures != null) this.maxOwnStructures = options.maxOwnStructures;

// Initialise typed structures state on this instance
if (!this.typedStructs) this.typedStructs = [];

Expand Down Expand Up @@ -75,6 +80,13 @@ export function createStructon(BaseClass) {
}
return encoded;
}
// Capped miss: fall back to plain base encoding. The base may persist its own
// named structures via saveStructures, overwriting our combined {named, typed}
// payload and stranding previously written struct data. Re-save afterward so the
// typed structures survive (this.structures now also holds any base record added).
const result = superEncode(value, encodeOptions);
if (this.typedStructs && this.typedStructs.length > 0) this._saveTypedStructures();
return result;
} finally {
this._onStructureAdded = null;
}
Expand Down
Loading