@native-sdk/cli 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (465) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +320 -60
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +1818 -87
  8. package/package.json +19 -14
  9. package/packages/core/compile-surface/core.ts +134 -72
  10. package/packages/core/package-lock.json +75 -357
  11. package/packages/core/package.json +25 -4
  12. package/packages/core/scripts/compiler_command.mjs +17 -12
  13. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  14. package/packages/core/scripts/gen_declarations.mjs +3 -2
  15. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  16. package/packages/core/scripts/install_scriptc.mjs +182 -0
  17. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  18. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  19. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  20. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  21. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  22. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  23. package/packages/core/scripts/run_native_tests.mjs +22 -0
  24. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  25. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  26. package/packages/core/scripts/stage_external_core.mjs +57 -1
  27. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  28. package/packages/core/sdk/bytes.d.ts +2 -0
  29. package/packages/core/sdk/bytes.ts +86 -0
  30. package/packages/core/sdk/core.d.ts +308 -4
  31. package/packages/core/sdk/core.ts +320 -84
  32. package/packages/core/sdk/events.d.ts +247 -0
  33. package/packages/core/sdk/events.ts +230 -2
  34. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  35. package/packages/core/sdk/internal/image_identity.ts +71 -0
  36. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  37. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  38. package/packages/core/sdk/text.d.ts +27 -0
  39. package/packages/core/sdk/text.ts +206 -15
  40. package/packages/core/sdk/theme.d.ts +251 -0
  41. package/packages/core/sdk/theme.ts +267 -0
  42. package/packages/core/src/authorization.ts +137 -0
  43. package/packages/core/src/automation_commands.ts +201 -0
  44. package/packages/core/src/automation_interactions.ts +92 -0
  45. package/packages/core/src/bridge_descriptors.ts +104 -0
  46. package/packages/core/src/builtin_coordination.ts +172 -0
  47. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  48. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  49. package/packages/core/src/canvas_scene_observation.ts +145 -0
  50. package/packages/core/src/chart_content.ts +161 -0
  51. package/packages/core/src/chart_plans.ts +432 -0
  52. package/packages/core/src/checker.ts +166 -19
  53. package/packages/core/src/code_content.ts +580 -0
  54. package/packages/core/src/command_coordination.ts +140 -0
  55. package/packages/core/src/component_composition.ts +94 -0
  56. package/packages/core/src/component_construction.ts +149 -0
  57. package/packages/core/src/contract.ts +25 -7
  58. package/packages/core/src/control_appearance.ts +232 -0
  59. package/packages/core/src/control_commands.ts +115 -0
  60. package/packages/core/src/control_content.ts +105 -0
  61. package/packages/core/src/control_geometry.ts +107 -0
  62. package/packages/core/src/control_payloads.ts +119 -0
  63. package/packages/core/src/control_primitives.ts +134 -0
  64. package/packages/core/src/devhost.ts +82 -7
  65. package/packages/core/src/devhost_journal.mjs +30 -7
  66. package/packages/core/src/effect_plans.ts +71 -0
  67. package/packages/core/src/flow_measurement.ts +121 -0
  68. package/packages/core/src/font_registry.ts +37 -0
  69. package/packages/core/src/glyph_atlas.ts +86 -0
  70. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  71. package/packages/core/src/gpu_planning.ts +123 -0
  72. package/packages/core/src/gpu_presentation.ts +55 -0
  73. package/packages/core/src/host_flow.ts +89 -0
  74. package/packages/core/src/host_input_regions.ts +165 -0
  75. package/packages/core/src/image_registry.ts +66 -0
  76. package/packages/core/src/indicator_plans.ts +132 -0
  77. package/packages/core/src/infer.ts +150 -8
  78. package/packages/core/src/input_composition.ts +116 -0
  79. package/packages/core/src/intrinsic_measure.ts +100 -0
  80. package/packages/core/src/layout_coordination.ts +207 -0
  81. package/packages/core/src/leaf_plans.ts +134 -0
  82. package/packages/core/src/markup_development.ts +160 -0
  83. package/packages/core/src/measurement_coordination.ts +185 -0
  84. package/packages/core/src/modules.ts +1 -1
  85. package/packages/core/src/motion_sampling.ts +100 -0
  86. package/packages/core/src/paragraph_layout.ts +192 -0
  87. package/packages/core/src/portable_sources.json +74 -0
  88. package/packages/core/src/portable_sources.ts +17 -0
  89. package/packages/core/src/registered_font.ts +93 -0
  90. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  91. package/packages/core/src/render_coordination.ts +170 -0
  92. package/packages/core/src/render_resources.ts +234 -0
  93. package/packages/core/src/runtime_policy.ts +3930 -0
  94. package/packages/core/src/scalar_text.ts +84 -0
  95. package/packages/core/src/service_contract.ts +2 -1
  96. package/packages/core/src/session_codecs.ts +309 -0
  97. package/packages/core/src/shell_admission.ts +126 -0
  98. package/packages/core/src/shell_coordination.ts +93 -0
  99. package/packages/core/src/sqlite_cli.ts +11 -0
  100. package/packages/core/src/status_validation.ts +232 -0
  101. package/packages/core/src/stream_policy.ts +63 -0
  102. package/packages/core/src/surface_recipes.ts +136 -0
  103. package/packages/core/src/system_admission.ts +60 -0
  104. package/packages/core/src/terminal_paint.ts +436 -0
  105. package/packages/core/src/text_document_width.ts +81 -0
  106. package/packages/core/src/text_measurement_cache.ts +69 -0
  107. package/packages/core/src/text_query_layout.ts +179 -0
  108. package/packages/core/src/text_run_layout.ts +410 -0
  109. package/packages/core/src/text_span_queries.ts +355 -0
  110. package/packages/core/src/typed_ast.ts +18 -1
  111. package/packages/core/src/types.ts +7 -5
  112. package/packages/core/src/vector_effects.ts +98 -0
  113. package/packages/core/src/vector_raster.ts +243 -0
  114. package/packages/core/src/view_components.ts +2415 -0
  115. package/packages/core/src/view_coordination.ts +198 -0
  116. package/packages/core/src/view_frontend.ts +980 -0
  117. package/packages/core/src/widget_audits.ts +202 -0
  118. package/packages/core/src/widget_changes.ts +258 -0
  119. package/packages/core/src/widget_metrics.ts +139 -0
  120. package/packages/core/src/widget_motion.ts +171 -0
  121. package/packages/core/src/widget_paint.ts +272 -0
  122. package/packages/core/src/widget_paint_walk.ts +203 -0
  123. package/packages/core/src/widget_presentation.ts +141 -0
  124. package/packages/core/src/widget_routing.ts +262 -0
  125. package/packages/core/src/window_lifecycle.ts +92 -0
  126. package/packages/core/testing/index.ts +430 -0
  127. package/schemas/app.schema.json +13 -0
  128. package/skill-data/core/SKILL.md +2 -2
  129. package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
  130. package/skill-data/native-ui/SKILL.md +76 -17
  131. package/skill-data/ts-core/SKILL.md +113 -9
  132. package/skill-data/ts-services/SKILL.md +1 -1
  133. package/skill-data/ts-services/references/service-surface.md +264 -144
  134. package/src/app_runner/root.zig +25 -12
  135. package/src/app_runner/ts_compiled_view.zig +1631 -0
  136. package/src/app_runner/ts_core_main.zig +143 -10
  137. package/src/app_runner/ts_core_mobile.zig +24 -12
  138. package/src/automation/server.zig +1 -3
  139. package/src/automation/snapshot.zig +9 -637
  140. package/src/automation/snapshot_reference.zig +656 -0
  141. package/src/automation/snapshot_serialization.zig +566 -0
  142. package/src/platform/linux/gtk_host.c +36 -24
  143. package/src/platform/linux/gtk_pixels.h +118 -0
  144. package/src/platform/linux/gtk_pixels_test.c +241 -0
  145. package/src/platform/linux/root.zig +2 -0
  146. package/src/platform/macos/appkit_host.m +188 -30
  147. package/src/platform/macos/pointer_motion_test.m +96 -0
  148. package/src/platform/macos/scroll_driver_test.m +105 -0
  149. package/src/platform/macos/spectrum_bins.h +34 -0
  150. package/src/platform/macos/spectrum_bins_test.c +56 -0
  151. package/src/platform/macos/text_keyboard_test.m +80 -0
  152. package/src/platform/macos/widget_focus_test.m +66 -0
  153. package/src/platform/null_platform.zig +26 -2
  154. package/src/platform/null_platform_tests.zig +13 -0
  155. package/src/platform/root.zig +1 -0
  156. package/src/platform/types.zig +13 -0
  157. package/src/platform/windows/root.zig +2 -0
  158. package/src/platform/windows/webview2_host.cpp +7 -2
  159. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  160. package/src/primitives/app_manifest/root.zig +2 -0
  161. package/src/primitives/app_manifest/tests.zig +4 -1
  162. package/src/primitives/app_manifest/validation.zig +2 -0
  163. package/src/primitives/canvas/a11y_audit.zig +3 -1
  164. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  165. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  166. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  167. package/src/primitives/canvas/code_content_policy.zig +162 -0
  168. package/src/primitives/canvas/commands.zig +29 -1
  169. package/src/primitives/canvas/component_composition.zig +125 -0
  170. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  171. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  172. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  173. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  174. package/src/primitives/canvas/control_command_policy.zig +75 -0
  175. package/src/primitives/canvas/control_content_policy.zig +90 -0
  176. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  177. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  178. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  179. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  180. package/src/primitives/canvas/events.zig +1027 -1
  181. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  182. package/src/primitives/canvas/frame.zig +92 -23
  183. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  184. package/src/primitives/canvas/gpu.zig +10 -0
  185. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  186. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  187. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  188. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  189. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  190. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  191. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  192. package/src/primitives/canvas/layout_audit.zig +5 -2
  193. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  194. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  195. package/src/primitives/canvas/markdown.zig +13 -3
  196. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  197. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  198. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  199. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  200. package/src/primitives/canvas/reference.zig +12 -6
  201. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  202. package/src/primitives/canvas/render.zig +48 -0
  203. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  204. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  205. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  206. package/src/primitives/canvas/render_effects.zig +14 -0
  207. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  208. package/src/primitives/canvas/render_images.zig +14 -0
  209. package/src/primitives/canvas/render_layers.zig +14 -0
  210. package/src/primitives/canvas/render_override_policy.zig +119 -0
  211. package/src/primitives/canvas/render_paths.zig +14 -0
  212. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  213. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  214. package/src/primitives/canvas/root.zig +100 -0
  215. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  216. package/src/primitives/canvas/serialization.zig +8 -1
  217. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  218. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  219. package/src/primitives/canvas/terminal_grid.zig +10 -696
  220. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  221. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  222. package/src/primitives/canvas/text.zig +1 -0
  223. package/src/primitives/canvas/text_atlas.zig +113 -0
  224. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  225. package/src/primitives/canvas/text_document_policy.zig +120 -0
  226. package/src/primitives/canvas/text_layout.zig +51 -2
  227. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  228. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  229. package/src/primitives/canvas/text_layout_types.zig +3 -0
  230. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  231. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  232. package/src/primitives/canvas/text_metrics.zig +23 -0
  233. package/src/primitives/canvas/text_query_policy.zig +156 -0
  234. package/src/primitives/canvas/text_run_policy.zig +252 -0
  235. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  236. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  237. package/src/primitives/canvas/text_spans.zig +280 -8
  238. package/src/primitives/canvas/text_tests.zig +10 -0
  239. package/src/primitives/canvas/tokens.zig +38 -0
  240. package/src/primitives/canvas/ui.zig +250 -83
  241. package/src/primitives/canvas/ui_markup.zig +139 -33
  242. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  243. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  244. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  245. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  246. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  247. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  248. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  249. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  250. package/src/primitives/canvas/ui_schema.zig +13 -1
  251. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  252. package/src/primitives/canvas/ui_tests.zig +1 -0
  253. package/src/primitives/canvas/vector.zig +36 -2
  254. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  255. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  256. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  257. package/src/primitives/canvas/virtual_extents.zig +99 -3
  258. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  259. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  260. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  261. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  262. package/src/primitives/canvas/widget_layout.zig +673 -128
  263. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  264. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  265. package/src/primitives/canvas/widget_metrics.zig +45 -6
  266. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  267. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  268. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  269. package/src/primitives/canvas/widget_render.zig +744 -74
  270. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  271. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  272. package/src/primitives/canvas/widget_render_style.zig +94 -0
  273. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  274. package/src/primitives/canvas/widget_routing.zig +75 -0
  275. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  276. package/src/primitives/canvas/widget_runtime.zig +20 -1
  277. package/src/primitives/canvas/widget_semantics.zig +25 -0
  278. package/src/primitives/canvas/widget_text_input.zig +86 -23
  279. package/src/primitives/canvas/widget_text_select.zig +1 -0
  280. package/src/primitives/canvas/widget_tree.zig +8 -1
  281. package/src/primitives/canvas/widgets.zig +42 -12
  282. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  283. package/src/root.zig +21 -0
  284. package/src/runtime/accessibility_policy.zig +122 -0
  285. package/src/runtime/api.zig +28 -0
  286. package/src/runtime/app_dispatch_policy.zig +68 -0
  287. package/src/runtime/authorization_policy.zig +150 -0
  288. package/src/runtime/automation_command_policy.zig +241 -0
  289. package/src/runtime/automation_interaction_policy.zig +107 -0
  290. package/src/runtime/automation_snapshot.zig +52 -22
  291. package/src/runtime/automation_snapshot_reference.zig +290 -0
  292. package/src/runtime/automation_widget_dispatch.zig +267 -355
  293. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  294. package/src/runtime/blob_policy.zig +58 -0
  295. package/src/runtime/blob_reference.zig +64 -0
  296. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  297. package/src/runtime/builtin_bridge.zig +180 -44
  298. package/src/runtime/builtin_coordination_policy.zig +121 -0
  299. package/src/runtime/callback_policy_test_reference.zig +97 -0
  300. package/src/runtime/canvas_drag_policy.zig +94 -0
  301. package/src/runtime/canvas_fonts.zig +38 -10
  302. package/src/runtime/canvas_frame.zig +590 -134
  303. package/src/runtime/canvas_frame_helpers.zig +1 -0
  304. package/src/runtime/canvas_hover_policy.zig +131 -0
  305. package/src/runtime/canvas_images.zig +59 -30
  306. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  307. package/src/runtime/canvas_limits.zig +1 -1
  308. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  309. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  310. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  311. package/src/runtime/canvas_widget_display.zig +110 -9
  312. package/src/runtime/canvas_widget_events.zig +718 -328
  313. package/src/runtime/canvas_widget_runtime.zig +437 -81
  314. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  315. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  316. package/src/runtime/canvas_widget_state.zig +93 -56
  317. package/src/runtime/channel_sources.zig +80 -0
  318. package/src/runtime/command_policy.zig +161 -0
  319. package/src/runtime/component_policy.zig +83 -0
  320. package/src/runtime/core.zig +156 -6
  321. package/src/runtime/desktop_files.zig +189 -0
  322. package/src/runtime/effects.zig +466 -29
  323. package/src/runtime/effects_tests.zig +28 -0
  324. package/src/runtime/file_policy_test_reference.zig +113 -0
  325. package/src/runtime/flow.zig +418 -341
  326. package/src/runtime/flow_reference.zig +1426 -0
  327. package/src/runtime/font_registry_policy.zig +72 -0
  328. package/src/runtime/frame_profile.zig +24 -33
  329. package/src/runtime/gpu_surface_events.zig +97 -35
  330. package/src/runtime/host_event_pump.zig +303 -0
  331. package/src/runtime/host_event_pump_reference.zig +268 -0
  332. package/src/runtime/host_flow_policy.zig +155 -0
  333. package/src/runtime/host_input_regions_policy.zig +156 -0
  334. package/src/runtime/image_registry_policy.zig +94 -0
  335. package/src/runtime/input_composition_policy.zig +138 -0
  336. package/src/runtime/journal_policy.zig +66 -0
  337. package/src/runtime/journal_reference.zig +53 -0
  338. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  339. package/src/runtime/markup_development_policy.zig +91 -0
  340. package/src/runtime/media_surface.zig +40 -1
  341. package/src/runtime/motion_sampling_policy.zig +159 -0
  342. package/src/runtime/recording_policy.zig +42 -0
  343. package/src/runtime/render_animation_policy.zig +206 -0
  344. package/src/runtime/replay_policy.zig +66 -0
  345. package/src/runtime/replay_policy_reference.zig +326 -0
  346. package/src/runtime/replay_progress_policy.zig +64 -0
  347. package/src/runtime/replay_progress_reference.zig +34 -0
  348. package/src/runtime/request_policy_test_reference.zig +188 -0
  349. package/src/runtime/root.zig +13 -0
  350. package/src/runtime/session_blobs.zig +157 -58
  351. package/src/runtime/session_blobs_reference.zig +692 -0
  352. package/src/runtime/session_codec.zig +361 -0
  353. package/src/runtime/session_codec_reference.zig +1027 -0
  354. package/src/runtime/session_journal.zig +246 -983
  355. package/src/runtime/session_record.zig +224 -45
  356. package/src/runtime/session_replay.zig +157 -415
  357. package/src/runtime/session_tests.zig +552 -0
  358. package/src/runtime/shell_admission_policy.zig +225 -0
  359. package/src/runtime/shell_coordination_policy.zig +138 -0
  360. package/src/runtime/shell_layout.zig +126 -1
  361. package/src/runtime/snapshot_policy.zig +60 -0
  362. package/src/runtime/snapshot_reference.zig +64 -0
  363. package/src/runtime/state.zig +16 -0
  364. package/src/runtime/status_validation.zig +190 -0
  365. package/src/runtime/system_admission_policy.zig +140 -0
  366. package/src/runtime/system_services.zig +46 -36
  367. package/src/runtime/tests.zig +1 -0
  368. package/src/runtime/ts_canvas_hooks.zig +261 -0
  369. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  370. package/src/runtime/ts_canvas_icons.zig +234 -0
  371. package/src/runtime/ts_core_host.zig +2325 -411
  372. package/src/runtime/ts_core_host_tests.zig +1982 -0
  373. package/src/runtime/ts_test_host.zig +699 -0
  374. package/src/runtime/ts_ui_app.zig +1087 -45
  375. package/src/runtime/ui_app.zig +1117 -629
  376. package/src/runtime/ui_app_provenance.zig +147 -5
  377. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  378. package/src/runtime/ui_app_tests.zig +619 -9
  379. package/src/runtime/ui_app_window_tests.zig +89 -0
  380. package/src/runtime/view.zig +25 -0
  381. package/src/runtime/view_canvas.zig +30 -6
  382. package/src/runtime/view_coordination_policy.zig +147 -0
  383. package/src/runtime/view_widget_control.zig +51 -14
  384. package/src/runtime/view_widget_scroll.zig +16 -5
  385. package/src/runtime/view_widget_text.zig +153 -68
  386. package/src/runtime/view_widget_tree.zig +460 -56
  387. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  388. package/src/runtime/widget_motion_policy.zig +238 -0
  389. package/src/runtime/window_command_bridge_tests.zig +63 -0
  390. package/src/runtime/window_lifecycle_policy.zig +127 -0
  391. package/src/runtime/window_storage.zig +74 -8
  392. package/src/runtime/window_view_runtime.zig +148 -33
  393. package/src/runtime/window_views.zig +163 -10
  394. package/src/tooling/codesign.zig +125 -74
  395. package/src/tooling/components/identity_tests.zig +62 -36
  396. package/src/tooling/components/stepper.native +24 -0
  397. package/src/tooling/components/stepper.zig +0 -19
  398. package/src/tooling/components/timeline-item.native +22 -0
  399. package/src/tooling/components/timeline.native +5 -3
  400. package/src/tooling/components/timeline_item.zig +0 -32
  401. package/src/tooling/eject_components.zig +76 -8
  402. package/src/tooling/ios.zig +66 -12
  403. package/src/tooling/manifest.zig +35 -0
  404. package/src/tooling/package.zig +85 -1
  405. package/src/tooling/raw_manifest.zig +6 -0
  406. package/src/tooling/templates.zig +15 -3
  407. package/src/tooling/ts_core.zig +13 -3
  408. package/src/tooling/verbs.zig +22 -0
  409. package/tools/corewire/build_profile.mjs +54 -0
  410. package/tools/corewire/contract_intake.ts +303 -0
  411. package/tools/corewire/contract_intake.zig +82 -0
  412. package/tools/corewire/core.test.ts +166 -0
  413. package/tools/corewire/core_abi.zig +51 -0
  414. package/tools/corewire/core_cases.ts +233 -0
  415. package/tools/corewire/core_contract.ts +407 -0
  416. package/tools/corewire/core_emission.ts +136 -0
  417. package/tools/corewire/core_emission.zig +69 -0
  418. package/tools/corewire/core_goldens.json +3110 -0
  419. package/tools/corewire/core_policy.ts +14 -0
  420. package/tools/corewire/core_policy.zig +48 -0
  421. package/tools/corewire/core_projection.ts +360 -0
  422. package/tools/corewire/core_vocabulary.ts +6 -0
  423. package/tools/corewire/emit.zig +19 -1590
  424. package/tools/corewire/emit_facade.ts +714 -0
  425. package/tools/corewire/emit_facade.zig +10 -3752
  426. package/tools/corewire/emit_mirror.ts +290 -0
  427. package/tools/corewire/emit_profile.ts +50 -0
  428. package/tools/corewire/emit_service.ts +331 -0
  429. package/tools/corewire/emit_service.zig +23 -842
  430. package/tools/corewire/entry.test.ts +95 -0
  431. package/tools/corewire/entry_coordination.ts +127 -0
  432. package/tools/corewire/entry_coordination.zig +190 -0
  433. package/tools/corewire/facade_templates.ts +85 -0
  434. package/tools/corewire/filesystem.test.ts +166 -0
  435. package/tools/corewire/filesystem_coordination.ts +213 -0
  436. package/tools/corewire/filesystem_coordination.zig +245 -0
  437. package/tools/corewire/intake.test.ts +35 -0
  438. package/tools/corewire/intake_cases.ts +55 -0
  439. package/tools/corewire/intake_goldens.json +12237 -0
  440. package/tools/corewire/invocation.test.ts +24 -0
  441. package/tools/corewire/invocation.ts +175 -0
  442. package/tools/corewire/invocation.zig +136 -0
  443. package/tools/corewire/invocation_cases.ts +60 -0
  444. package/tools/corewire/invocation_fixture.ts +33 -0
  445. package/tools/corewire/invocation_goldens.json +1143 -0
  446. package/tools/corewire/invocation_tests.zig +111 -0
  447. package/tools/corewire/invocation_usage.ts +2 -0
  448. package/tools/corewire/lossless_projection.ts +96 -0
  449. package/tools/corewire/main.zig +7 -680
  450. package/tools/corewire/main_reference.zig +415 -0
  451. package/tools/corewire/mirror_templates.ts +55 -0
  452. package/tools/corewire/profile.test.ts +248 -0
  453. package/tools/corewire/profile.zig +56 -0
  454. package/tools/corewire/profile_emission.ts +202 -0
  455. package/tools/corewire/profile_library.json +29 -0
  456. package/tools/corewire/profile_tests.zig +136 -0
  457. package/tools/corewire/service.test.ts +75 -0
  458. package/tools/corewire/service_cases.ts +61 -0
  459. package/tools/corewire/service_contract.zig +40 -146
  460. package/tools/corewire/service_goldens.json +650 -0
  461. package/tools/corewire/service_projection.zig +52 -0
  462. package/tools/corewire/service_templates.ts +14 -0
  463. package/tools/corewire/shim_rt.zig +9 -0
  464. package/tools/corewire/sidecar.zig +267 -1438
  465. package/tools/corewire/emit_profile.zig +0 -521
