Skip to content
Hoody.com

The Code Validation endpoints let you statically inspect a piece of source code without executing it. They cover JavaScript syntax checks, TypeScript transpilation, dependency presence, magic-comment parsing, return-type conformance, and a combined full-script validation. Use these endpoints from editor tooling, CI pipelines, or pre-flight checks before persisting or executing user-authored scripts.

All endpoints are scoped to a container and accept a JSON body containing the code (or the type definition and value, for return-type checks). Each request returns a structured result describing what was detected; validation failures are reported in the 200 payload rather than as HTTP errors.

POST /api/v1/exec/validate/syntax

Checks whether the submitted source code parses as valid JavaScript.

This endpoint takes no parameters.

NameTypeRequiredDescription
codestringYesSource code to validate
{
"code": "const greet = (name) => `Hello, ${name}!`;\nconsole.log(greet('Hoody'));"
}
{
"valid": true,
"message": "JavaScript syntax is valid",
"codeLength": 76,
"normalized": false,
"transformations": []
}
import { HoodyClient } from 'hoody-sdk';
const client = new HoodyClient({ baseURL: 'https://{projectId}-{containerId}-exec-1.{server}.containers.hoody.com', token: process.env.HOODY_TOKEN });
await client.exec.validate.validateSyntax({ code: "const greet = (name) => `Hello, ${name}!`;\nconsole.log(greet('Hoody'));" });

POST /api/v1/exec/validate/typescript

Transpiles TypeScript to JavaScript and reports the result, including byte-length deltas and any normalization transformations applied to the input.

This endpoint takes no parameters.

NameTypeRequiredDescription
codestringYesTypeScript source code to validate
{
"code": "type Greeting = { name: string };\nconst greet = (g: Greeting): string => `Hello, ${g.name}!`;"
}
{
"valid": true,
"javascript": "const greet = (g) => `Hello, ${g.name}!`;\n",
"originalLength": 92,
"transpiledLength": 41,
"normalized": false,
"transformations": [],
"message": "TypeScript validation successful"
}
import { HoodyClient } from 'hoody-sdk';
const client = new HoodyClient({ baseURL: 'https://{projectId}-{containerId}-exec-1.{server}.containers.hoody.com', token: process.env.HOODY_TOKEN });
await client.exec.validate.validateTypeScript({ code: "type Greeting = { name: string };\nconst greet = (g: Greeting): string => `Hello, ${g.name}!`;" });

POST /api/v1/exec/validate/dependencies

Inspects the source code for imported or required modules and reports which ones are missing from the container’s runtime environment, along with a suggested install command.

This endpoint takes no parameters.

NameTypeRequiredDescription
codestringYesSource code to inspect for module dependencies
{
"code": "import lodash from 'lodash';\nimport { z } from 'zod';\n\nconst schema = z.object({ name: z.string() });\nconst result = lodash.camelCase(schema.parse({ name: 'Hello World' }).name);\nconsole.log(result);"
}
{
"totalModules": 2,
"allInstalled": false,
"missingCount": 1,
"missingModules": ["zod"],
"dependencies": [
{ "module": "lodash", "installed": true, "version": "4.17.21" },
{ "module": "zod", "installed": false, "version": null }
],
"message": "1 module(s) missing: zod",
"installCommand": "npm install zod"
}
import { HoodyClient } from 'hoody-sdk';
const client = new HoodyClient({ baseURL: 'https://{projectId}-{containerId}-exec-1.{server}.containers.hoody.com', token: process.env.HOODY_TOKEN });
await client.exec.validate.validateDependencies({ code: "import lodash from 'lodash';\nimport { z } from 'zod';\nconsole.log(lodash.camelCase('hello world'));" });

POST /api/v1/exec/validate/magic-comments

Parses and validates the magic-comment directives embedded at the top of a script (such as @timeout, @memory, @network) and detects any numeric directives whose value was malformed and therefore fell back to its default.

This endpoint takes no parameters.

