refactor: modularize Fn:: handlers + add recursion depth safety#86
Merged
refactor: modularize Fn:: handlers + add recursion depth safety#86
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts all Fn:: handlers from the monolithic
recurse()function insrc/index.tsinto individual modules undersrc/lib/functions/.Changes
src/index.ts: 889 → ~110 lines. Now a clean dispatcher using a handler registry.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)MAX_RECURSE_DEPTH=100with tracking through all recursive callscreateFnXxx(recurse)) gives each handler access torecursewithout circular importsTests