@@ -1,815 +1,27 @@
1
- //! Fourth corewire projection: the service entries and the Zig name/index
2
- //! registry consumed by the runner transports. Two entry projections share
3
- //! one contract: the plain-scriptc child-process host main (framed stdio)
4
- //! and the in-process library facade (a library-mode archive linked into
5
- //! the app binary, one instance per pool thread).
6
-
1
+ //! Native structural and owned-byte adapter for compiled service generation.
7
2
  const std = @import("std");
8
3
  const service = @import("service_contract.zig");
4
+ const projection = @import("service_projection.zig");
9
5
 
10
- /// The in-process service archive's C symbol family. Distinct from the
11
- /// compiled core's prefix (the frontend's abi.prefix, canonically
12
- /// "nsc_core_") so both archives link into one binary; fixed because one
13
- /// app binary carries at most one service archive.
14
- pub const inproc_symbol_prefix = "nsc_svc_";
15
-
16
- const fingerprint_len = std.crypto.hash.sha2.Sha256.digest_length;
17
-
18
- fn fingerprintField(hasher: *std.crypto.hash.sha2.Sha256, bytes: []const u8) void {
19
- var len: [8]u8 = undefined;
20
- std.mem.writeInt(u64, &len, @intCast(bytes.len), .little);
21
- hasher.update(&len);
22
- hasher.update(bytes);
23
- }
24
-
25
- fn fingerprintType(hasher: *std.crypto.hash.sha2.Sha256, ref: service.TypeRef) void {
26
- hasher.update(&.{@intFromEnum(ref.kind)});
27
- if (ref.inner) |inner| fingerprintType(hasher, inner.*);
28
- if (ref.elem) |elem| fingerprintType(hasher, elem.*);
29
- if (ref.name) |name| fingerprintField(hasher, name);
30
- }
31
-
32
- /// Identity of the service ABI facts both carriers put on the wire. The same
33
- /// digest is embedded in the service executable and the Zig registry so a
34
- /// stale or hand-supplied sibling is refused before numeric indices are used.
35
- ///
36
- /// Deliberately excluded: compiler/package identities, implementation module
37
- /// paths and exports, and `source_hash`. Those facts rebuild the service
38
- /// executable, but they do not change operation indices or encoded values and
39
- /// therefore must not rewrite the app runner or recompile the app core.
40
- fn contractFingerprint(contract: service.Contract) [fingerprint_len]u8 {
41
- var hasher = std.crypto.hash.sha2.Sha256.init(.{});
42
- hasher.update("native-sdk.services.abi.v3\x00");
43
- var scalar: [8]u8 = undefined;
44
- std.mem.writeInt(i64, &scalar, contract.format, .little);
45
- hasher.update(&scalar);
46
- std.mem.writeInt(i64, &scalar, contract.protocol_version, .little);
47
- hasher.update(&scalar);
48
- for (contract.types.records) |record| {
49
- fingerprintField(&hasher, record.name);
50
- for (record.fields) |field| {
51
- fingerprintField(&hasher, field.name);
52
- fingerprintType(&hasher, field.type);
53
- }
54
- }
55
- for (contract.types.enums) |enum_type| {
56
- fingerprintField(&hasher, enum_type.name);
57
- for (enum_type.members) |member| fingerprintField(&hasher, member);
58
- }
59
- for (contract.types.unions) |union_type| {
60
- fingerprintField(&hasher, union_type.name);
61
- for (union_type.arms) |arm| {
62
- fingerprintField(&hasher, arm.name);
63
- for (arm.fields) |field| {
64
- fingerprintField(&hasher, field.name);
65
- fingerprintType(&hasher, field.type);
66
- }
67
- }
68
- }
69
- std.mem.writeInt(u64, &scalar, @intCast(contract.operations.len), .little);
70
- hasher.update(&scalar);
71
- for (contract.operations) |op| {
72
- fingerprintField(&hasher, op.name);
73
- fingerprintType(&hasher, op.request);
74
- fingerprintType(&hasher, op.result);
75
- std.mem.writeInt(i64, &scalar, op.deadline_ms orelse 0, .little);
76
- hasher.update(&scalar);
77
- hasher.update(&.{@intFromBool(op.cancellable)});
78
- if (op.stream) |stream| {
79
- hasher.update(&.{1});
80
- fingerprintType(&hasher, stream.chunk);
81
- std.mem.writeInt(i64, &scalar, stream.in_flight, .little);
82
- hasher.update(&scalar);
83
- } else hasher.update(&.{0});
84
- }
85
- return hasher.finalResult();
86
- }
87
-
88
- fn jsString(w: *std.Io.Writer, value: []const u8) !void {
89
- try w.writeByte('"');
90
- for (value) |byte| switch (byte) {
91
- '"' => try w.writeAll("\\\""),
92
- '\\' => try w.writeAll("\\\\"),
93
- '\n' => try w.writeAll("\\n"),
94
- '\r' => try w.writeAll("\\r"),
95
- '\t' => try w.writeAll("\\t"),
96
- else => if (byte < 0x20)
97
- try w.print("\\u00{x:0>2}", .{byte})
98
- else
99
- try w.writeByte(byte),
100
- };
101
- try w.writeByte('"');
6
+ fn generate(arena: std.mem.Allocator, contract: service.Contract, name: []const u8) ![]const u8 {
7
+ const input = try std.json.Stringify.valueAlloc(arena, contract, .{});
8
+ defer arena.free(input);
9
+ return projection.generate(arena, input, name, "");
102
10
  }
103
-
104
- fn emitDecodeExpr(w: *std.Io.Writer, ref: service.TypeRef, reader: []const u8) !void {
105
- switch (ref.kind) {
106
- .none => try w.writeAll("undefined"),
107
- .bool => try w.print("{s}.bool()", .{reader}),
108
- .f64 => try w.print("{s}.f64()", .{reader}),
109
- .i64 => try w.print("{s}.i64()", .{reader}),
110
- .bytes => try w.print("{s}.bytesValue()", .{reader}),
111
- .optional => {
112
- try w.print("readOptional({s}, (nested) => ", .{reader});
113
- try emitDecodeExpr(w, ref.inner.?.*, "nested");
114
- try w.writeByte(')');
115
- },
116
- .slice => {
117
- try w.print("readSlice({s}, (nested) => ", .{reader});
118
- try emitDecodeExpr(w, ref.elem.?.*, "nested");
119
- try w.writeByte(')');
120
- },
121
- .record, .@"enum", .@"union" => try w.print("__nativeSdkDecode{s}({s})", .{ ref.name.?, reader }),
122
- }
123
- }
124
-
125
- fn emitEncodeExpr(w: *std.Io.Writer, ref: service.TypeRef, value: []const u8) !void {
126
- switch (ref.kind) {
127
- .none => try w.writeAll("new Uint8Array(0)"),
128
- .bool => try w.print("writeBool({s})", .{value}),
129
- .f64 => try w.print("writeF64({s})", .{value}),
130
- .i64 => try w.print("writeI64({s})", .{value}),
131
- .bytes => try w.print("writeBytes({s})", .{value}),
132
- .optional => {
133
- try w.print("{s} === null ? writeOptional(null) : writeOptional(", .{value});
134
- try emitEncodeExpr(w, ref.inner.?.*, value);
135
- try w.writeByte(')');
136
- },
137
- .slice => {
138
- try w.print("writeSlice({s}.map((item) => ", .{value});
139
- try emitEncodeExpr(w, ref.elem.?.*, "item");
140
- try w.writeAll("))");
141
- },
142
- .record, .@"enum", .@"union" => try w.print("__nativeSdkEncode{s}({s})", .{ ref.name.?, value }),
143
- }
144
- }
145
-
146
- fn emitHostCodecs(w: *std.Io.Writer, contract: service.Contract) !void {
147
- try w.writeAll(
148
- \\class __NativeSdkReader {
149
- \\ readonly bytes: Uint8Array;
150
- \\ at: number;
151
- \\ constructor(bytes: Uint8Array) { this.bytes = bytes; this.at = 0; }
152
- \\ take(length: number): Uint8Array {
153
- \\ if (length < 0 || this.at + length > this.bytes.length) throw new Error("truncated service value");
154
- \\ const out = this.bytes.subarray(this.at, this.at + length);
155
- \\ this.at += length;
156
- \\ return out;
157
- \\ }
158
- \\ u8(): number { return this.take(1)[0]; }
159
- \\ u32(): number {
160
- \\ const b = this.take(4);
161
- \\ return (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0;
162
- \\ }
163
- \\ bool(): boolean {
164
- \\ const value = this.u8();
165
- \\ if (value > 1) throw new Error("invalid service boolean");
166
- \\ return value === 1;
167
- \\ }
168
- \\ f64(): number {
169
- \\ const b = this.take(8);
170
- \\ return new DataView(b.buffer, b.byteOffset, 8).getFloat64(0, true);
171
- \\ }
172
- \\ i64(): number {
173
- \\ const b = this.take(8);
174
- \\ const view = new DataView(b.buffer, b.byteOffset, 8);
175
- \\ return view.getUint32(0, true) + view.getInt32(4, true) * 4294967296;
176
- \\ }
177
- \\ bytesValue(): Uint8Array { return this.take(this.u32()); }
178
- \\ finish(): void {
179
- \\ if (this.at !== this.bytes.length) throw new Error("trailing service value bytes");
180
- \\ }
181
- \\}
182
- \\function readOptional<T>(reader: __NativeSdkReader, decode: (reader: __NativeSdkReader) => T): T | null {
183
- \\ const present = reader.u8();
184
- \\ if (present === 0) return null;
185
- \\ if (present !== 1) throw new Error("invalid service optional");
186
- \\ return decode(reader);
187
- \\}
188
- \\function readSlice<T>(reader: __NativeSdkReader, decode: (reader: __NativeSdkReader) => T): T[] {
189
- \\ const count = reader.u32();
190
- \\ const out: T[] = [];
191
- \\ for (let i = 0; i < count; i++) out.push(decode(reader));
192
- \\ return out;
193
- \\}
194
- \\function writeU32(value: number): Uint8Array {
195
- \\ const out = new Uint8Array(4);
196
- \\ new DataView(out.buffer).setUint32(0, value, true);
197
- \\ return out;
198
- \\}
199
- \\function concat(parts: readonly Uint8Array[]): Uint8Array {
200
- \\ let length = 0;
201
- \\ for (const part of parts) length += part.length;
202
- \\ const out = new Uint8Array(length);
203
- \\ let at = 0;
204
- \\ for (const part of parts) { out.set(part, at); at += part.length; }
205
- \\ return out;
206
- \\}
207
- \\function writeBool(value: boolean): Uint8Array { return new Uint8Array([value ? 1 : 0]); }
208
- \\function writeF64(value: number): Uint8Array {
209
- \\ const out = new Uint8Array(8);
210
- \\ new DataView(out.buffer).setFloat64(0, Number.isNaN(value) ? Number.NaN : value, true);
211
- \\ return out;
212
- \\}
213
- \\function writeI64(value: number): Uint8Array {
214
- \\ const out = new Uint8Array(8);
215
- \\ const view = new DataView(out.buffer);
216
- \\ const base = 4294967296;
217
- \\ let low = value % base;
218
- \\ if (low < 0) low += base;
219
- \\ view.setUint32(0, low, true);
220
- \\ view.setInt32(4, Math.floor(value / base), true);
221
- \\ return out;
222
- \\}
223
- \\function writeBytes(value: Uint8Array): Uint8Array { return concat([writeU32(value.length), value]); }
224
- \\function writeOptional(value: Uint8Array | null): Uint8Array {
225
- \\ return value === null ? new Uint8Array([0]) : concat([new Uint8Array([1]), value]);
226
- \\}
227
- \\function writeSlice(values: readonly Uint8Array[]): Uint8Array {
228
- \\ return concat([writeU32(values.length), ...values]);
229
- \\}
230
- \\
231
- );
232
- for (contract.types.records) |record| {
233
- try w.print("function __nativeSdkDecode{s}(reader: __NativeSdkReader): {s} {{ return {{ ", .{ record.name, record.name });
234
- for (record.fields, 0..) |field, index| {
235
- if (index > 0) try w.writeAll(", ");
236
- try w.print("{s}: ", .{field.name});
237
- try emitDecodeExpr(w, field.type, "reader");
238
- }
239
- try w.writeAll(" }; }\n");
240
- try w.print("function __nativeSdkEncode{s}(value: {s}): Uint8Array {{ return concat([", .{ record.name, record.name });
241
- for (record.fields, 0..) |field, index| {
242
- if (index > 0) try w.writeAll(", ");
243
- const field_value = try std.fmt.allocPrint(std.heap.page_allocator, "value.{s}", .{field.name});
244
- defer std.heap.page_allocator.free(field_value);
245
- try emitEncodeExpr(w, field.type, field_value);
246
- }
247
- try w.writeAll("]); }\n");
248
- }
249
- for (contract.types.enums) |enum_type| {
250
- try w.print("function __nativeSdkDecode{s}(reader: __NativeSdkReader): {s} {{ switch (reader.u32()) {{\n", .{ enum_type.name, enum_type.name });
251
- for (enum_type.members, 0..) |member, index| {
252
- try w.print(" case {d}: return ", .{index});
253
- try jsString(w, member);
254
- try w.writeAll(";\n");
255
- }
256
- try w.writeAll(" default: throw new Error(\"invalid service enum\");\n} }\n");
257
- try w.print("function __nativeSdkEncode{s}(value: {s}): Uint8Array {{ return writeU32(", .{ enum_type.name, enum_type.name });
258
- for (enum_type.members, 0..) |member, index| {
259
- try w.writeAll("value === ");
260
- try jsString(w, member);
261
- try w.print(" ? {d} : (", .{index});
262
- }
263
- try w.writeAll("0");
264
- for (enum_type.members) |_| try w.writeByte(')');
265
- try w.writeAll("); }\n");
266
- }
267
- for (contract.types.unions) |union_type| {
268
- try w.print("function __nativeSdkDecode{s}(reader: __NativeSdkReader): {s} {{ switch (reader.u8()) {{\n", .{ union_type.name, union_type.name });
269
- for (union_type.arms, 0..) |arm, index| {
270
- try w.print(" case {d}: return {{ kind: ", .{index});
271
- try jsString(w, arm.name);
272
- for (arm.fields) |field| {
273
- try w.print(", {s}: ", .{field.name});
274
- try emitDecodeExpr(w, field.type, "reader");
275
- }
276
- try w.writeAll(" };\n");
277
- }
278
- try w.writeAll(" default: throw new Error(\"invalid service union\");\n} }\n");
279
- try w.print("function __nativeSdkEncode{s}(value: {s}): Uint8Array {{ switch (value.kind) {{\n", .{ union_type.name, union_type.name });
280
- for (union_type.arms, 0..) |arm, index| {
281
- try w.writeAll(" case ");
282
- try jsString(w, arm.name);
283
- try w.print(": return concat([new Uint8Array([{d}])", .{index});
284
- for (arm.fields) |field| {
285
- try w.writeAll(", ");
286
- const field_value = try std.fmt.allocPrint(std.heap.page_allocator, "value.{s}", .{field.name});
287
- defer std.heap.page_allocator.free(field_value);
288
- try emitEncodeExpr(w, field.type, field_value);
289
- }
290
- try w.writeAll("]);\n");
291
- }
292
- try w.writeAll("} }\n");
293
- }
294
- }
295
-
296
11
  pub fn emitHost(arena: std.mem.Allocator, contract: service.Contract) ![]const u8 {
297
- var out = std.Io.Writer.Allocating.init(arena);
298
- const w = &out.writer;
299
- try w.writeAll(
300
- \\// Generated by corewire from services.contract.json. Do not edit.
301
- \\import * as fs from "node:fs";
302
- \\
303
- );
304
- for (contract.operations, 0..) |op, index| {
305
- const staged_module = op.module["src/".len..];
306
- try w.print("import {{ {s} as serviceOp{d} }} from \"./{s}\";\n", .{ op.@"export", index, staged_module });
307
- }
308
- for (contract.types.records) |record| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ record.name, record.origin });
309
- for (contract.types.enums) |enum_type| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ enum_type.name, enum_type.origin });
310
- for (contract.types.unions) |union_type| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ union_type.name, union_type.origin });
311
- const fingerprint = contractFingerprint(contract);
312
- try w.print("\nconst PROTOCOL_VERSION = {d};\nconst CONTRACT_FINGERPRINT = new Uint8Array([", .{contract.protocol_version});
313
- for (fingerprint, 0..) |byte, index| {
314
- if (index > 0) try w.writeAll(", ");
315
- try w.print("{d}", .{byte});
316
- }
317
- try w.writeAll("]);\n");
318
- try w.writeAll(
319
- \\const MAX_FRAME_BYTES = 16 * 1024 * 1024;
320
- \\function readExact(length: number, eofAllowed: boolean): Uint8Array | null {
321
- \\ const bytes = new Uint8Array(length);
322
- \\ let offset = 0;
323
- \\ while (offset < length) {
324
- \\ const read = fs.readSync(0, bytes, offset, length - offset);
325
- \\ if (read === 0) {
326
- \\ if (offset === 0 && eofAllowed) return null;
327
- \\ throw { kind: "service_protocol", message: "truncated frame" };
328
- \\ }
329
- \\ offset += read;
330
- \\ }
331
- \\ return bytes;
332
- \\}
333
- \\
334
- \\function u16(bytes: Uint8Array, at: number): number {
335
- \\ return bytes[at] | (bytes[at + 1] << 8);
336
- \\}
337
- \\function u32(bytes: Uint8Array, at: number): number {
338
- \\ return (bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16) | (bytes[at + 3] << 24)) >>> 0;
339
- \\}
340
- \\function putU32(bytes: Uint8Array, at: number, value: number): void {
341
- \\ bytes[at] = value & 255;
342
- \\ bytes[at + 1] = (value >>> 8) & 255;
343
- \\ bytes[at + 2] = (value >>> 16) & 255;
344
- \\ bytes[at + 3] = (value >>> 24) & 255;
345
- \\}
346
- \\function writeHello(): void {
347
- \\ const frame = new Uint8Array(5 + CONTRACT_FINGERPRINT.length);
348
- \\ putU32(frame, 0, 1 + CONTRACT_FINGERPRINT.length);
349
- \\ frame[4] = PROTOCOL_VERSION;
350
- \\ frame.set(CONTRACT_FINGERPRINT, 5);
351
- \\ process.stdout.write(frame);
352
- \\}
353
- \\function writeResult(requestId: number, status: number, payload: Uint8Array): void {
354
- \\ const frame = new Uint8Array(9 + payload.length);
355
- \\ putU32(frame, 0, 5 + payload.length);
356
- \\ putU32(frame, 4, requestId);
357
- \\ frame[8] = status;
358
- \\ frame.set(payload, 9);
359
- \\ process.stdout.write(frame);
360
- \\}
361
- \\class __NativeSdkCancelled extends Error {
362
- \\ constructor() { super("service operation was cancelled"); this.name = "cancelled"; }
363
- \\}
364
- \\function cancellation(path: string) {
365
- \\ const cancelled = (): boolean => path.length > 0 && fs.existsSync(path);
366
- \\ return {
367
- \\ cancelled,
368
- \\ throwIfCancelled: (): void => { if (cancelled()) throw new __NativeSdkCancelled(); },
369
- \\ };
370
- \\}
371
- \\
372
- );
373
- try emitHostCodecs(w, contract);
374
- for (contract.operations, 0..) |op, index| if (op.stream) |stream| {
375
- try w.print("\nfunction __nativeSdkEmit{d}(requestId: number, chunk: ", .{index});
376
- try emitTsType(w, stream.chunk);
377
- try w.writeAll("): void { writeResult(requestId, 2, ");
378
- if (stream.chunk.kind == .bytes) try w.writeAll("chunk") else try emitEncodeExpr(w, stream.chunk, "chunk");
379
- try w.writeAll("); }\n");
380
- };
381
- try w.writeAll(
382
- \\function dispatch(index: number, payload: Uint8Array, requestId: number, cancelPath: string): Uint8Array {
383
- \\ switch (index) {
384
- \\
385
- );
386
- try emitDispatchCases(w, arena, contract, .child_process);
387
- try w.writeAll(
388
- \\ default: throw new Error("service operation index is not in the contract");
389
- \\ }
390
- \\}
391
- \\
392
- \\writeHello();
393
- \\while (true) {
394
- \\ const header = readExact(4, true);
395
- \\ if (header === null) break;
396
- \\ const length = u32(header, 0);
397
- \\ if (length < 8 || length > MAX_FRAME_BYTES) throw { kind: "service_protocol", message: "invalid request frame length" };
398
- \\ const body = readExact(length, false) as Uint8Array;
399
- \\ const requestId = u32(body, 0);
400
- \\ const operation = u16(body, 4);
401
- \\ const cancelPathLength = u16(body, 6);
402
- \\ if (8 + cancelPathLength > body.length) throw { kind: "service_protocol", message: "truncated cancellation path" };
403
- \\ const cancelPath = new TextDecoder().decode(body.subarray(8, 8 + cancelPathLength));
404
- \\ const payload = body.subarray(8 + cancelPathLength);
405
- \\ try {
406
- \\ const result = dispatch(operation, payload, requestId, cancelPath);
407
- \\ cancellation(cancelPath).throwIfCancelled();
408
- \\ writeResult(requestId, 0, result);
409
- \\ } catch (error) {
410
- \\ if (error instanceof Error) {
411
- \\ writeResult(requestId, 1, new TextEncoder().encode(JSON.stringify({ kind: error.name, message: error.message })));
412
- \\ } else {
413
- \\ writeResult(requestId, 1, new TextEncoder().encode(JSON.stringify({ kind: "service_error", message: "service operation threw" })));
414
- \\ }
415
- \\ }
416
- \\}
417
- \\
418
- );
419
- return out.toOwnedSlice();
12
+ return generate(arena, contract, "host");
420
13
  }
