The Mizan codegen substrate moves off JavaScript template-literal emission
onto a compiled Rust binary that consumes the same OpenAPI + x-mizan-* IR
the JS substrate consumed. Three structural wins fall out of one move:
1. Moat closes. The codegen logic (how `affects` becomes auto-invalidation,
how named contexts collapse onto bundled fetches, how the registry-to-
Provider mapping is shaped) ships compiled instead of as source bytes
in every consumer's node_modules.
2. Pattern F (lines.push append-walls) becomes structurally unauthorable.
The emit substrate is askama templates in templates/<target>/*.j2 —
actual target-language files with {{ ... }} substitution markers,
syntax-highlighted natively, type-checked against the render context
structs at compile time. The Rust emit modules build typed render
contexts and call .render(); no string-builder surface exists.
3. OpenAPI `default`-bearing fields now emit as non-optional in TS / Python
/ Rust — the server always populates them, so consumer code reads them
without nullable checks. Surfaced by Blazr's typecheck on regeneration.
Layout:
frontends/mizan-rust/ — Rust port of @mizan/base; #[cfg(feature="pyo3")]
exposes PyMizanClient for the Python target.
protocol/mizan-codegen/ — codegen binary source + askama templates.
protocol/mizan-generate/ — npm-package shim. bin/launcher.mjs dispatches
to the platform-appropriate prebuilt binary.
Old generator/ JS tree deleted.
tests/rust/ — wire-parity drivers. drive_kernel exercises
raw client.call() / fetch_context(); drive_emitted
exercises the typed crate the codegen emits.
tests/afi/afi_codegen_app.py — codegen entrypoint module (imports + registers).
backends/mizan-fastapi/.../schema.py — adds outputNullable so the Rust
codegen can wrap T | None responses in Option<T>.
Verification:
- 20 mizan-codegen tests green (IR deserialization, byte-equivalent
parity vs JS baseline for stage1/rust/python/react/vue/svelte,
structural test for channels).
- tests/rust/run_wire_parity.py — 12/12 probes green via the Rust binary
driving the FastAPI fixture end-to-end.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
97 lines
3.5 KiB
TypeScript
97 lines
3.5 KiB
TypeScript
// AUTO-GENERATED by mizan — do not edit
|
|
|
|
import { ref, computed, onMounted, onUnmounted, onServerPrefetch, type ComputedRef } from 'vue'
|
|
import { registerContext, type ContextState } from '@mizan/base'
|
|
|
|
import { fetchUserContext, type UserContextData, type UserContextParams, callUpdateProfile, callEcho, callWhoami, callFindUser, callRenameUser } from '../index'
|
|
|
|
export function useUserContext(params: UserContextParams) {
|
|
const state = ref<ContextState<UserContextData>>({ data: null, status: 'idle', error: null })
|
|
let handle: ReturnType<typeof registerContext> | null = null
|
|
|
|
onMounted(() => {
|
|
handle = registerContext('user', params, () => fetchUserContext(params))
|
|
handle.subscribe(() => { state.value = handle!.getState() })
|
|
handle.refetch()
|
|
})
|
|
|
|
onServerPrefetch(async () => {
|
|
handle = registerContext('user', params, () => fetchUserContext(params))
|
|
await handle.refetch()
|
|
state.value = handle.getState()
|
|
})
|
|
|
|
onUnmounted(() => { handle?.unregister() })
|
|
|
|
return {
|
|
state,
|
|
userProfile: computed(() => state.value.data?.user_profile ?? null) as ComputedRef<userProfileOutput | null>,
|
|
userOrders: computed(() => state.value.data?.user_orders ?? null) as ComputedRef<userOrdersOutput | null>,
|
|
loading: computed(() => state.value.status === 'loading'),
|
|
error: computed(() => state.value.error),
|
|
}
|
|
}
|
|
|
|
export function useUpdateProfile() {
|
|
const isPending = ref(false)
|
|
const error = ref<Error | null>(null)
|
|
async function mutate(args: Parameters<typeof callUpdateProfile>[0]) {
|
|
isPending.value = true; error.value = null
|
|
try { return await callUpdateProfile(args) }
|
|
catch (e) { error.value = e as Error; throw e }
|
|
finally { isPending.value = false }
|
|
}
|
|
return { mutate, isPending, error }
|
|
}
|
|
|
|
export function useEcho() {
|
|
const isPending = ref(false)
|
|
const error = ref<Error | null>(null)
|
|
async function mutate(args: Parameters<typeof callEcho>[0]) {
|
|
isPending.value = true; error.value = null
|
|
try { return await callEcho(args) }
|
|
catch (e) { error.value = e as Error; throw e }
|
|
finally { isPending.value = false }
|
|
}
|
|
return { mutate, isPending, error }
|
|
}
|
|
|
|
export function useWhoami() {
|
|
const isPending = ref(false)
|
|
const error = ref<Error | null>(null)
|
|
async function mutate() {
|
|
isPending.value = true; error.value = null
|
|
try { return await callWhoami() }
|
|
catch (e) { error.value = e as Error; throw e }
|
|
finally { isPending.value = false }
|
|
}
|
|
return { mutate, isPending, error }
|
|
}
|
|
|
|
export function useFindUser() {
|
|
const isPending = ref(false)
|
|
const error = ref<Error | null>(null)
|
|
async function mutate(args: Parameters<typeof callFindUser>[0]) {
|
|
isPending.value = true; error.value = null
|
|
try { return await callFindUser(args) }
|
|
catch (e) { error.value = e as Error; throw e }
|
|
finally { isPending.value = false }
|
|
}
|
|
return { mutate, isPending, error }
|
|
}
|
|
|
|
export function useRenameUser() {
|
|
const isPending = ref(false)
|
|
const error = ref<Error | null>(null)
|
|
async function mutate(args: Parameters<typeof callRenameUser>[0]) {
|
|
isPending.value = true; error.value = null
|
|
try { return await callRenameUser(args) }
|
|
catch (e) { error.value = e as Error; throw e }
|
|
finally { isPending.value = false }
|
|
}
|
|
return { mutate, isPending, error }
|
|
}
|
|
|
|
export type { ContextState } from '@mizan/base'
|
|
export { configure, initSession, MizanError } from '@mizan/base'
|