/** * Rill Value Types and Utilities * * Core value types that flow through Rill programs. * Public API for host applications. * * Structural operations (structureEquals, structureMatches, formatStructure, * inferStructure, commonType) live in types/operations.ts and are re-exported. * * Dispatch functions (inferType, formatValue) re-export from * types/registrations.ts protocol implementations. */ import type { RillTypeName } from '../../types.js'; export { isEmpty } from './types/status.js'; import type { RillTypeValue, RillValue, TypeStructure } from './types/structures.js'; /** Infer the Rill type from a runtime value. Delegates to types/registrations. */ export declare const inferType: (value: RillValue) => string; /** * Check if a value is of the expected type. * Returns true if the value matches the expected type, false otherwise. */ export declare function checkType(value: RillValue, expected: RillTypeName): boolean; /** Format a value for display. Delegates to types/registrations. */ export declare const formatValue: (value: RillValue) => string; /** * Recursive native (host-side) value type. * Represents values that can cross the host/script boundary. */ export type NativeValue = string | number | boolean | null | NativeArray | NativePlainObject; /** Array of NativeValue */ export type NativeArray = NativeValue[]; /** * Plain object with string keys and NativeValue values. * * A dict with number or boolean keys additionally carries a reserved * `__rill_typed_keys` field: an array of `{ key, value }` entries holding the * original number/boolean key alongside its native value. String keys of the * same spelling (e.g. `"1"`) are unaffected and still surface as ordinary own * fields on the object. The field is omitted entirely when the dict has no * number/boolean keys. */ export type NativePlainObject = { [key: string]: NativeValue; }; /** Structured result from toNative conversion */ export interface NativeResult { /** Rill type name -- matches RillTypeName, or 'iterator' for lazy sequences */ rillTypeName: string; /** Human-readable type signature, e.g. "string", "list(number)", "|x: number| :string" */ rillTypeSignature: string; /** * Native JS representation. Non-native types produce descriptor objects. * Dicts with number/boolean keys carry those keys under the reserved * `__rill_typed_keys` field; see {@link NativePlainObject}. */ value: NativeValue; } /** * Convert a RillValue to a NativeResult for host consumption. * Non-representable types (closures, vectors, type values, iterators) produce descriptor objects. * Tuples convert to native arrays. Ordered values convert to plain objects. * Dict number/boolean keys surface under the reserved `__rill_typed_keys` field * (see {@link NativePlainObject}); string keys are unaffected. */ export declare function toNative(value: RillValue): NativeResult; /** * Number/boolean-keyed entries of a dict, preserving each key's JS type. * * `toNative()` is insufficient for a host that needs to read a dict's typed * keys while keeping the value a live RillValue: it recursively coerces the * whole dict (and every nested value) into native descriptors, destroying * the RillValue shapes a host may still need to hand back into the runtime * (e.g. to a closure or another host call). This accessor reads the typed * keys in place, without converting anything. * * Returns `[]` — never `undefined` — for any non-dict RillValue (`null`, a * primitive, a list, or any branded value such as a stream, vector, * datetime, duration, ordered value, or type value), and for a dict with no * number/boolean keys. The `isDict` guard alone is not enough to exclude * branded objects (several call sites elsewhere pair it with an explicit * `!isStream(...)` check for the same reason), so this also confirms via * `inferType`, which dispatches through the same identity checks that put * dict last as a fallback and so classifies branded values correctly. */ export declare function getTypedKeyEntries(value: RillValue): ReadonlyArray<{ key: number | boolean; value: RillValue; }>; /** * Reserved dict method names that cannot be overridden. * Must match the full key set of DICT_METHODS in * runtime/ext/builtins/methods/tables.ts (len, first, empty, eq, ne, keys, * values, entries). Kept as a literal array rather than an import because * core/ must not import from ext/; a runtime-level parity test guards * against drift between the two. */ export declare const RESERVED_DICT_METHODS: readonly ['len', 'first', 'empty', 'eq', 'ne', 'keys', 'values', 'entries']; export { anyTypeValue } from './types/any-type.js'; /** * Convert a TypeStructure descriptor to a RillTypeValue. * Uses the TypeStructure's `kind` field as the `typeName`. * Falls back to 'any' for compound types that lack a direct RillTypeName mapping. */ export declare function structureToTypeValue(type: TypeStructure): RillTypeValue; /** * Check if a type is a collection (dict, ordered, tuple) with defined * fields or elements. Used to decide if an empty collection can be * synthesized and hydrated. */ export declare function hasCollectionFields(type: TypeStructure): boolean; /** Check if a key name is reserved */ export declare function isReservedMethod(name: string): boolean; /** Check if a key name collides with a reserved brand key */ export declare function isReservedBrandKey(name: string): boolean;