421
-
422
- /// The dispatch switch shared by both entry projections. The child host
423
- /// main's streaming emits carry the frame's request id; the in-process
424
- /// facade's emits write to the request's chunk-relay file instead, so its
425
- /// emit helpers take the chunk alone.
426
- const DispatchLane = enum { child_process, in_process };
427
-
428
- fn emitDispatchCases(w: *std.Io.Writer, arena: std.mem.Allocator, contract: service.Contract, lane: DispatchLane) !void {
429
- for (contract.operations, 0..) |op, index| {
430
- try w.print(" case {d}: {{\n", .{index});
431
- const emit_callback = switch (lane) {
432
- .child_process => try std.fmt.allocPrint(arena, "(chunk) => __nativeSdkEmit{d}(requestId, chunk)", .{index}),
433
- .in_process => try std.fmt.allocPrint(arena, "(chunk) => __nativeSdkEmit{d}(chunk)", .{index}),
434
- };
435
- defer arena.free(emit_callback);
436
- if (op.request.kind == .none) {
437
- try w.writeAll(" if (payload.length !== 0) throw new Error(\"unexpected service request payload\");\n");
438
- try w.print(" return ", .{});
439
- const call = if (op.stream != null and op.cancellable)
440
- try std.fmt.allocPrint(arena, "serviceOp{d}({s}, cancellation(cancelPath))", .{ index, emit_callback })
441
- else if (op.stream != null)
442
- try std.fmt.allocPrint(arena, "serviceOp{d}({s})", .{ index, emit_callback })
443
- else if (op.cancellable)
444
- try std.fmt.allocPrint(arena, "serviceOp{d}(cancellation(cancelPath))", .{index})
445
- else
446
- try std.fmt.allocPrint(arena, "serviceOp{d}()", .{index});
447
- defer arena.free(call);
448
- if (op.result.kind == .bytes) try w.writeAll(call) else try emitEncodeExpr(w, op.result, call);
449
- try w.writeAll(";\n");
450
- } else {
451
- if (op.request.kind == .bytes) {
452
- try w.writeAll(" const request = payload;\n return ");
453
- } else {
454
- try w.writeAll(" const reader = new __NativeSdkReader(payload);\n const request = ");
455
- try emitDecodeExpr(w, op.request, "reader");
456
- try w.writeAll(";\n reader.finish();\n return ");
457
- }
458
- const call = if (op.stream != null and op.cancellable)
459
- try std.fmt.allocPrint(arena, "serviceOp{d}(request, {s}, cancellation(cancelPath))", .{ index, emit_callback })
460
- else if (op.stream != null)
461
- try std.fmt.allocPrint(arena, "serviceOp{d}(request, {s})", .{ index, emit_callback })
462
- else if (op.cancellable)
463
- try std.fmt.allocPrint(arena, "serviceOp{d}(request, cancellation(cancelPath))", .{index})
464
- else
465
- try std.fmt.allocPrint(arena, "serviceOp{d}(request)", .{index});
466
- defer arena.free(call);
467
- if (op.result.kind == .bytes) try w.writeAll(call) else try emitEncodeExpr(w, op.result, call);
468
- try w.writeAll(";\n");
469
- }
470
- try w.writeAll(" }\n");
471
- }
14
+ pub fn emitRegistry(arena: std.mem.Allocator, contract: service.Contract) ![]const u8 {
15
+ return generate(arena, contract, "registry");
16
+ }
17
+ pub fn emitClient(arena: std.mem.Allocator, contract: service.Contract) ![]const u8 {
18
+ return generate(arena, contract, "client");
472
19
  }
473
-
474
- /// The in-process facade: the library-mode entry the service archive
475
- /// compiles from. One exported dispatch covers every operation — the pool
476
- /// passes the contract's operation index, the encoded request, the
477
- /// cooperative-cancellation marker path, and (streaming operations only)
478
- /// the chunk-relay file path. The return is a status byte (0 ok, 1 err)
479
- /// followed by the encoded result or the error JSON. Interim stream
480
- /// chunks ride the relay file as [len u32 LE][bytes] frames while the
481
- /// operation runs — the same liveness the child's stdout frames give.
482
20
  pub fn emitInprocMain(arena: std.mem.Allocator, contract: service.Contract) ![]const u8 {
483
- var out = std.Io.Writer.Allocating.init(arena);
484
- const w = &out.writer;
485
- try w.writeAll(
486
- \\// Generated by corewire from services.contract.json. Do not edit.
487
- \\import * as fs from "node:fs";
488
- \\
489
- );
490
- for (contract.operations, 0..) |op, index| {
491
- const staged_module = op.module["src/".len..];
492
- try w.print("import {{ {s} as serviceOp{d} }} from \"./{s}\";\n", .{ op.@"export", index, staged_module });
493
- }
494
- for (contract.types.records) |record| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ record.name, record.origin });
495
- for (contract.types.enums) |enum_type| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ enum_type.name, enum_type.origin });
496
- for (contract.types.unions) |union_type| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ union_type.name, union_type.origin });
497
- const fingerprint = contractFingerprint(contract);
498
- try w.writeAll("\nconst CONTRACT_FINGERPRINT = new Uint8Array([");
499
- for (fingerprint, 0..) |byte, index| {
500
- if (index > 0) try w.writeAll(", ");
501
- try w.print("{d}", .{byte});
502
- }
503
- try w.writeAll("]);\n");
504
- try w.writeAll(
505
- \\export function contractFingerprint(): Uint8Array {
506
- \\ return CONTRACT_FINGERPRINT;
507
- \\}
508
- \\class __NativeSdkCancelled extends Error {
509
- \\ constructor() { super("service operation was cancelled"); this.name = "cancelled"; }
510
- \\}
511
- \\function cancellation(path: string) {
512
- \\ const cancelled = (): boolean => path.length > 0 && fs.existsSync(path);
513
- \\ return {
514
- \\ cancelled,
515
- \\ throwIfCancelled: (): void => { if (cancelled()) throw new __NativeSdkCancelled(); },
516
- \\ };
517
- \\}
518
- \\let __nativeSdkStreamFd = -1;
519
- \\function __nativeSdkEmitFrame(bytes: Uint8Array): void {
520
- \\ if (__nativeSdkStreamFd < 0) return;
521
- \\ const frame = new Uint8Array(4 + bytes.length);
522
- \\ frame[0] = bytes.length & 255;
523
- \\ frame[1] = (bytes.length >>> 8) & 255;
524
- \\ frame[2] = (bytes.length >>> 16) & 255;
525
- \\ frame[3] = (bytes.length >>> 24) & 255;
526
- \\ frame.set(bytes, 4);
527
- \\ fs.writeSync(__nativeSdkStreamFd, frame, 0, frame.length);
528
- \\}
529
- \\
530
- );
531
- try emitHostCodecs(w, contract);
532
- for (contract.operations, 0..) |op, index| if (op.stream) |stream| {
533
- try w.print("\nfunction __nativeSdkEmit{d}(chunk: ", .{index});
534
- try emitTsType(w, stream.chunk);
535
- try w.writeAll("): void { __nativeSdkEmitFrame(");
536
- if (stream.chunk.kind == .bytes) try w.writeAll("chunk") else try emitEncodeExpr(w, stream.chunk, "chunk");
537
- try w.writeAll("); }\n");
538
- };
539
- try w.writeAll(
540
- \\function dispatchOperation(index: number, payload: Uint8Array, cancelPath: string): Uint8Array {
541
- \\ switch (index) {
542
- \\
543
- );
544
- try emitDispatchCases(w, arena, contract, .in_process);
545
- try w.writeAll(
546
- \\ default: throw new Error("service operation index is not in the contract");
547
- \\ }
548
- \\}
549
- \\
550
- \\export function dispatch(operation: number, payload: Uint8Array, cancelPathBytes: Uint8Array, streamPathBytes: Uint8Array): Uint8Array {
551
- \\ const cancelPath = new TextDecoder().decode(cancelPathBytes);
552
- \\ const streamPath = new TextDecoder().decode(streamPathBytes);
553
- \\ __nativeSdkStreamFd = streamPath.length > 0 ? fs.openSync(streamPath, "a") : -1;
554
- \\ try {
555
- \\ const result = dispatchOperation(operation, payload, cancelPath);
556
- \\ cancellation(cancelPath).throwIfCancelled();
557
- \\ const out = new Uint8Array(1 + result.length);
558
- \\ out[0] = 0;
559
- \\ out.set(result, 1);
560
- \\ return out;
561
- \\ } catch (error) {
562
- \\ let kind = "service_error";
563
- \\ let message = "service operation threw";
564
- \\ if (error instanceof Error) {
565
- \\ kind = error.name;
566
- \\ message = error.message;
567
- \\ }
568
- \\ const body = new TextEncoder().encode(JSON.stringify({ kind, message }));
569
- \\ const out = new Uint8Array(1 + body.length);
570
- \\ out[0] = 1;
571
- \\ out.set(body, 1);
572
- \\ return out;
573
- \\ } finally {
574
- \\ if (__nativeSdkStreamFd >= 0) {
575
- \\ fs.closeSync(__nativeSdkStreamFd);
576
- \\ __nativeSdkStreamFd = -1;
577
- \\ }
578
- \\ }
579
- \\}
580
- \\
581
- );
582
- return out.toOwnedSlice();
21
+ return generate(arena, contract, "inproc");
583
22
  }
