Skip to content

refactor: modularize Fn:: handlers + add recursion depth safety#86

Merged
nmccready merged 2 commits intomasterfrom
refactor/modularize-fn-functions
Feb 15, 2026
Merged

refactor: modularize Fn:: handlers + add recursion depth safety#86
nmccready merged 2 commits intomasterfrom
refactor/modularize-fn-functions

Conversation

@nmccready-tars
Copy link

Summary

Extracts all Fn:: handlers from the monolithic recurse() function in src/index.ts into individual modules under src/lib/functions/.

Changes

  • src/index.ts: 889 → ~110 lines. Now a clean dispatcher using a handler registry.
  • 10 new files under src/lib/functions/:
    • types.ts, helpers.ts, registry.ts (infrastructure)
    • fn-map.ts, fn-length.ts, fn-include.ts (complex handlers)
    • fn-array-ops.ts, fn-object-ops.ts, fn-string-ops.ts, fn-misc.ts (grouped by domain)
  • Depth safety: MAX_RECURSE_DEPTH=100 with tracking through all recursive calls
  • Factory pattern (createFnXxx(recurse)) gives each handler access to recurse without circular imports

Tests

  • 197/197 passing
  • No behavioral changes — pure refactor

…functions/

Phase 1 complete:
- Created src/lib/functions/ with types, helpers, and individual handler files
- fn-array-ops.ts: Flatten, FlattenDeep, Uniq, Compact, Concat, Sort, SortedUniq, SortBy, Without
- fn-object-ops.ts: Omit, OmitEmpty, Merge, DeepMerge, ObjectKeys, ObjectValues, SortObject
- fn-string-ops.ts: Stringify, StringSplit, UpperCamelCase, LowerCamelCase, JoinNow, SubNow
- fn-misc.ts: GetEnv, Eval, Filenames, Outputs, Sequence, IfEval, RefNow, ApplyTags
- fn-map.ts: Map handler
- fn-length.ts: Length handler
- fn-include.ts: Include handler with fnInclude, handleIncludeBody
- registry.ts: dispatch map Record<string, FnHandler>
- helpers.ts: findAndReplace, interpolate, JSONifyString, getBoolEnvOpt
- src/index.ts reduced from 889 to ~100 lines, clean dispatcher
- All 197 tests pass
Phase 2:
- Added depth parameter to RecurseContext, incremented on each recurse call
- Added MAX_RECURSE_DEPTH=100 safety limit to prevent stack overflow
- Depth is propagated through handler dispatch
- All 197 tests pass
@nmccready nmccready merged commit e321bde into master Feb 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants