diff --git a/src/cli/codegen_templates/component_server.ts b/src/cli/codegen_templates/component_server.ts index b010575..49fcc0d 100644 --- a/src/cli/codegen_templates/component_server.ts +++ b/src/cli/codegen_templates/component_server.ts @@ -19,8 +19,8 @@ import { Value, jsonToConvex } from "../../values/value.js"; import { z } from "zod"; import { encodeDefinitionPath } from "../lib/components/definition/bundle.js"; -export function componentServerJS(isRoot: boolean): string { - let result = ` +export function componentServerJS(): string { + const result = ` ${header( "Generated utilities for implementing server-side Convex query and mutation functions.", )} @@ -33,7 +33,6 @@ export function componentServerJS(isRoot: boolean): string { internalMutationGeneric, internalQueryGeneric, componentsGeneric, - createComponentArg, } from "convex/server"; /** @@ -108,11 +107,6 @@ export function componentServerJS(isRoot: boolean): string { export const components = componentsGeneric(); `; - if (!isRoot) { - result += ` - export const componentArg = createComponentArg(); - `; - } return result; } @@ -265,11 +259,6 @@ export function componentServerStubDTS(isRoot: boolean): string { result += ` export declare const components: AnyComponents; `; - if (!isRoot) { - result += ` - export declare const componentArg: (ctx: GenericCtx, name: string) => any; - `; - } return result; } @@ -316,19 +305,6 @@ export async function componentServerDTS( result.push("};"); - const definitionType = analysis.definition.definitionType; - if (definitionType.type === "childComponent") { - result.push(`type ComponentArgs = {`); - for (const [name, { value: serializedValidator }] of definitionType.args) { - const validatorType = validatorToType(JSON.parse(serializedValidator)); - result.push(`${name}: ${validatorType},`); - } - result.push("};"); - result.push( - `export declare const componentArg: (ctx: GenericCtx, name: Name) => ComponentArgs[Name];`, - ); - } - return result.join("\n"); } diff --git a/src/cli/lib/codegen.ts b/src/cli/lib/codegen.ts index eb4d9cc..06e3def 100644 --- a/src/cli/lib/codegen.ts +++ b/src/cli/lib/codegen.ts @@ -392,7 +392,7 @@ async function doInitialComponentServerCodegen( await writeFormattedFile( ctx, tmpDir, - componentServerJS(isRoot), + componentServerJS(), "typescript", path.join(codegenDir, "server.js"), opts, diff --git a/src/server/components/index.ts b/src/server/components/index.ts index 0dbe1ab..e3c7842 100644 --- a/src/server/components/index.ts +++ b/src/server/components/index.ts @@ -1,18 +1,12 @@ -import { - Infer, - ObjectType, - PropertyValidators, - convexToJson, - jsonToConvex, -} from "../../values/index.js"; +import { PropertyValidators, convexToJson } from "../../values/index.js"; import { AnyFunctionReference, FunctionReference, FunctionType, } from "../api.js"; import { getFunctionAddress } from "../impl/actions_impl.js"; -import { performAsyncSyscall, performSyscall } from "../impl/syscall.js"; -import { DefaultFunctionArgs, EmptyObject } from "../registration.js"; +import { performAsyncSyscall } from "../impl/syscall.js"; +import { DefaultFunctionArgs } from "../registration.js"; import { AppDefinitionAnalysis, ComponentDefinitionAnalysis, @@ -73,35 +67,19 @@ export interface InitCtx {} * * @internal */ // eslint-disable-next-line @typescript-eslint/ban-types -export type ComponentDefinition< - Args extends PropertyValidators = EmptyObject, - Exports extends ComponentExports = any, -> = { +export type ComponentDefinition = { /** * Install a component with the given definition in this component definition. * - * Takes a component definition, an optional name, and the args it requires. + * Takes a component definition, and an optional name. * * For editor tooling this method expects a {@link ComponentDefinition} * but at runtime the object that is imported will be a {@link ImportedComponentDefinition} */ - install>( - definition: Definition, - options: { - name?: string; - // TODO we have to do the "arguments are optional if empty, otherwise required" - args?: ObjectType>; - }, - ): InstalledComponent; - - installWithInit>( + install>( definition: Definition, - options: { + options?: { name?: string; - onInit: ( - ctx: InitCtx, - args: ObjectType, - ) => ObjectType>; }, ): InstalledComponent; @@ -112,21 +90,13 @@ export type ComponentDefinition< */ mountHttp(pathPrefix: string, component: InstalledComponent): void; - // TODO this will be needed once components are responsible for building interfaces for themselves - /** - * @internal - */ - __args: Args; - /** * @internal */ __exports: Exports; }; -type ComponentDefinitionArgs> = - T["__args"]; -type ComponentDefinitionExports> = +type ComponentDefinitionExports> = T["__exports"]; /** @@ -144,11 +114,10 @@ export type AppDefinition = { * For editor tooling this method expects a {@link ComponentDefinition} * but at runtime the object that is imported will be a {@link ImportedComponentDefinition} */ - install>( + install>( definition: Definition, - options: { + options?: { name?: string; - args?: ObjectType>; }, ): InstalledComponent; @@ -186,7 +155,7 @@ type AppDefinitionData = CommonDefinitionData; /** * Used to refer to an already-installed component. */ -class InstalledComponent> { +class InstalledComponent> { /** * @internal */ @@ -236,36 +205,8 @@ function createExports(name: string, pathParts: string[]): any { function install>( this: CommonDefinitionData, definition: Definition, - options: { + options?: { name?: string; - args?: Infer>; - } = {}, -): InstalledComponent { - // At runtime an imported component will have this shape. - const importedComponentDefinition = - definition as unknown as ImportedComponentDefinition; - if (typeof importedComponentDefinition.componentDefinitionPath !== "string") { - throw new Error( - "Component definition does not have the required componentDefinitionPath property. This code only works in Convex runtime.", - ); - } - const name = - options.name || - importedComponentDefinition.componentDefinitionPath.split("/").pop()!; - this._childComponents.push([ - name, - importedComponentDefinition, - options.args ?? {}, - ]); - return new InstalledComponent(definition, name); -} - -function installWithInit>( - this: ComponentDefinitionData, - definition: Definition, - options: { - name?: string; - onInit: (ctx: InitCtx, args: any) => any; }, ): InstalledComponent { // At runtime an imported component will have this shape. @@ -277,23 +218,12 @@ function installWithInit>( ); } const name = - options.name || + options?.name || importedComponentDefinition.componentDefinitionPath.split("/").pop()!; - this._childComponents.push([name, importedComponentDefinition, null]); - this._onInitCallbacks[name] = (s) => invokeOnInit(s, options.onInit); + this._childComponents.push([name, importedComponentDefinition, {}]); return new InstalledComponent(definition, name); } -function invokeOnInit( - argsStr: string, - onInit: (ctx: InitCtx, args: any) => any, -): string { - const argsJson = JSON.parse(argsStr); - const args = jsonToConvex(argsJson); - const result = onInit({}, args); - return JSON.stringify(convexToJson(result)); -} - function mount(this: CommonDefinitionData, exports: any) { function visit(definition: CommonDefinitionData, path: string[], value: any) { const valueReference = value[toReferencePath]; @@ -458,10 +388,7 @@ function exportComponentForAnalysis( } // This is what is actually contained in a ComponentDefinition. -type RuntimeComponentDefinition = Omit< - ComponentDefinition, - "__args" | "__exports" -> & +type RuntimeComponentDefinition = Omit, "__exports"> & ComponentDefinitionData & { export: () => ComponentDefinitionAnalysis; }; @@ -474,17 +401,13 @@ type RuntimeAppDefinition = AppDefinition & * @internal */ // eslint-disable-next-line @typescript-eslint/ban-types -export function defineComponent< - Args extends PropertyValidators = EmptyObject, - Exports extends ComponentExports = any, ->( +export function defineComponent( name: string, - options: { args?: Args } = {}, -): ComponentDefinition { +): ComponentDefinition { const ret: RuntimeComponentDefinition = { _isRoot: false, _name: name, - _args: options.args || {}, + _args: {}, _childComponents: [], _httpMounts: {}, _exportTree: {}, @@ -492,14 +415,13 @@ export function defineComponent< export: exportComponentForAnalysis, install, - installWithInit, mount, mountHttp, // pretend to conform to ComponentDefinition, which temporarily expects __args ...({} as { __args: any; __exports: any }), }; - return ret as any as ComponentDefinition; + return ret as any as ComponentDefinition; } /** @@ -564,19 +486,6 @@ function createChildComponents( return new Proxy({}, handler); } -/** - * - * @internal - */ -export function createComponentArg(): (ctx: any, name: string) => any { - return (ctx: any, name: string) => { - const result = performSyscall("1.0/componentArgument", { - name, - }); - return (jsonToConvex(result) as any).value; - }; -} - /** * @internal */ diff --git a/src/server/index.ts b/src/server/index.ts index 7b8693e..7a82db1 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -172,7 +172,6 @@ export { defineComponent, componentsGeneric, currentSystemUdfInComponent, - createComponentArg, createFunctionHandle, } from "./components/index.js"; /**