584
-
585
- /// The library-mode compiler profile for the in-process service archive.
586
- /// Contract-independent by design: one fixed entry, the fixed service
587
- /// symbol family, runtime localization (so the archive links beside the
588
- /// compiled core's archive), and thread-instanced state (one independent
589
- /// instance per pool thread). No sidecar section — the archive is built
590
- /// and linked by one build graph, and the facade's fingerprint export is
591
- /// the pairing check. No determinism fences — services run with ambient
592
- /// authority by contract.
593
23
  pub fn emitInprocProfile(arena: std.mem.Allocator, optimization: ?[]const u8) ![]const u8 {
594
- var out = std.Io.Writer.Allocating.init(arena);
595
- const w = &out.writer;
596
- try w.writeAll(
597
- \\{
598
- \\ "profile_format": 1,
599
- \\ "name": "native-sdk-services",
600
- \\ "entry": "service_inproc_main.ts",
601
- \\ "emission": "llvm",
602
- );
603
- if (optimization) |value| {
604
- try w.print(
605
- \\ "optimization": "{s}",
606
- , .{value});
607
- try w.writeByte('\n');
608
- }
609
- try w.print(
610
- \\ "abi": {{
611
- \\ "prefix": "{s}",
612
- \\ "init_symbol": "{s}init",
613
- \\ "sink_register_symbol": "{s}set_panic_sink",
614
- \\ "collect_symbol": "{s}collect",
615
- \\ "result_reset_symbol": null,
616
- \\ "localize_runtime": true,
617
- \\ "instance_per_thread": true
618
- \\ }},
619
- \\ "exports": [
620
- \\ {{ "export": "dispatch", "symbol": "{s}dispatch", "params": ["u32", "bytes", "bytes", "bytes"], "returns": "bytes" }},
621
- \\ {{ "export": "contractFingerprint", "symbol": "{s}contract_fingerprint", "params": [], "returns": "bytes" }}
622
- \\ ]
623
- \\}}
624
- \\
625
- , .{ inproc_symbol_prefix, inproc_symbol_prefix, inproc_symbol_prefix, inproc_symbol_prefix, inproc_symbol_prefix, inproc_symbol_prefix });
626
- return out.toOwnedSlice();
627
- }
628
-
629
- pub fn emitRegistry(arena: std.mem.Allocator, contract: service.Contract) ![]const u8 {
630
- var out = std.Io.Writer.Allocating.init(arena);
631
- const w = &out.writer;
632
- const fingerprint = contractFingerprint(contract);
633
- try w.print(
634
- \\//! Generated by corewire from services.contract.json. Do not edit.
635
- \\pub const enabled = true;
636
- \\pub const protocol_version: u8 = {d};
637
- \\pub const compiler_version = "{s}";
638
- \\pub const inproc_symbol_prefix = "{s}";
639
- \\
640
- , .{ contract.protocol_version, contract.compiler_version, inproc_symbol_prefix });
641
- try w.writeAll("pub const contract_fingerprint = [_]u8{");
642
- for (fingerprint, 0..) |byte, index| {
643
- if (index > 0) try w.writeAll(", ");
644
- try w.print("{d}", .{byte});
645
- }
646
- try w.writeAll(
647
- \\};
648
- \\pub const Operation = struct { name: []const u8, index: u16, deadline_ms: ?u32, cancellable: bool, streaming: bool, in_flight: u8 };
649
- \\pub const operations = [_]Operation{
650
- \\
651
- );
652
- for (contract.operations, 0..) |op, index| {
653
- const streaming = op.stream != null;
654
- const in_flight: i64 = if (op.stream) |stream| stream.in_flight else 0;
655
- if (op.deadline_ms) |deadline| {
656
- try w.print(" .{{ .name = \"{s}\", .index = {d}, .deadline_ms = {d}, .cancellable = {}, .streaming = {}, .in_flight = {d} }},\n", .{ op.name, index, deadline, op.cancellable, streaming, in_flight });
657
- } else {
658
- try w.print(" .{{ .name = \"{s}\", .index = {d}, .deadline_ms = null, .cancellable = {}, .streaming = {}, .in_flight = {d} }},\n", .{ op.name, index, op.cancellable, streaming, in_flight });
659
- }
660
- }
661
- try w.writeAll(
662
- \\};
663
- \\pub fn indexOf(name: []const u8) ?u16 {
664
- \\ for (operations) |op| if (@import("std").mem.eql(u8, op.name, name)) return op.index;
665
- \\ return null;
666
- \\}
667
- \\pub fn operationAt(index: u16) ?Operation {
668
- \\ for (operations) |op| if (op.index == index) return op;
669
- \\ return null;
670
- \\}
671
- \\pub fn isStreaming(index: u16) bool {
672
- \\ return if (operationAt(index)) |op| op.streaming else false;
673
- \\}
674
- );
675
- try w.writeAll("pub fn resultIsBytes(index: u16) bool {\n return switch (index) {\n");
676
- for (contract.operations, 0..) |op, index| if (op.result.kind == .bytes) {
677
- try w.print(" {d} => true,\n", .{index});
678
- };
679
- try w.writeAll(" else => false,\n };\n}\n");
680
- try w.writeAll(
681
- \\pub fn resultDecoder(comptime core: type) *const fn (operation: u16, tag: u8, bytes: []const u8) core.Msg {
682
- \\ return struct {
683
- \\ fn decode(operation: u16, tag: u8, bytes: []const u8) core.Msg {
684
- \\ if (operationAt(operation) == null) @panic("typed service result names an operation outside services.contract.json");
685
- \\ inline for (@typeInfo(core.Msg).@"union".fields, 0..) |arm, index| {
686
- \\ if (tag == index) {
687
- \\ if (comptime arm.type == void) @panic("typed service result targets a void Msg arm");
688
- \\ if (resultIsBytes(operation)) {
689
- \\ if (comptime arm.type == []const u8) return @unionInit(core.Msg, arm.name, core.rt.copyServiceBytes(bytes));
690
- \\ @panic("typed byte service result targets a non-bytes Msg arm");
691
- \\ }
692
- \\ return @unionInit(core.Msg, arm.name, core.rt.decodeExact(arm.type, bytes));
693
- \\ }
694
- \\ }
695
- \\ @panic("typed service result names a Msg tag outside the core contract");
696
- \\ }
697
- \\ }.decode;
698
- \\}
699
- \\
700
- );
701
- return out.toOwnedSlice();
702
- }
703
-
704
- fn emitTsType(w: *std.Io.Writer, ref: service.TypeRef) !void {
705
- switch (ref.kind) {
706
- .none => try w.writeAll("void"),
707
- .bool => try w.writeAll("boolean"),
708
- .f64, .i64 => try w.writeAll("number"),
709
- .bytes => try w.writeAll("Uint8Array"),
710
- .optional => {
711
- try emitTsType(w, ref.inner.?.*);
712
- try w.writeAll(" | null");
713
- },
714
- .slice => {
715
- try w.writeAll("readonly ");
716
- const parenthesize = ref.elem.?.kind == .optional or ref.elem.?.kind == .slice;
717
- if (parenthesize) try w.writeByte('(');
718
- try emitTsType(w, ref.elem.?.*);
719
- if (parenthesize) try w.writeByte(')');
720
- try w.writeAll("[]");
721
- },
722
- .record, .@"enum", .@"union" => try w.writeAll(ref.name.?),
723
- }
724
- }
725
-
726
- pub fn emitClient(arena: std.mem.Allocator, contract: service.Contract) ![]const u8 {
727
- var out = std.Io.Writer.Allocating.init(arena);
728
- const w = &out.writer;
729
- try w.writeAll(
730
- \\// Generated by corewire from services.contract.json. Do not edit.
731
- \\import {
732
- \\ Cmd,
733
- \\ serviceBoolBytes as writeBool,
734
- \\ serviceBytes as writeBytes,
735
- \\ serviceConcat as concat,
736
- \\ serviceEnumBytes as writeEnum,
737
- \\ serviceF64Bytes as writeF64,
738
- \\ serviceI64Bytes as writeI64,
739
- \\ serviceOptionalBytes as writeOptional,
740
- \\ serviceSliceBytes as writeSlice,
741
- \\ serviceUnionBytes as writeUnion,
742
- \\ type ServiceRoute,
743
- \\ type ServiceStreamRoute,
744
- \\} from "@native-sdk/core";
745
- \\import type { Msg } from "./core.ts";
746
- \\
747
- );
748
- for (contract.types.records) |record| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ record.name, record.origin });
749
- for (contract.types.enums) |enum_type| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ enum_type.name, enum_type.origin });
750
- for (contract.types.unions) |union_type| try w.print("import type {{ {s} }} from \"./{s}\";\n", .{ union_type.name, union_type.origin });
751
-
752
- for (contract.types.records) |record| {
753
- try w.print("\nfunction __nativeSdkEncode{s}(value: {s}): Uint8Array {{ return concat([", .{ record.name, record.name });
754
- for (record.fields, 0..) |field, index| {
755
- if (index > 0) try w.writeAll(", ");
756
- const field_value = try std.fmt.allocPrint(arena, "value.{s}", .{field.name});
757
- try emitEncodeExpr(w, field.type, field_value);
758
- }
759
- try w.writeAll("]); }\n");
760
- }
761
- for (contract.types.enums) |enum_type| {
762
- try w.print("\nfunction __nativeSdkEncode{s}(value: {s}): Uint8Array {{ return writeEnum(", .{ enum_type.name, enum_type.name });
763
- for (enum_type.members, 0..) |member, index| {
764
- try w.writeAll("value === ");
765
- try jsString(w, member);
766
- try w.print(" ? {d} : (", .{index});
767
- }
768
- try w.writeAll("0");
769
- for (enum_type.members) |_| try w.writeByte(')');
770
- try w.writeAll("); }\n");
771
- }
772
- for (contract.types.unions) |union_type| {
773
- try w.print("\nfunction __nativeSdkEncode{s}(value: {s}): Uint8Array {{ switch (value.kind) {{\n", .{ union_type.name, union_type.name });
774
- for (union_type.arms, 0..) |arm, index| {
775
- try w.writeAll(" case ");
776
- try jsString(w, arm.name);
777
- try w.print(": return concat([writeUnion({d})", .{index});
778
- for (arm.fields) |field| {
779
- try w.writeAll(", ");
780
- const field_value = try std.fmt.allocPrint(arena, "value.{s}", .{field.name});
781
- try emitEncodeExpr(w, field.type, field_value);
782
- }
783
- try w.writeAll("]);\n");
784
- }
785
- try w.writeAll("} }\n");
786
- }
787
- for (contract.operations) |op| {
788
- try w.print("\nexport function {s}(", .{op.client});
789
- if (op.request.kind != .none) {
790
- try w.writeAll("request: ");
791
- try emitTsType(w, op.request);
792
- try w.writeAll(", ");
793
- }
794
- try w.writeAll(if (op.stream == null) "route: ServiceRoute<Msg, " else "route: ServiceStreamRoute<Msg, ");
795
- try emitTsType(w, op.result);
796
- try w.writeAll(">): Cmd<Msg> {\n return Cmd.");
797
- try w.writeAll(if (op.stream == null) "serviceRequest(" else "serviceStreamRequest(");
798
- try jsString(w, op.name);
799
- if (op.stream != null) try w.writeAll(", route.channelKey");
800
- try w.writeAll(", ");
801
- if (op.request.kind == .none) {
802
- try w.writeAll("new Uint8Array(0)");
803
- } else if (op.request.kind == .bytes) {
804
- try w.writeAll("request");
805
- } else {
806
- try emitEncodeExpr(w, op.request, "request");
807
- }
808
- try w.writeAll(", route");
809
- if (op.stream) |stream| try w.print(", {d}", .{stream.in_flight});
810
- try w.writeAll(");\n}\n");
811
- }
812
- return out.toOwnedSlice();
24
+ return projection.generate(arena, "{}", "profile", optimization orelse "");
813
25
  }
