Skip to content

refactor(nitro): Nitrogen specs, bridge boundaries, typed snapshots - #6

Merged
yfcyrus merged 5 commits into
mainfrom
refactor/nitrogen-specs
Nov 13, 2026
Merged

yfcyrus merged 5 commits into
mainfrom
refactor/nitrogen-specs

Conversation

@yfcyrus

@yfcyrus yfcyrus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

refactor: Nitrogen specs, bridge boundaries, typed snapshots

Why

The bridge was still mostly hand-written: easy to drift from the TS API, easy to miss a method at runtime. Snapshots were string maps on both sides. JSI had leaked into domain code. Every task looked like a list task. Peer deps didn’t match what Nitrogen 0.37.2 actually generates.

What

Nitrogen owns the HybridObject surface now (src/specs → nitrogen/generated). Domain stays JSI-free; bridge owns conversion. List streaming lives on NativeSmbListTask only. Task and pool snapshots are typed structs—codec and decode.ts are gone. Peer is react-native-nitro-modules >= 0.37.2.

App TS API unchanged. getResultValue / drainEntries stay raw until recursive SmbFileInfo can be generated.

Notes for reviewers

Big generated diff is expected. Review specs + bridge, not every generated line. Example still uses file:...

The method table, pure virtual interface, and iOS registration
duplicated the TypeScript API, and a missed registerHybridMethod
only showed up at runtime. Generate them from the specs so a missing
override fails to compile. Result payloads stay handwritten: one
task's result type varies, and SmbFileInfo is recursive.

- add src/specs and nitrogen/generated; register ReactNativeSmb from
  the generated autolinking +load instead of OnLoad.mm
- move domain structs to SmbModels and take SmbTask off HybridObject;
  HybridSMB and HybridSmbTask implement the generated specs
- keep getResultValue and drainEntries as raw methods, and keep the
  SmbFileInfo JSIConverter
- depend on Nitro 0.37.2, make react-native-nitro-modules an optional
  peer, and set FOLLY_CFG_NO_COROUTINES while excluding generated
  Swift from the pod
- rerun nitrogen in CI and fail when nitrogen/ drifts
Generated Nitrogen headers target 0.37.2, so an older peer would
compile against the wrong APIs. Keep the peer optional for non-RN
consumers of the TypeScript surface.

- set peerDependencies.react-native-nitro-modules to >=0.37.2
Domain tasks stored results as any plus a jsi::Runtime converter, so
operators and SmbTaskCore depended on Nitro headers. Publish a typed
variant instead and convert only in HybridSmbTask.

- add SmbTaskResult and ListingResult; EntryStream still holds listing rows
- move hand-written JSIConverters into bridge/DomainConverters.hpp
- strip jsi includes from SmbTaskCore, SmbTask, and OperatorBase
Entry streaming methods belonged on every HybridSmbTask even though
only listDirectory uses them, and every task allocated an EntryStream.
Generate a listing HybridObject that extends NativeSmbTask and create
the stream only for ListDirectory.

- add NativeSmbListTask.nitro.ts and HybridSmbListTask with raw drainEntries
- keep getResultValue on HybridSmbTask; listDirectory returns the list hybrid
- Nitrogen uses virtual inheritance for the HybridObject diamond
String-map snapshots forced a hand-written codec on both sides and hid
enum/struct types from Nitrogen. Specs now carry SmbTaskState and
PoolInfo so the bridge maps domain DTOs once and JS consumes typed values.

- add TaskStatus/SmbOperatorKind/SlotState plus snapshot/pool structs to specs
- bridge with toBridge; drop TaskSnapshotCodec and decode.ts
- update SmbTask/TransferStore/SmbClient and test mocks to typed objects
@yfcyrus
yfcyrus merged commit b22ff49 into main Nov 13, 2026
3 of 4 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.

1 participant