feat: add a Laravel-style Support layer (Str, Number, Arr, Cast, Env.filled, shortDiffForHumans, validateRequest, view mixins) - #202
Conversation
…DiffForHumans, validateRequest and view mixins
…per docs the review found
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Note Kodizm (AI-generated). May contain mistakes; verify before acting. Looks correct and well tested. Nothing here should block the merge. There is one testing-harness side effect worth fixing, plus two repo-rule gaps. Minor
TestsEvery new surface has its own test file: Number, Str, Arr, Cast, Env, the short Carbon diff, CI
I read all the |
…et under BREAKING and add example usage
|
@kodizm review Addressed the three points from the last pass:
|
|
Note Kodizm (AI-generated). May contain mistakes; verify before acting. All three earlier points are fixed, and the new commit looks correct. Nothing blocks the merge. What changed since the last review: Minor
Tests
CI
For this pass I read only the diff of |
|
Note Kodizm (AI-generated). May contain mistakes; verify before acting. The last open point is fixed and nothing new is introduced. Nothing blocks the merge. What changed since the last review: TestsNothing to cover, because this commit only changes a comment. CI
|
What
A Laravel-style Support layer for magic, extracted from helpers that apps built on magic kept writing for themselves:
Number(lib/src/support/number.dart):format,currency,percentage,fileSize,abbreviate, locale-aware through intl, locale fromLang.currentwith anenfallback for an unknown locale. Mirrors Laravel'sNumber:percentagetakes a 0-100 value,currencyis built onNumberFormat.simpleCurrency(tr₺1.234,50, notTRY1.234,50).Str(lib/src/support/str.dart):upper,lowerandinitialswith the Turkish/Azerbaijani dotted-i rule (istanbul->İSTANBULin tr), acceptingtr,tr_TRortr-TR;lowermapsİto a plainiin every locale because the JS engine adds a combining dot on web.CastandArr(lib/src/support/{cast,arr}.dart):Castreads a loosely typed wire value with a fallback instead of a hard cast (Cast.stringOr,Cast.intOrNull, ...; onlyintOrparses a numeric string).Arris dot-path access with Laravel'sget/has/set/dotsemantics and deliberately no typed accessors; typing composes withCast.Env:KEY=""andKEY=''now resolve to''(flutter_dotenv leaves the literal quotes), matching Laravel; blank still stays blank. NewEnv.filled(key, fallback)for a value a blank would corrupt, andEnv.getOrFail(key).Carbon.shortDiffForHumans([other]): a compact ladder (14m ago,1w ago,5m from now,Just now) throughtime.*catalogue keys with an English fallback;diffForHumansis unchanged.ValidatesRequests.validateRequest/validateRequestAsyncrun aFormRequestthrough the controller's own error bag and return the full prepared map;setErrorsFromMapplus anerrorFieldForhook, and the opt-inCollapsesIndexedErrorKeysmixin (items.0.name->name). The default keeps raw keys.RefetchesOnMountandSubmitsOnce(lib/src/ui/).MagicTest.init()also resets the Gate and the Translator between tests;MagicTest.loadTranslations(locale, {directory})loads a real catalogue for a widget test (JsonAssetLoader.flattenis now public).doc/digging-deeper/helpers.mdplus sections in carbon, validation, configuration, views and testing), CHANGELOG, skill, and thetimegroup in the install lang stub.Why
uptizm, watchools and depools each hand-rolled the same things: three apps format decimal separators through three different catalogue keys, two re-implement Turkish casing, and uptizm carried its own env cleaning, wire reads, request validation bridge, 422 key collapsing and view mixins. These belong at framework level the way Laravel ships
Str,NumberandArr.Testing
flutter analyze: no issues.flutter test: 1774 passing (was 1674 on master).dart format --set-exit-if-changed .: clean.Stralso runs on--platform chromebecause the dotted-i case only discriminates on web.1.234.567,891,%99,95, compact1,5 Mn).No version bump; publishing is a separate step.