Mizan IR: cut over to KDL, delete OpenAPI envelope
Replaces the transitional OpenAPI 3.0 + `x-mizan-*` extensions
substrate with the canonical Mizan IR as KDL, per docs/AFI_ARCHITECTURE.md:
"KDL is the contract; everything else (REST envelopes, OpenAPI
documents, framework idioms) is sediment around it."
End-to-end cutover. No transitional path left on main.
Forward direction:
cores/mizan-python/src/mizan_core/ir.py
build_ir() walks mizan_core.registry, introspects Pydantic
models directly (no JSON-Schema indirection), and emits the
Mizan IR document. The KDL grammar is locked in this file's
module docstring.
Backends emit KDL:
backends/mizan-fastapi/src/mizan_fastapi/ir.py
`python -m mizan_fastapi.ir <module>` — CLI entry point.
backends/mizan-django/.../management/commands/export_mizan_ir.py
`manage.py export_mizan_ir` — Django mgmt command.
Codegen consumes KDL:
protocol/mizan-codegen/Cargo.toml: + kdl = "6"
protocol/mizan-codegen/src/ir.rs: NamedType { Struct/List/Enum/Alias }
+ TypeShape { Primitive/Ref/List/Optional/Enum/Union } sum types,
replacing the JsonSchema sprawl. KDL parser walks the
`kdl::KdlDocument` tree into typed Rust structs.
protocol/mizan-codegen/src/fetch.rs: subprocess command switches
to the new IR-export entry points.
All emit modules (stage1 / react / python / rust / vue / svelte /
channels) port their type-walkers from JsonSchema to the new
sum types — case analysis collapses substantially.
Substrate-honesty wins beyond the moat closure:
- `int | bool` multi-arm unions land as `TypeShape::Union` (was
silently coerced to "string" before).
- `<CamelName>Output = list[T]` returns emit as named alias
types instead of struct-shaped wrappers, so consumer code
`.map()` works directly on the type.
- Pydantic field defaults flow through to `default` properties
in KDL, then back to non-optional shape in every target.
Deleted:
- backends/mizan-fastapi/src/mizan_fastapi/{cli,schema}.py
- backends/mizan-django/.../export_mizan_schema.py
- openapi-bearing half of mizan/export/__init__.py (edge
manifest generator preserved — separate concern).
- tests/afi/schema_normalizer.py
- tests/fixtures/{afi_schema.json, channels_schema.json}
- tests/fixtures/js_* baseline directories.
Verification:
- 20 mizan-codegen unit tests green (IR deserialization,
byte-equivalence parity across stage1/rust/python/react/vue/svelte
against fresh KDL-driven baselines, channels structural).
- tests/rust/run_wire_parity.py: 12/12 probes green driving
the binary end-to-end through KDL.
- Blazr studio-ui typechecks against the regenerated React client.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
4
protocol/mizan-codegen/tests/fixtures/baselines/python/__init__.py
vendored
Normal file
4
protocol/mizan-codegen/tests/fixtures/baselines/python/__init__.py
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
from .client import MizanClient # noqa: F401
|
||||
from .types import * # noqa: F401, F403
|
||||
67
protocol/mizan-codegen/tests/fixtures/baselines/python/client.py
vendored
Normal file
67
protocol/mizan-codegen/tests/fixtures/baselines/python/client.py
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
# AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
# Built from frontends/mizan-rust with `maturin develop --features pyo3`.
|
||||
from mizan_rust import PyMizanClient, PyContextSubscription
|
||||
|
||||
from .types import * # noqa: F401, F403
|
||||
from .types import BaseModel # re-import for the synthesized ContextData classes
|
||||
|
||||
|
||||
class MizanClient:
|
||||
"""Typed Python facade over the PyO3 mizan-rust kernel."""
|
||||
|
||||
def __init__(self, base_url: str, *, session: bool = False,
|
||||
csrf_cookie_name: str = "csrftoken",
|
||||
csrf_header_name: str = "X-CSRFToken") -> None:
|
||||
self._inner = PyMizanClient(
|
||||
base_url,
|
||||
session=session,
|
||||
csrf_cookie_name=csrf_cookie_name,
|
||||
csrf_header_name=csrf_header_name,
|
||||
)
|
||||
|
||||
def fetch_user_context(self, user_id: int) -> "UserContextData":
|
||||
raw = self._inner.fetch_context("user", {"user_id": user_id})
|
||||
return UserContextData(**raw)
|
||||
def subscribe_user_context(self, user_id: int,
|
||||
callback: Callable[[dict[str, Any]], None]) -> PyContextSubscription:
|
||||
return self._inner.subscribe_context("user", {"user_id": user_id}, callback)
|
||||
|
||||
def call_echo(self, args: EchoInput) -> EchoOutput:
|
||||
raw = self._inner.call("echo", args.model_dump())
|
||||
return EchoOutput(**raw)
|
||||
|
||||
def call_whoami(self) -> WhoamiOutput:
|
||||
raw = self._inner.call("whoami", {})
|
||||
return WhoamiOutput(**raw)
|
||||
|
||||
def call_update_profile(self, args: UpdateProfileInput) -> UpdateProfileOutput:
|
||||
raw = self._inner.call("update_profile", args.model_dump())
|
||||
return UpdateProfileOutput(**raw)
|
||||
|
||||
def call_find_user(self, args: FindUserInput) -> FindUserOutput | None:
|
||||
raw = self._inner.call("find_user", args.model_dump())
|
||||
return FindUserOutput(**raw) if raw is not None else None
|
||||
|
||||
def call_rename_user(self, args: RenameUserInput) -> RenameUserOutput:
|
||||
raw = self._inner.call("rename_user", args.model_dump())
|
||||
return RenameUserOutput(**raw)
|
||||
|
||||
def invalidate(self, context: str) -> None:
|
||||
self._inner.invalidate(context)
|
||||
|
||||
def invalidate_scoped(self, context: str, params: dict[str, Any]) -> None:
|
||||
self._inner.invalidate_scoped(context, params)
|
||||
|
||||
|
||||
# ── Context data shapes (per-context bundle) ──────────────────────────────
|
||||
|
||||
class UserContextData(BaseModel):
|
||||
"""Bundled return of fetch_user_context."""
|
||||
user_profile: UserProfileOutput
|
||||
user_orders: UserOrdersOutput
|
||||
56
protocol/mizan-codegen/tests/fixtures/baselines/python/types.py
vendored
Normal file
56
protocol/mizan-codegen/tests/fixtures/baselines/python/types.py
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
# AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
class OrderOutput(BaseModel):
|
||||
id: int
|
||||
user_id: int
|
||||
total: int
|
||||
|
||||
class EchoInput(BaseModel):
|
||||
text: str
|
||||
|
||||
class EchoOutput(BaseModel):
|
||||
message: str
|
||||
|
||||
class FindUserInput(BaseModel):
|
||||
user_id: int
|
||||
|
||||
class FindUserOutput(BaseModel):
|
||||
user_id: int
|
||||
name: str
|
||||
|
||||
class RenameUserInput(BaseModel):
|
||||
user_id: int
|
||||
name: str
|
||||
|
||||
class RenameUserOutput(BaseModel):
|
||||
user_id: int
|
||||
name: str
|
||||
|
||||
class UpdateProfileInput(BaseModel):
|
||||
user_id: int
|
||||
name: str
|
||||
|
||||
class UpdateProfileOutput(BaseModel):
|
||||
ok: bool
|
||||
|
||||
class UserOrdersInput(BaseModel):
|
||||
user_id: int
|
||||
|
||||
UserOrdersOutput = list[OrderOutput]
|
||||
|
||||
class UserProfileInput(BaseModel):
|
||||
user_id: int
|
||||
|
||||
class UserProfileOutput(BaseModel):
|
||||
user_id: int
|
||||
name: str
|
||||
|
||||
class WhoamiOutput(BaseModel):
|
||||
email: str
|
||||
authenticated: bool
|
||||
18
protocol/mizan-codegen/tests/fixtures/baselines/react/contexts/user.ts
vendored
Normal file
18
protocol/mizan-codegen/tests/fixtures/baselines/react/contexts/user.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanFetch } from '@mizan/base'
|
||||
|
||||
import type { userProfileOutput, userOrdersOutput } from '../types'
|
||||
|
||||
export interface UserContextData {
|
||||
user_profile: userProfileOutput
|
||||
user_orders: userOrdersOutput
|
||||
}
|
||||
|
||||
export interface UserContextParams {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export function fetchUserContext(params: UserContextParams): Promise<UserContextData> {
|
||||
return mizanFetch('user', params)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/echo.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/echo.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { echoInput, echoOutput } from '../types'
|
||||
|
||||
export function callEcho(args: echoInput): Promise<echoOutput> {
|
||||
return mizanCall('echo', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/findUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/findUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { findUserInput, findUserOutput } from '../types'
|
||||
|
||||
export function callFindUser(args: findUserInput): Promise<findUserOutput> {
|
||||
return mizanCall('find_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/renameUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/renameUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { renameUserInput, renameUserOutput } from '../types'
|
||||
|
||||
export function callRenameUser(args: renameUserInput): Promise<renameUserOutput> {
|
||||
return mizanCall('rename_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/whoami.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/react/functions/whoami.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { whoamiOutput } from '../types'
|
||||
|
||||
export function callWhoami(): Promise<whoamiOutput> {
|
||||
return mizanCall('whoami', {})
|
||||
}
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/react/index.ts
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/react/index.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export * from './types'
|
||||
|
||||
export { fetchUserContext, type UserContextData, type UserContextParams } from './contexts/user'
|
||||
|
||||
export { callEcho } from './functions/echo'
|
||||
export { callWhoami } from './functions/whoami'
|
||||
export { callUpdateProfile } from './mutations/updateProfile'
|
||||
export { callFindUser } from './functions/findUser'
|
||||
export { callRenameUser } from './functions/renameUser'
|
||||
|
||||
// Stage 2 framework adapter
|
||||
export * from './react'
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/react/mutations/updateProfile.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/react/mutations/updateProfile.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { updateProfileInput, updateProfileOutput } from '../types'
|
||||
|
||||
export function callUpdateProfile(args: updateProfileInput): Promise<updateProfileOutput> {
|
||||
return mizanCall('update_profile', args)
|
||||
}
|
||||
157
protocol/mizan-codegen/tests/fixtures/baselines/react/react.tsx
vendored
Normal file
157
protocol/mizan-codegen/tests/fixtures/baselines/react/react.tsx
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
'use client'
|
||||
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
type ReactNode,
|
||||
} from 'react'
|
||||
import {
|
||||
configure,
|
||||
initSession,
|
||||
mizanCall,
|
||||
mizanFetch,
|
||||
MizanError,
|
||||
registerContext,
|
||||
type ContextState,
|
||||
} from '@mizan/base'
|
||||
|
||||
import { fetchUserContext, type UserContextData, type UserContextParams, callUpdateProfile, callEcho, callWhoami, callFindUser, callRenameUser, type userProfileOutput, type userOrdersOutput } from './index'
|
||||
|
||||
// Internal — runs inside a Provider, registers with the kernel exactly once.
|
||||
function useContextSubscription<T>(
|
||||
name: string,
|
||||
params: Record<string, any>,
|
||||
fetchFn: () => Promise<T>,
|
||||
initialData?: T,
|
||||
): ContextState<T> {
|
||||
const ref = useRef<ReturnType<typeof registerContext> | null>(null)
|
||||
if (!ref.current) {
|
||||
ref.current = registerContext(name, params, fetchFn, initialData)
|
||||
}
|
||||
const handle = ref.current
|
||||
|
||||
useEffect(() => {
|
||||
if (handle.getState().status === 'idle') handle.refetch()
|
||||
return () => handle.unregister()
|
||||
}, [handle])
|
||||
|
||||
return useSyncExternalStore(handle.subscribe, handle.getState, handle.getState)
|
||||
}
|
||||
|
||||
// Internal — wraps an imperative call() with isPending / error state.
|
||||
interface MutationHook<TArgs, TResult> {
|
||||
mutate: (args: TArgs) => Promise<TResult>
|
||||
isPending: boolean
|
||||
error: Error | null
|
||||
}
|
||||
|
||||
function useMutation<TArgs, TResult>(
|
||||
callFn: (args: TArgs) => Promise<TResult>,
|
||||
): MutationHook<TArgs, TResult> {
|
||||
const [isPending, setIsPending] = useState(false)
|
||||
const [error, setError] = useState<Error | null>(null)
|
||||
|
||||
const mutate = useCallback(async (args: TArgs) => {
|
||||
setIsPending(true)
|
||||
setError(null)
|
||||
try {
|
||||
return await callFn(args)
|
||||
} catch (e) {
|
||||
setError(e as Error)
|
||||
throw e
|
||||
} finally {
|
||||
setIsPending(false)
|
||||
}
|
||||
}, [callFn])
|
||||
|
||||
return { mutate, isPending, error }
|
||||
}
|
||||
|
||||
// ── User Context ──
|
||||
|
||||
const UserCtx = createContext<ContextState<UserContextData> | null>(null)
|
||||
|
||||
export function UserContext({ children, ...params }: UserContextParams & { children: ReactNode }) {
|
||||
const state = useContextSubscription('user', params, () => fetchUserContext(params))
|
||||
return <UserCtx.Provider value={state}>{children}</UserCtx.Provider>
|
||||
}
|
||||
|
||||
export function useUserContext(): ContextState<UserContextData> {
|
||||
const ctx = useContext(UserCtx)
|
||||
if (!ctx) throw new Error('useUserContext requires <UserContext>')
|
||||
return ctx
|
||||
}
|
||||
|
||||
export function useUserProfile(): userProfileOutput | null {
|
||||
return useUserContext().data?.user_profile ?? null
|
||||
}
|
||||
|
||||
export function useUserOrders(): userOrdersOutput | null {
|
||||
return useUserContext().data?.user_orders ?? null
|
||||
}
|
||||
|
||||
export function useUpdateProfile() {
|
||||
return useMutation<Parameters<typeof callUpdateProfile>[0], Awaited<ReturnType<typeof callUpdateProfile>>>(callUpdateProfile)
|
||||
}
|
||||
|
||||
export function useEcho() {
|
||||
return useMutation<Parameters<typeof callEcho>[0], Awaited<ReturnType<typeof callEcho>>>(callEcho)
|
||||
}
|
||||
|
||||
export function useWhoami() {
|
||||
return useMutation<void, Awaited<ReturnType<typeof callWhoami>>>(() => callWhoami() as any)
|
||||
}
|
||||
|
||||
export function useFindUser() {
|
||||
return useMutation<Parameters<typeof callFindUser>[0], Awaited<ReturnType<typeof callFindUser>>>(callFindUser)
|
||||
}
|
||||
|
||||
export function useRenameUser() {
|
||||
return useMutation<Parameters<typeof callRenameUser>[0], Awaited<ReturnType<typeof callRenameUser>>>(callRenameUser)
|
||||
}
|
||||
|
||||
// ── MizanContext root provider ──
|
||||
|
||||
export interface MizanContextProps {
|
||||
/** Base URL for protocol endpoints. Defaults to "/api/mizan". */
|
||||
baseUrl?: string
|
||||
/** Set to `false` for backends without a `/session/` endpoint (e.g. FastAPI). */
|
||||
session?: boolean
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
/**
|
||||
* Root provider — calls configure() once and mounts the global context (if defined).
|
||||
* Must wrap any component using Mizan-generated hooks.
|
||||
*/
|
||||
export function MizanContext({ baseUrl, session, children }: MizanContextProps) {
|
||||
const configured = useRef(false)
|
||||
if (!configured.current) {
|
||||
const opts: Parameters<typeof configure>[0] = {}
|
||||
if (baseUrl !== undefined) opts.baseUrl = baseUrl
|
||||
if (session !== undefined) opts.session = session
|
||||
if (Object.keys(opts).length > 0) configure(opts)
|
||||
configured.current = true
|
||||
}
|
||||
return <>{children}</>
|
||||
}
|
||||
|
||||
// ── Imperative escape hatch ──
|
||||
|
||||
/**
|
||||
* Returns the imperative kernel API. For test harnesses or rare cases where
|
||||
* a typed generated hook does not fit. Most app code should use the typed hooks.
|
||||
*/
|
||||
export function useMizan() {
|
||||
return { call: mizanCall, fetch: mizanFetch }
|
||||
}
|
||||
|
||||
export type { ContextState } from '@mizan/base'
|
||||
export { configure, initSession, MizanError } from '@mizan/base'
|
||||
64
protocol/mizan-codegen/tests/fixtures/baselines/react/types.ts
vendored
Normal file
64
protocol/mizan-codegen/tests/fixtures/baselines/react/types.ts
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export interface OrderOutput {
|
||||
id: number
|
||||
user_id: number
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface echoInput {
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface echoOutput {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface findUserInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface findUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileOutput {
|
||||
ok: boolean
|
||||
}
|
||||
|
||||
export interface userOrdersInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export type userOrdersOutput = OrderOutput[]
|
||||
|
||||
export interface userProfileInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface userProfileOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface whoamiOutput {
|
||||
email: string
|
||||
authenticated: boolean
|
||||
}
|
||||
|
||||
10
protocol/mizan-codegen/tests/fixtures/baselines/rust/Cargo.toml
vendored
Normal file
10
protocol/mizan-codegen/tests/fixtures/baselines/rust/Cargo.toml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "fixture_client"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
mizan-rust = { path = "../../../frontends/mizan-rust" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tokio = { version = "1", features = ["rt", "macros"] }
|
||||
3
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/contexts/mod.rs
vendored
Normal file
3
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/contexts/mod.rs
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
pub mod user;
|
||||
29
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/contexts/user.rs
vendored
Normal file
29
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/contexts/user.rs
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use mizan_rust::{MizanClient, MizanError};
|
||||
|
||||
use crate::types::{UserProfileOutput, UserOrdersOutput};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UserContextData {
|
||||
pub user_profile: UserProfileOutput,
|
||||
pub user_orders: UserOrdersOutput,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UserContextParams {
|
||||
pub user_id: i64,
|
||||
}
|
||||
|
||||
pub async fn fetch_user_context(
|
||||
client: &MizanClient,
|
||||
params: &UserContextParams,
|
||||
) -> Result<UserContextData, MizanError> {
|
||||
let params_value = serde_json::to_value(params).unwrap_or(Value::Object(Default::default()));
|
||||
let raw = client.fetch_context("user", ¶ms_value).await?;
|
||||
serde_json::from_value(raw)
|
||||
.map_err(|e| MizanError::transport(format!("decode user context: {e}")))
|
||||
}
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/echo.rs
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/echo.rs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use mizan_rust::{MizanClient, MizanError};
|
||||
|
||||
use crate::types::{EchoOutput, EchoInput};
|
||||
|
||||
pub async fn call_echo(client: &MizanClient, args: &EchoInput) -> Result<EchoOutput, MizanError> {
|
||||
let args_value = serde_json::to_value(args).unwrap_or(Value::Object(Default::default()));
|
||||
let raw = client.call("echo", args_value).await?;
|
||||
serde_json::from_value(raw)
|
||||
.map_err(|e| MizanError::transport(format!("decode echo result: {e}")))
|
||||
}
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/find_user.rs
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/find_user.rs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use mizan_rust::{MizanClient, MizanError};
|
||||
|
||||
use crate::types::{FindUserOutput, FindUserInput};
|
||||
|
||||
pub async fn call_find_user(client: &MizanClient, args: &FindUserInput) -> Result<Option<FindUserOutput>, MizanError> {
|
||||
let args_value = serde_json::to_value(args).unwrap_or(Value::Object(Default::default()));
|
||||
let raw = client.call("find_user", args_value).await?;
|
||||
serde_json::from_value(raw)
|
||||
.map_err(|e| MizanError::transport(format!("decode find_user result: {e}")))
|
||||
}
|
||||
6
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/mod.rs
vendored
Normal file
6
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/mod.rs
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
pub mod echo;
|
||||
pub mod find_user;
|
||||
pub mod rename_user;
|
||||
pub mod whoami;
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/rename_user.rs
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/rename_user.rs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use mizan_rust::{MizanClient, MizanError};
|
||||
|
||||
use crate::types::{RenameUserOutput, RenameUserInput};
|
||||
|
||||
pub async fn call_rename_user(client: &MizanClient, args: &RenameUserInput) -> Result<RenameUserOutput, MizanError> {
|
||||
let args_value = serde_json::to_value(args).unwrap_or(Value::Object(Default::default()));
|
||||
let raw = client.call("rename_user", args_value).await?;
|
||||
serde_json::from_value(raw)
|
||||
.map_err(|e| MizanError::transport(format!("decode rename_user result: {e}")))
|
||||
}
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/whoami.rs
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/functions/whoami.rs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use mizan_rust::{MizanClient, MizanError};
|
||||
|
||||
use crate::types::{WhoamiOutput};
|
||||
|
||||
pub async fn call_whoami(client: &MizanClient) -> Result<WhoamiOutput, MizanError> {
|
||||
let args_value = Value::Object(Default::default());
|
||||
let raw = client.call("whoami", args_value).await?;
|
||||
serde_json::from_value(raw)
|
||||
.map_err(|e| MizanError::transport(format!("decode whoami result: {e}")))
|
||||
}
|
||||
8
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/lib.rs
vendored
Normal file
8
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/lib.rs
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
pub mod types;
|
||||
pub mod contexts;
|
||||
pub mod mutations;
|
||||
pub mod functions;
|
||||
|
||||
pub use mizan_rust::{MizanClient, MizanConfig, MizanError};
|
||||
3
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/mutations/mod.rs
vendored
Normal file
3
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/mutations/mod.rs
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
pub mod update_profile;
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/mutations/update_profile.rs
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/mutations/update_profile.rs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use mizan_rust::{MizanClient, MizanError};
|
||||
|
||||
use crate::types::{UpdateProfileOutput, UpdateProfileInput};
|
||||
|
||||
pub async fn call_update_profile(client: &MizanClient, args: &UpdateProfileInput) -> Result<UpdateProfileOutput, MizanError> {
|
||||
let args_value = serde_json::to_value(args).unwrap_or(Value::Object(Default::default()));
|
||||
let raw = client.call("update_profile", args_value).await?;
|
||||
serde_json::from_value(raw)
|
||||
.map_err(|e| MizanError::transport(format!("decode update_profile result: {e}")))
|
||||
}
|
||||
81
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/types.rs
vendored
Normal file
81
protocol/mizan-codegen/tests/fixtures/baselines/rust/src/types.rs
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct OrderOutput {
|
||||
pub id: i64,
|
||||
pub user_id: i64,
|
||||
pub total: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct EchoInput {
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct EchoOutput {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FindUserInput {
|
||||
pub user_id: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FindUserOutput {
|
||||
pub user_id: i64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct RenameUserInput {
|
||||
pub user_id: i64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct RenameUserOutput {
|
||||
pub user_id: i64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UpdateProfileInput {
|
||||
pub user_id: i64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UpdateProfileOutput {
|
||||
pub ok: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UserOrdersInput {
|
||||
pub user_id: i64,
|
||||
}
|
||||
|
||||
pub type UserOrdersOutput = Vec<OrderOutput>;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UserProfileInput {
|
||||
pub user_id: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UserProfileOutput {
|
||||
pub user_id: i64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WhoamiOutput {
|
||||
pub email: String,
|
||||
pub authenticated: bool,
|
||||
}
|
||||
|
||||
18
protocol/mizan-codegen/tests/fixtures/baselines/stage1/contexts/user.ts
vendored
Normal file
18
protocol/mizan-codegen/tests/fixtures/baselines/stage1/contexts/user.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanFetch } from '@mizan/base'
|
||||
|
||||
import type { userProfileOutput, userOrdersOutput } from '../types'
|
||||
|
||||
export interface UserContextData {
|
||||
user_profile: userProfileOutput
|
||||
user_orders: userOrdersOutput
|
||||
}
|
||||
|
||||
export interface UserContextParams {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export function fetchUserContext(params: UserContextParams): Promise<UserContextData> {
|
||||
return mizanFetch('user', params)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/echo.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/echo.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { echoInput, echoOutput } from '../types'
|
||||
|
||||
export function callEcho(args: echoInput): Promise<echoOutput> {
|
||||
return mizanCall('echo', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/findUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/findUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { findUserInput, findUserOutput } from '../types'
|
||||
|
||||
export function callFindUser(args: findUserInput): Promise<findUserOutput> {
|
||||
return mizanCall('find_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/renameUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/renameUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { renameUserInput, renameUserOutput } from '../types'
|
||||
|
||||
export function callRenameUser(args: renameUserInput): Promise<renameUserOutput> {
|
||||
return mizanCall('rename_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/whoami.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/functions/whoami.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { whoamiOutput } from '../types'
|
||||
|
||||
export function callWhoami(): Promise<whoamiOutput> {
|
||||
return mizanCall('whoami', {})
|
||||
}
|
||||
11
protocol/mizan-codegen/tests/fixtures/baselines/stage1/index.ts
vendored
Normal file
11
protocol/mizan-codegen/tests/fixtures/baselines/stage1/index.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export * from './types'
|
||||
|
||||
export { fetchUserContext, type UserContextData, type UserContextParams } from './contexts/user'
|
||||
|
||||
export { callEcho } from './functions/echo'
|
||||
export { callWhoami } from './functions/whoami'
|
||||
export { callUpdateProfile } from './mutations/updateProfile'
|
||||
export { callFindUser } from './functions/findUser'
|
||||
export { callRenameUser } from './functions/renameUser'
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/mutations/updateProfile.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/stage1/mutations/updateProfile.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { updateProfileInput, updateProfileOutput } from '../types'
|
||||
|
||||
export function callUpdateProfile(args: updateProfileInput): Promise<updateProfileOutput> {
|
||||
return mizanCall('update_profile', args)
|
||||
}
|
||||
64
protocol/mizan-codegen/tests/fixtures/baselines/stage1/types.ts
vendored
Normal file
64
protocol/mizan-codegen/tests/fixtures/baselines/stage1/types.ts
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export interface OrderOutput {
|
||||
id: number
|
||||
user_id: number
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface echoInput {
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface echoOutput {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface findUserInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface findUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileOutput {
|
||||
ok: boolean
|
||||
}
|
||||
|
||||
export interface userOrdersInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export type userOrdersOutput = OrderOutput[]
|
||||
|
||||
export interface userProfileInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface userProfileOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface whoamiOutput {
|
||||
email: string
|
||||
authenticated: boolean
|
||||
}
|
||||
|
||||
18
protocol/mizan-codegen/tests/fixtures/baselines/svelte/contexts/user.ts
vendored
Normal file
18
protocol/mizan-codegen/tests/fixtures/baselines/svelte/contexts/user.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanFetch } from '@mizan/base'
|
||||
|
||||
import type { userProfileOutput, userOrdersOutput } from '../types'
|
||||
|
||||
export interface UserContextData {
|
||||
user_profile: userProfileOutput
|
||||
user_orders: userOrdersOutput
|
||||
}
|
||||
|
||||
export interface UserContextParams {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export function fetchUserContext(params: UserContextParams): Promise<UserContextData> {
|
||||
return mizanFetch('user', params)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/echo.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/echo.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { echoInput, echoOutput } from '../types'
|
||||
|
||||
export function callEcho(args: echoInput): Promise<echoOutput> {
|
||||
return mizanCall('echo', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/findUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/findUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { findUserInput, findUserOutput } from '../types'
|
||||
|
||||
export function callFindUser(args: findUserInput): Promise<findUserOutput> {
|
||||
return mizanCall('find_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/renameUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/renameUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { renameUserInput, renameUserOutput } from '../types'
|
||||
|
||||
export function callRenameUser(args: renameUserInput): Promise<renameUserOutput> {
|
||||
return mizanCall('rename_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/whoami.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/functions/whoami.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { whoamiOutput } from '../types'
|
||||
|
||||
export function callWhoami(): Promise<whoamiOutput> {
|
||||
return mizanCall('whoami', {})
|
||||
}
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/svelte/index.ts
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/svelte/index.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export * from './types'
|
||||
|
||||
export { fetchUserContext, type UserContextData, type UserContextParams } from './contexts/user'
|
||||
|
||||
export { callEcho } from './functions/echo'
|
||||
export { callWhoami } from './functions/whoami'
|
||||
export { callUpdateProfile } from './mutations/updateProfile'
|
||||
export { callFindUser } from './functions/findUser'
|
||||
export { callRenameUser } from './functions/renameUser'
|
||||
|
||||
// Stage 2 framework adapter
|
||||
export * from './svelte'
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/mutations/updateProfile.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/svelte/mutations/updateProfile.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { updateProfileInput, updateProfileOutput } from '../types'
|
||||
|
||||
export function callUpdateProfile(args: updateProfileInput): Promise<updateProfileOutput> {
|
||||
return mizanCall('update_profile', args)
|
||||
}
|
||||
29
protocol/mizan-codegen/tests/fixtures/baselines/svelte/svelte.ts
vendored
Normal file
29
protocol/mizan-codegen/tests/fixtures/baselines/svelte/svelte.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { readable, type Readable } from 'svelte/store'
|
||||
import { registerContext, type ContextState } from '@mizan/base'
|
||||
|
||||
import { fetchUserContext, type UserContextData, type UserContextParams, callUpdateProfile, callEcho, callWhoami, callFindUser, callRenameUser } from '../index'
|
||||
|
||||
export function createUserContext(params: UserContextParams) {
|
||||
const store = readable<ContextState<UserContextData>>(
|
||||
{ data: null, status: 'idle', error: null },
|
||||
(set) => {
|
||||
const handle = registerContext('user', params, () => fetchUserContext(params))
|
||||
const unsub = handle.subscribe(() => set(handle.getState()))
|
||||
handle.refetch()
|
||||
return () => { unsub(); handle.unregister() }
|
||||
},
|
||||
)
|
||||
|
||||
return store
|
||||
}
|
||||
|
||||
export { callUpdateProfile } from '../index'
|
||||
export { callEcho } from '../index'
|
||||
export { callWhoami } from '../index'
|
||||
export { callFindUser } from '../index'
|
||||
export { callRenameUser } from '../index'
|
||||
|
||||
export type { ContextState } from '@mizan/base'
|
||||
export { configure, initSession, MizanError } from '@mizan/base'
|
||||
64
protocol/mizan-codegen/tests/fixtures/baselines/svelte/types.ts
vendored
Normal file
64
protocol/mizan-codegen/tests/fixtures/baselines/svelte/types.ts
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export interface OrderOutput {
|
||||
id: number
|
||||
user_id: number
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface echoInput {
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface echoOutput {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface findUserInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface findUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileOutput {
|
||||
ok: boolean
|
||||
}
|
||||
|
||||
export interface userOrdersInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export type userOrdersOutput = OrderOutput[]
|
||||
|
||||
export interface userProfileInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface userProfileOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface whoamiOutput {
|
||||
email: string
|
||||
authenticated: boolean
|
||||
}
|
||||
|
||||
18
protocol/mizan-codegen/tests/fixtures/baselines/vue/contexts/user.ts
vendored
Normal file
18
protocol/mizan-codegen/tests/fixtures/baselines/vue/contexts/user.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanFetch } from '@mizan/base'
|
||||
|
||||
import type { userProfileOutput, userOrdersOutput } from '../types'
|
||||
|
||||
export interface UserContextData {
|
||||
user_profile: userProfileOutput
|
||||
user_orders: userOrdersOutput
|
||||
}
|
||||
|
||||
export interface UserContextParams {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export function fetchUserContext(params: UserContextParams): Promise<UserContextData> {
|
||||
return mizanFetch('user', params)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/echo.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/echo.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { echoInput, echoOutput } from '../types'
|
||||
|
||||
export function callEcho(args: echoInput): Promise<echoOutput> {
|
||||
return mizanCall('echo', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/findUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/findUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { findUserInput, findUserOutput } from '../types'
|
||||
|
||||
export function callFindUser(args: findUserInput): Promise<findUserOutput> {
|
||||
return mizanCall('find_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/renameUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/renameUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { renameUserInput, renameUserOutput } from '../types'
|
||||
|
||||
export function callRenameUser(args: renameUserInput): Promise<renameUserOutput> {
|
||||
return mizanCall('rename_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/whoami.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/whoami.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { whoamiOutput } from '../types'
|
||||
|
||||
export function callWhoami(): Promise<whoamiOutput> {
|
||||
return mizanCall('whoami', {})
|
||||
}
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/vue/index.ts
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/vue/index.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export * from './types'
|
||||
|
||||
export { fetchUserContext, type UserContextData, type UserContextParams } from './contexts/user'
|
||||
|
||||
export { callEcho } from './functions/echo'
|
||||
export { callWhoami } from './functions/whoami'
|
||||
export { callUpdateProfile } from './mutations/updateProfile'
|
||||
export { callFindUser } from './functions/findUser'
|
||||
export { callRenameUser } from './functions/renameUser'
|
||||
|
||||
// Stage 2 framework adapter
|
||||
export * from './vue'
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/mutations/updateProfile.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/mutations/updateProfile.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { updateProfileInput, updateProfileOutput } from '../types'
|
||||
|
||||
export function callUpdateProfile(args: updateProfileInput): Promise<updateProfileOutput> {
|
||||
return mizanCall('update_profile', args)
|
||||
}
|
||||
64
protocol/mizan-codegen/tests/fixtures/baselines/vue/types.ts
vendored
Normal file
64
protocol/mizan-codegen/tests/fixtures/baselines/vue/types.ts
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export interface OrderOutput {
|
||||
id: number
|
||||
user_id: number
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface echoInput {
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface echoOutput {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface findUserInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface findUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileOutput {
|
||||
ok: boolean
|
||||
}
|
||||
|
||||
export interface userOrdersInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export type userOrdersOutput = OrderOutput[]
|
||||
|
||||
export interface userProfileInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface userProfileOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface whoamiOutput {
|
||||
email: string
|
||||
authenticated: boolean
|
||||
}
|
||||
|
||||
96
protocol/mizan-codegen/tests/fixtures/baselines/vue/vue.ts
vendored
Normal file
96
protocol/mizan-codegen/tests/fixtures/baselines/vue/vue.ts
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
// 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'
|
||||
Reference in New Issue
Block a user