814
26
 
815
27
  test "service projection derives host dispatch and registry from one contract" {
@@ -873,6 +85,10 @@ test "service projection derives host dispatch and registry from one contract" {
873
85
  try std.testing.expect(std.mem.indexOf(u8, host, "PROTOCOL_VERSION = 3") != null);
874
86
  try std.testing.expect(std.mem.indexOf(u8, host, "CONTRACT_FINGERPRINT = new Uint8Array([") != null);
875
87
 
88
+ const host_hash = std.crypto.hash.sha2.Sha256.hash;
89
+ var before: [32]u8 = undefined;
90
+ host_hash(host, &before, .{});
91
+
876
92
  const inproc = try emitInprocMain(std.testing.allocator, contract);
877
93
  defer std.testing.allocator.free(inproc);
878
94
  try std.testing.expect(std.mem.indexOf(u8, inproc, "export function dispatch(operation: number, payload: Uint8Array, cancelPathBytes: Uint8Array, streamPathBytes: Uint8Array): Uint8Array") != null);
@@ -906,44 +122,9 @@ test "service projection derives host dispatch and registry from one contract" {
906
122
  defer std.testing.allocator.free(client);
907
123
  try std.testing.expect(std.mem.indexOf(u8, client, "request: readonly (Uint8Array | null)[]") != null);
908
124
  try std.testing.expect(std.mem.indexOf(u8, client, "ServiceRoute<Msg, readonly (Uint8Array | null)[]>") != null);
909
-
910
- const original_fingerprint = contractFingerprint(contract);
911
- // An implementation-only fingerprint input change must leave the ABI
912
- // digest alone: source/package/compiler facts rebuild only the service.
913
- const implementation_only_fingerprint = contractFingerprint(.{
914
- .format = contract.format,
915
- .protocol_version = contract.protocol_version,
916
- .compiler_version = "9.9.9",
917
- .deterministic = contract.deterministic,
918
- .packages = &.{.{ .name = "different-package", .version = "4.5.6", .content_hash = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }},
919
- .types = contract.types,
920
- .operations = &.{
921
- .{
922
- .name = operations[0].name,
923
- .client = "renamedInternalClient",
924
- .module = "src/services/moved.ts",
925
- .@"export" = "moved",
926
- .request = operations[0].request,
927
- .result = operations[0].result,
928
- .deadline_ms = operations[0].deadline_ms,
929
- .cancellable = operations[0].cancellable,
930
- .stream = operations[0].stream,
931
- .source_hash = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
932
- },
933
- operations[1],
934
- operations[2],
935
- },
936
- });
937
- try std.testing.expectEqualSlices(u8, &original_fingerprint, &implementation_only_fingerprint);
938
- const reordered_operations = [_]service.Operation{ operations[1], operations[0] };
939
- const reordered_fingerprint = contractFingerprint(.{
940
- .format = contract.format,
941
- .protocol_version = contract.protocol_version,
942
- .compiler_version = contract.compiler_version,
943
- .deterministic = contract.deterministic,
944
- .packages = contract.packages,
945
- .types = contract.types,
946
- .operations = &reordered_operations,
947
- });
948
- try std.testing.expect(!std.mem.eql(u8, &original_fingerprint, &reordered_fingerprint));
125
+ // The first result remains owned by its caller after four more init /
126
+ // collect cycles, including a different projection and crypto handles.
127
+ var after: [32]u8 = undefined;
128
+ host_hash(host, &after, .{});
129
+ try std.testing.expectEqualSlices(u8, &before, &after);
949
130
  }