Type Reference
The complete TypeScript declarations exported by the autolang-compiler package - types, enums, interfaces, and the main ACompiler class.
If you're just getting started, see the npm Integration Guide for usage examples first.
Full Declarations
These types are shipped with the package. If you use TypeScript, they're picked up automatically - no separate @types install needed.
// ── Primitive types ──────────────────────────────────────────
type AObject = number;
type AutolangType =
| number
| null
| undefined
| string
| boolean
| void
| AObject
| object
| number[]
| string[]
| boolean[]
| AObject[]
| object[]
| Set<any>
| Map<any, any>;
// Native function bound to an Autolang function declaration.
// Parameters map directly to the Autolang function's parameter list.
type AutolangNativeFunc = (
thisArg: AutolangType,
...args: AutolangType[]
) => AutolangType;
// ── Built-in Libraries configuration ──────────────────────────
interface FileLibraryConfig {
enabled?: boolean;
autoImport?: boolean;
allowRead?: boolean;
allowWrite?: boolean;
allowDelete?: boolean;
allowedPaths?: string[];
}
interface HttpLibraryConfig {
enabled?: boolean;
autoImport?: boolean;
allowedDomains?: string[];
}
interface CommonLibraryConfig {
enabled?: boolean;
autoImport?: boolean;
}
interface CompilerLibrariesConfig {
file?: FileLibraryConfig;
http?: HttpLibraryConfig;
json?: CommonLibraryConfig;
math?: CommonLibraryConfig;
regex?: CommonLibraryConfig;
bytes?: CommonLibraryConfig;
date?: CommonLibraryConfig;
}
// ── Resource limits configuration ─────────────────────────────
interface CompilerLimitsConfig {
maxOpcodeCount?: number;
maxMemoryBytes?: number;
}
// ── Compatibility configuration ───────────────────────────────
interface CompilerCompatibilityConfig {
ignoreForeignImports?: boolean;
allowLateinit?: boolean;
allowNonNullAssertion?: boolean;
strictMode?: boolean;
allowValReassign?: boolean;
autoCloseBracketsOnEof?: boolean;
allowImplicitVarDeclaration?: boolean;
}
// ── Compiler configuration ────────────────────────────────────
// Passed to ACompiler.create() to control libraries, limits and compatibility options.
interface ACompilerConfig {
libraries?: CompilerLibrariesConfig;
limits?: CompilerLimitsConfig;
compatibility?: CompilerCompatibilityConfig;
strictMode?: boolean;
}
// ── Library configuration ─────────────────────────────────────
// Used when registering a native library or configuring the main source.
interface LibraryConfig {
autoImport?: boolean; // skip @import in all files
allowLateinitKeyword?: boolean; // allow "lateinit var"
allowNonNullAssertion?: boolean; // allow the ! postfix operator
}
// ── Runtime exception object ──────────────────────────────────
interface AException {
message: string;
}
// ── Security rule types ───────────────────────────────────────
enum AllowRuleType {
PLAIN_PREFIX = 0, // plain string prefix (special chars escaped)
REGEX = 1, // full ECMAScript regex pattern
}
type AllowRule =
| string // shorthand for PLAIN_PREFIX
| [AllowRuleType, string] // tuple form
| { type: AllowRuleType; value: string }; // object form
// ── Main compiler class ───────────────────────────────────────
declare class ACompiler {
static create(config?: ACompilerConfig): Promise<ACompiler>;
// Output buffer
getOutput(): any;
clearOutput(): void;
setOutput(output: string): void;
// Library registration
registerBuiltInLibrary(
name: string,
source: string,
config?: LibraryConfig,
methods?: Record<string, AutolangNativeFunc>
): void;
// Compiler options & Resource limits
setMainSourceConfig(config: LibraryConfig): void;
setLimitOpcodeCount(limit: number): void;
getLimitOpcodeCount(): number;
setMaxManagedMemory(limit: number): void;
getManagedMemorySize(): number;
getCurrentManagedMemory(): number;
getMaxManagedMemory(): number;
// Compiler mode & Compatibility
setAllowImplicitVarDeclaration(enable: boolean): void;
getAllowImplicitVarDeclaration(): boolean;
setAutoCloseBracketsOnEof(enable: boolean): void;
getAutoCloseBracketsOnEof(): boolean;
setStrictMode(enable: boolean): void;
getStrictMode(): boolean;
loadBuiltInLibraries(): void;
// Security - HTTP (requires std/http)
setAllowedDomainsRules(rules: AllowRule[]): void;
// Security - File system (requires std/file)
setAllowFileRead(allow: boolean): void;
setAllowFileWrite(allow: boolean): void;
setAllowFileDelete(allow: boolean): void;
setAllowedFilePathsRules(rules: AllowRule[]): void;
setFileBasePath(path: string): void;
// Compilation & execution
compileAndRun(path: string, code: string): Promise<boolean>;
compile(path: string, code: string): Promise<boolean>;
run(): Promise<boolean>;
// Diagnostics
hasCompilerError(): boolean;
throwException(message: string): boolean;
hasException(): boolean;
getException(): AException | null;
// Callbacks (fired during compilation)
setOnError(callback: ((error: string) => void) | null): void;
setOnWarning(callback: ((warning: string) => void) | null): void;
// State reset
refresh(): void;
// Cleanup
dispose(): void;
[Symbol.dispose](): void;
}
export {
ACompiler,
AllowRuleType,
type ACompilerConfig,
type AException,
type AObject,
type AllowRule,
type AutolangNativeFunc,
type AutolangType,
type CommonLibraryConfig,
type CompilerCompatibilityConfig,
type CompilerLibrariesConfig,
type CompilerLimitsConfig,
type FileLibraryConfig,
type HttpLibraryConfig,
type LibraryConfig
};For security-related methods (setAllowedDomainsRules, setAllowFileRead, etc.), see Security & Sandboxing.