/**
 * Canonical typed value model for the JS-facing Lora packages
 * (`lora-node` and `lora-wasm`).
 *
 * Every structural value carries a `kind` discriminator. Temporal and
 * spatial values are tagged so TypeScript can narrow safely after a
 * query runs.
 *
 * Canonical source: `crates/shared-ts/types.ts`. Each JS-facing package
 * (`lora-node`, `lora-wasm`) copies this file into its own `ts/` dir
 * via its `sync:types` npm script. The `verify:types` script fails CI if
 * the copies drift — do not edit the per-package copies directly.
 */
// ---------------------------------------------------------------------------
// Guards
// ---------------------------------------------------------------------------
export function isNode(v) {
    return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "node";
}
export function isRelationship(v) {
    return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "relationship";
}
export function isPath(v) {
    return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "path";
}
export function isPoint(v) {
    return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "point";
}
export function isVector(v) {
    return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "vector";
}
export function isTemporal(v) {
    if (typeof v !== "object" || v === null || Array.isArray(v))
        return false;
    const kind = v.kind;
    return (kind === "date" ||
        kind === "time" ||
        kind === "localtime" ||
        kind === "datetime" ||
        kind === "localdatetime" ||
        kind === "duration");
}
// ---------------------------------------------------------------------------
// Constructors
// ---------------------------------------------------------------------------
export const date = (iso) => ({ kind: "date", iso });
export const time = (iso) => ({ kind: "time", iso });
export const localtime = (iso) => ({ kind: "localtime", iso });
export const datetime = (iso) => ({ kind: "datetime", iso });
export const localdatetime = (iso) => ({ kind: "localdatetime", iso });
export const duration = (iso) => ({ kind: "duration", iso });
/**
 * Build a `LoraVector` parameter value. Mirrors the on-wire tagged
 * shape the engine emits, so round-trips (receive from a query, pass
 * back into the next query) work without any conversion.
 */
export const vector = (values, dimension, coordinateType) => ({ kind: "vector", dimension, coordinateType, values });
export const cartesian = (x, y) => ({
    kind: "point",
    srid: 7203,
    crs: "cartesian",
    x,
    y,
});
export const cartesian3d = (x, y, z) => ({
    kind: "point",
    srid: 9157,
    crs: "cartesian-3D",
    x,
    y,
    z,
});
export const wgs84 = (longitude, latitude) => ({
    kind: "point",
    srid: 4326,
    crs: "WGS-84-2D",
    x: longitude,
    y: latitude,
    longitude,
    latitude,
});
export const wgs84_3d = (longitude, latitude, height) => ({
    kind: "point",
    srid: 4979,
    crs: "WGS-84-3D",
    x: longitude,
    y: latitude,
    z: height,
    longitude,
    latitude,
    height,
});
/**
 * Error thrown by `Database.execute` when Lora parsing, analysis, or
 * execution fails.
 */
export class LoraError extends Error {
    code;
    constructor(message, code = "UNKNOWN") {
        super(message);
        this.name = "LoraError";
        this.code = code;
    }
}
const ERROR_PREFIX_RE = /^(LORA_ERROR|INVALID_PARAMS|WORKER_ERROR):\s*(.*)$/s;
/**
 * Normalise a thrown value into a `LoraError` with a narrowed `code`
 * when the message carries a recognised prefix; otherwise returns the
 * original `Error` unchanged.
 */
export function wrapError(err) {
    if (!(err instanceof Error))
        return new LoraError(String(err), "UNKNOWN");
    const match = ERROR_PREFIX_RE.exec(err.message);
    if (match) {
        return new LoraError(match[2], match[1]);
    }
    return err;
}
//# sourceMappingURL=types.js.map