44 isOpaqueRef ,
55 isShadowRef ,
66 type JSONSchema ,
7+ type JSONSchemaWritable ,
78 makeOpaqueRef ,
89 type Module ,
910 type Node ,
@@ -27,6 +28,7 @@ import {
2728 toJSONWithAliases ,
2829 traverseValue ,
2930} from "./utils.ts" ;
31+ import { SchemaWithoutCell } from "./schema-to-ts.ts" ;
3032import { z } from "zod" ;
3133import { zodToJsonSchema } from "zod-to-json-schema" ;
3234
@@ -71,6 +73,21 @@ export function recipe<T, R>(
7173 resultSchema : JSONSchema ,
7274 fn : ( input : OpaqueRef < Required < T > > ) => Opaque < R > ,
7375) : RecipeFactory < T , R > ;
76+ export function recipe < S extends JSONSchema > (
77+ argumentSchema : S ,
78+ fn : ( input : OpaqueRef < Required < SchemaWithoutCell < S > > > ) => any ,
79+ ) : RecipeFactory < SchemaWithoutCell < S > , ReturnType < typeof fn > > ;
80+ export function recipe < S extends JSONSchema , R > (
81+ argumentSchema : S ,
82+ fn : ( input : OpaqueRef < Required < SchemaWithoutCell < S > > > ) => Opaque < R > ,
83+ ) : RecipeFactory < SchemaWithoutCell < S > , R > ;
84+ export function recipe < S extends JSONSchema , RS extends JSONSchema > (
85+ argumentSchema : S ,
86+ resultSchema : RS ,
87+ fn : (
88+ input : OpaqueRef < Required < SchemaWithoutCell < S > > > ,
89+ ) => Opaque < SchemaWithoutCell < RS > > ,
90+ ) : RecipeFactory < SchemaWithoutCell < S > , SchemaWithoutCell < RS > > ;
7491export function recipe < T , R > (
7592 argumentSchema : string | JSONSchema | z . ZodTypeAny ,
7693 resultSchema :
@@ -246,15 +263,15 @@ function factoryFromRecipe<T, R>(
246263 if ( external ) setValueAtPath ( initial , paths . get ( cell ) ! , external ) ;
247264 } ) ;
248265
249- let argumentSchema : JSONSchema ;
266+ let argumentSchema : JSONSchemaWritable ;
250267
251268 if ( typeof argumentSchemaArg === "string" ) {
252269 // TODO(seefeld): initial is likely not needed anymore
253- // TODO(seefeld): But we need a new one for the result
270+ // TODO(seefeld): But we need a derived schema for the result
254271 argumentSchema = createJsonSchema ( defaults , { } ) ;
255272 argumentSchema . description = argumentSchemaArg ;
256273
257- delete argumentSchema . properties ?. [ UI ] ; // TODO(seefeld): This should be a schema for views
274+ delete ( argumentSchema . properties as any ) ?. [ UI ] ; // TODO(seefeld): This should be a schema for views
258275 if ( argumentSchema . properties ?. internal ?. properties ) {
259276 for (
260277 const key of Object . keys (
@@ -269,15 +286,15 @@ function factoryFromRecipe<T, R>(
269286 } else if ( argumentSchemaArg instanceof z . ZodType ) {
270287 argumentSchema = zodToJsonSchema ( argumentSchemaArg ) as JSONSchema ;
271288 } else {
272- argumentSchema = argumentSchemaArg as unknown as JSONSchema ;
289+ argumentSchema = argumentSchemaArg ;
273290 }
274291
275292 const resultSchema : JSONSchema = resultSchemaArg instanceof z . ZodType
276293 ? ( zodToJsonSchema ( resultSchemaArg ) as JSONSchema )
277294 : ( resultSchemaArg ?? ( { } as JSONSchema ) ) ;
278295
279296 const serializedNodes = Array . from ( nodes ) . map ( ( node ) => {
280- const module = toJSONWithAliases ( node . module , paths ) as Module ;
297+ const module = toJSONWithAliases ( node . module , paths ) as unknown as Module ;
281298 const inputs = toJSONWithAliases ( node . inputs , paths ) ! ;
282299 const outputs = toJSONWithAliases ( node . outputs , paths ) ! ;
283300 return { module, inputs, outputs } satisfies Node ;
0 commit comments