effx
API reference@effx/compilergenerate

term

API reference for @effx/compiler/generate/term

term.ts overview


Exports Grouped by Category


utils

MethodCall (interface)

One method-call suffix (.<name>(<args>)), e.g. .annotate(K, v) appended to a generated expression.

Signature

export interface MethodCall {
  readonly name: string
  readonly args: ReadonlyArray<Term>
}

NameOf (type alias)

Resolves a reference to its printed name (collision-free local plus static-member suffix). Pure.

Signature

type NameOf = (ref: RefLike) => string

ObjEntry (interface)

One key: value entry of an object literal. key is the exact key text (already quoted if it must be).

Signature

export interface ObjEntry {
  readonly key: string
  readonly value: Term
}

ObjLayout (type alias)

How an object literal prints. "inline" is the generator's { ${join} } template, which pads an empty object to { }; "compact" is the Arg printer's form, which collapses an empty object to {}; "block" writes one entry per line at two-space indent with a trailing comma (the endpoint options object).

Signature

type ObjLayout = "inline" | "compact" | "block"

RefLike (type alias)

A reference a term names; the term keeps the identity, the printer resolves it to an import local.

Signature

type RefLike = SchemaRef | SymbolRef

Term (type alias)

A generated TypeScript expression, structurally. Call.callee is itself a term, so higher-order calls (HttpApiSchema.status(200)(success)) and chains (SchemaAST.resolve(s.ast)?.httpApiStatus) are exact.

Signature

type Term =
  | { readonly _tag: "Lit"; readonly json: Schema.Json }
  | { readonly _tag: "Ref"; readonly ref: RefLike }
  | { readonly _tag: "Call"; readonly callee: Term; readonly args: ReadonlyArray<Term> }
  | { readonly _tag: "Chain"; readonly head: Term; readonly calls: ReadonlyArray<MethodCall> }
  | { readonly _tag: "Member"; readonly term: Term; readonly member: string }
  | { readonly _tag: "OptionalMember"; readonly term: Term; readonly member: string }
  | { readonly _tag: "Nullish"; readonly head: Term; readonly tail: ReadonlyArray<Term> }
  | { readonly _tag: "StrictEqual"; readonly left: Term; readonly right: Term }
  | {
      readonly _tag: "Cond"
      readonly test: Term
      readonly consequent: Term
      readonly alternate: Term
    }
  | { readonly _tag: "Paren"; readonly term: Term }
  | { readonly _tag: "Obj"; readonly entries: ReadonlyArray<ObjEntry>; readonly layout: ObjLayout }
  | { readonly _tag: "Arr"; readonly items: ReadonlyArray<Term> }

arr

Signature

declare const arr: (items: ReadonlyArray<Term>) => Term

call

Signature

declare const call: (callee: Term, args: ReadonlyArray<Term>) => Term

chain

Signature

declare const chain: (head: Term, calls: ReadonlyArray<MethodCall>) => Term

cond

Signature

declare const cond: (test: Term, consequent: Term, alternate: Term) => Term

lit

Signature

declare const lit: (json: Schema.Json) => Term

member

Signature

declare const member: (term: Term, name: string) => Term

methodCall

Signature

declare const methodCall: (name: string, args: ReadonlyArray<Term>) => MethodCall

nullish

Signature

declare const nullish: (head: Term, tail: ReadonlyArray<Term>) => Term

obj

Signature

declare const obj: (entries: ReadonlyArray<ObjEntry>, layout?: ObjLayout) => Term

optionalMember

Signature

declare const optionalMember: (term: Term, name: string) => Term

paren

Signature

declare const paren: (term: Term) => Term

printMethodCall

Prints a receiverless method-call suffix: .name(arg, …).

Signature

declare const printMethodCall: (names: NameOf, call_: MethodCall) => string

printTerm

Prints a term exactly as the generator wrote it; names resolves references and nothing else. Pure.

Signature

declare const printTerm: (names: NameOf, term: Term) => string

ref

Signature

declare const ref: (reference: RefLike) => Term

refKey

The import-binding key of a reference: one binding per module/export, independent of any member.

Signature

declare const refKey: (ref: RefLike) => string

strictEqual

Signature

declare const strictEqual: (left: Term, right: Term) => Term

On this page