module

Noir::WaspExtractor

Wasp (https://wasp.sh) app declarations.

A Wasp app declares its HTTP surface in a config file rather than in route calls, in one of three syntaxes:

  • The Wasp DSL (main.wasp, any *.wasp file up to Wasp 0.23): api fooBar { fn: import { fooBar } from "@src/apis", httpRoute: (GET, "/foo/bar") }
  • The Wasp Spec (main.wasp.ts plus any *.wasp.ts, Wasp 0.24+, imported from @wasp.sh/spec): api("GET", "/foo/bar", fooBar, { auth: false })
  • The preview TS config (Wasp 0.15–0.23, imported from wasp-config): app.api("fooBar", { fn: { import: "fooBar", from: "@src/apis" }, httpRoute: { method: "GET", route: "/foo/bar" } })

All three describe the same declarations, so each parser fills the same Spec. Mapping declarations to server routes is left to the analyzer.

Constants

CONFIG_APP = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*new\s+App\s*\(/
CONFIG_IMPORT = /from\s*['"]wasp-config['"]/
CRUD_OPERATIONS = ["get", "getAll", "create", "update", "delete"] of ::String
DSL_DECL = /^[ \t]*(app|page|route|query|action|api|apiNamespace|crud|job|entity)\s+([A-Za-z_]\w*)\s*\{/m
DSL_HTTP_ROUTE = /\A\(\s*([A-Za-z]+)\s*,\s*"([^"]*)"\s*\)\z/
DSL_IMPORT = /\Aimport\s+(?:\{\s*([A-Za-z_$][\w$]*)(?:\s+as\s+[A-Za-z_$][\w$]*)?\s*\}|([A-Za-z_$][\w$]*))\s+from\s+"([^"]+)"\z/
IDENTIFIER = /\A[A-Za-z_$][\w$]*\z/
JS_RULES = TopLevelSplit::Rules::JS
SPEC_CALLEES = ["app", "api", "query", "action", "route", "crud", "page"] of ::String
SPEC_IMPORT = /import\s*(\{[^}]*\}|\*\s*as\s+[A-Za-z_$][\w$]*)\s*from\s*['"]@wasp\.sh\/spec['"]/
STRING_LIT = /\A(["'`])(.*)\1\z/m
TS_IMPORT = /import\s+(?:type\s+)?((?:[A-Za-z_$][\w$]*\s*,?\s*)?(?:\{[^}]*\})?)\s*from\s*['"]([^'"]+)['"]/
TS_TYPE_SPLIT = /\s*:\s*/

Instance methods

auth_methods(auth_value : String) : Array(String)

auth: { methods: { usernameAndPassword: {}, google: {} } } → the enabled method keys.

Source
bool_value(value : String | Nil) : Bool | Nil
Source
config_module?(content : String) : Bool
Source
handler(content : String, name : String) : Handler | Nil

Finds the exported function name (default for the default export) in a handler module: export const x = async (args, ctx) => {...}, export function x(req, res) {...}, export default async function.

Source
object_body(value : String) : String | Nil

The text between the braces of an object literal, or nil when the value is not one. Trailing TS as X / satisfies X are tolerated.

Source
object_entries(body : String) : Hash(String, String)

Top-level key: value entries of an object literal body (the text between its braces). Shorthand entries map a key to itself; spreads are skipped.

Source
object_literal_for(content : String, name : String) : String | Nil

The object literal bound to name (const name: Auth = { ... }), for an app({ auth: name }) declared in another file.

Source
operation_args(handler : Handler) : Array(String)

The fields an operation reads from its first argument (args): destructured in the signature (({ id, title }, context)), or read as args.x / const { x } = args in the body.

Source
parse_config(content : String) : Spec
Source
parse_dsl(content : String) : Spec
Source
parse_spec(content : String) : Spec
Source
spec_module?(content : String) : Bool
Source
string_value(value : String | Nil) : String | Nil
Source
strip_dsl(content : String) : String

Blanks DSL comments and {=json ... json=} / {=psl ... psl=} quoted blocks (keeping newlines, so line numbers hold). Strings are double-quoted only.

Source

Nested types