NameTypeRequiredDescription
codestringYesSource code whose magic comments should be parsed
{
"code": "// @timeout 30s\n// @memory 256MB\n// @network\n// @description Run a long batch job\n\nasync function run() { /* ... */ }\nreturn run();"
}
{
"magicComments": {
"timeout": "30s",
"memory": "256MB",
"network": true,
"description": "Run a long batch job"
},
"warnings": [],
"returnType": {
"definition": "Promise<void>",
"mode": "async",
"location": "function run(): Promise<void>"
},
"message": "Magic comments parsed successfully"
}
import { HoodyClient } from 'hoody-sdk';
const client = new HoodyClient({ baseURL: 'https://{projectId}-{containerId}-exec-1.{server}.containers.hoody.com', token: process.env.HOODY_TOKEN });
await client.exec.validate.validateMagicComments({ code: "// @timeout 30s\n// @memory 256MB\n// @network\nasync function run() { /* ... */ }\nreturn run();" });

POST /api/v1/exec/validate/return-type

Checks whether a JSON value conforms to a declared TypeScript-style type definition. The endpoint parses the type definition, walks it against the supplied value, and returns any structural mismatches it finds.

This endpoint takes no parameters.

NameTypeRequiredDescription
typeDefinitionstringYesTypeScript-style type definition to validate against
valueanyYesArbitrary JSON value to validate against the declared return type
{
"typeDefinition": "{ id: string; tags: string[]; meta: { version: number } }",
"value": {
"id": "doc-001",
"tags": ["alpha", "beta"],
"meta": { "version": 3 }
}
}
{
"valid": true,
"errors": [],
"typeDefinition": "{ id: string; tags: string[]; meta: { version: number } }",
"parsedType": {
"kind": "object",
"properties": {
"id": { "kind": "primitive", "type": "string" },
"tags": { "kind": "array", "items": { "kind": "primitive", "type": "string" } },
"meta": {
"kind": "object",
"properties": { "version": { "kind": "primitive", "type": "number" } }
}
}
},
"message": "Value matches declared return type"
}
import { HoodyClient } from 'hoody-sdk';
const client = new HoodyClient({ baseURL: 'https://{projectId}-{containerId}-exec-1.{server}.containers.hoody.com', token: process.env.HOODY_TOKEN });
await client.exec.validate.validateReturnType({
typeDefinition: "{ id: string; tags: string[]; meta: { version: number } }",
value: { id: "doc-001", tags: ["alpha", "beta"], meta: { version: 3 } }
});

POST /api/v1/exec/validate/script

Runs every per-aspect validator (syntax, TypeScript, dependencies, magic comments) against the same piece of code in a single request. This is the recommended endpoint for full pre-flight checks before persisting or executing user-authored scripts.

This endpoint takes no parameters.

NameTypeRequiredDescription
codestringYesFull script source to validate
{
"code": "// @timeout 30s\nimport lodash from 'lodash';\n\nconst items: Array<{ id: number; name: string }> = [\n { id: 1, name: 'alpha' },\n { id: 2, name: 'beta' },\n];\n\nreturn lodash.sortBy(items, ['name']);"
}
{
"valid": true,
"results": {
"syntax": {
"valid": true,
"message": "JavaScript syntax is valid"
},
"typescript": {
"valid": true,
"transpiledLength": 214
},
"dependencies": {
"total": 1,
"installed": 1,
"missing": 0,
"missingModules": [],
"allInstalled": true
},
"magicComments": {
"timeout": "30s"
},
"magicCommentWarnings": [],
"normalized": false,
"transformations": []
},
"message": "Script validation passed"
}
import { HoodyClient } from 'hoody-sdk';
const client = new HoodyClient({ baseURL: 'https://{projectId}-{containerId}-exec-1.{server}.containers.hoody.com', token: process.env.HOODY_TOKEN });
await client.exec.validate.validateScript({
code: "// @timeout 30s\nimport lodash from 'lodash';\nconst items: Array<{ id: number; name: string }> = [{ id: 1, name: 'alpha' }];\nreturn lodash.sortBy(items, ['name']);"
});