actions/action_codegen.ts

Declarations
#

5 declarations

view source

create_banner
#

generate_phase_handlers
#

actions/action_codegen.ts view source

(spec: { method: string; initiator: "frontend" | "backend" | "both"; side_effects: true | null; input: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; output: ZodType<unknown, unknown, $ZodTypeInternals<...>>; description: string; kind: "request_response"; auth: "public" | ... 2 more ... | { ...; }; async: true; } | { ...; } | { ...; }, executor: "frontend" | "backend", imports: ImportBuilder): string

Generates the phase handlers for an action spec using the unified ActionEvent type with the new phase/step type parameters.

spec

type { method: string; initiator: "frontend" | "backend" | "both"; side_effects: true | null; input: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; output: ZodType<unknown, unknown, $ZodTypeInternals<...>>; description: string; kind: "request_response"; auth: "public" | ... 2 more ... | { ...; }; async: ...

executor

type "frontend" | "backend"

imports

returns

string

get_executor_phases
#

actions/action_codegen.ts view source

(spec: { method: string; initiator: "frontend" | "backend" | "both"; side_effects: true | null; input: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; output: ZodType<unknown, unknown, $ZodTypeInternals<...>>; description: string; kind: "request_response"; auth: "public" | ... 2 more ... | { ...; }; async: true; } | { ...; } | { ...; }, executor: "frontend" | "backend"): ("send_request" | ... 7 more ... | "execute")[]

Determines which phases an executor can handle based on the action spec.

spec

type { method: string; initiator: "frontend" | "backend" | "both"; side_effects: true | null; input: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; output: ZodType<unknown, unknown, $ZodTypeInternals<...>>; description: string; kind: "request_response"; auth: "public" | ... 2 more ... | { ...; }; async: ...

executor

type "frontend" | "backend"

returns

("send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute")[]

get_handler_return_type
#

actions/action_codegen.ts view source

(spec: { method: string; initiator: "frontend" | "backend" | "both"; side_effects: true | null; input: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; output: ZodType<unknown, unknown, $ZodTypeInternals<...>>; description: string; kind: "request_response"; auth: "public" | ... 2 more ... | { ...; }; async: true; } | { ...; } | { ...; }, phase: "send_request" | ... 7 more ... | "execute", imports: ImportBuilder, path_prefix: string): string

Gets the handler return type for a specific phase and spec. Also adds necessary imports to the ImportBuilder.

spec

type { method: string; initiator: "frontend" | "backend" | "both"; side_effects: true | null; input: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; output: ZodType<unknown, unknown, $ZodTypeInternals<...>>; description: string; kind: "request_response"; auth: "public" | ... 2 more ... | { ...; }; async: ...

phase

type "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute"

imports

path_prefix

type string

returns

string

ImportBuilder
#

actions/action_codegen.ts view source

Manages imports for generated code, building them on demand. Automatically optimizes type-only imports to use import type syntax.

Why this matters: - import type statements are completely removed during compilation - Mixed imports like import { type A, B } cannot be safely removed - This ensures optimal tree-shaking and smaller bundle sizes

examples

const imports = new ImportBuilder(); imports.add_types('./types.js', 'Foo', 'Bar'); imports.add('./utils.js', 'helper'); imports.add_type('./utils.js', 'HelperOptions'); imports.add('./action_specs.js', '* as specs'); // Generates: // import type {Foo, Bar} from './types.js'; // import {helper, type HelperOptions} from './utils.js'; // import * as specs from './action_specs.js';

imports

type Map<string, Map<string, ImportItem>>

add

Add a value import to be included in the generated code.

type (from: string, what: string): this

from

the module to import from

type string
what

what to import (value)

type string
returns this

add_type

Add a type import to be included in the generated code.

type (from: string, what: string): this

from

the module to import from

type string
what

what to import (type)

type string
returns this

add_many

Add multiple value imports from the same module.

type (from: string, ...items: string[]): this

from
type string
items
type string[]
returns this

add_types

Add multiple type imports from the same module.

type (from: string, ...items: string[]): this

from
type string
items
type string[]
returns this

build

Generate the import statements. If all imports from a module are types, uses import type syntax.

type (): string

returns string

has_imports

Check if the builder has any imports.

type (): boolean

returns boolean

preview

Preview what imports will be generated (useful for debugging).

type (): string[]

returns string[]

array of import statement strings

clear

Clear all imports.

type (): this

returns this