/** * Schema definitions for CR-SQLite change tracking and serialization. * * This module provides Effect Schema definitions for CR-SQLite data structures, * including change rows, tracked peers, and various identifier types used * throughout the CR-SQLite system. * * @since 0.1.0 * @example * ```typescript * import * as CrSqlSchema from "@effect-native/crsql/CrSqlSchema" * import { Schema as S } from "effect" * * // Validate a change row from CR-SQLite * const changeRow = { * table: "users", * pk: "1A2B3C4D", * cid: "name", * val: "Alice", * val_type: "text", * col_version: "1", * db_version: "1", * site_id: "A1B2C3D4E5F6789012345678ABCDEF90", * cl: 0, * seq: 0 * } * * const decoded = S.decodeUnknownSync(CrSqlSchema.ChangeRowSerialized)(changeRow) * ``` */ import * as S from "effect/Schema"; /** * Basic hex string pattern (uppercase or lowercase) used for site_id and pk values. * * @since 0.1.0 * @category Schema */ export declare const HexString: S.filter; /** * Site ID as a 32-character hex string (16 bytes). * * @since 0.1.0 * @category Schema */ export declare const SiteIdHex: S.filter; /** * @since 0.1.0 * @category Models */ export type SiteIdHex = typeof SiteIdHex.Type; /** * Version string schema for CR-SQLite version fields. * * Represents a bigint serialized as a base-10 string. There are two viable approaches * for version fields in this codebase: * * 1) Transport (string) only: keep versions as base-10 strings everywhere * - Pro: avoids bigint parsing; matches SQL CAST(... AS TEXT) output * - Con: consumers must parse to bigint for arithmetic/comparisons * * 2) Parsed (bigint) in code + string at IO: use S.BigInt transformations * - Pro: safe arithmetic in code; precise type * - Con: requires transform step at IO boundaries * * In "Serialized" schemas we use strings to faithfully represent boundary data. * * @since 0.1.0 * @category Schema */ export declare const VersionString: S.refine; /** * @since 0.1.0 * @category Models */ export type VersionString = typeof VersionString.Type; /** * SQLite column value type from typeof() function. * * @since 0.1.0 * @category Schema */ export declare const SqlValueType: S.Literal<["null", "text", "integer", "real", "blob"]>; /** * Type alias for SQLite column value types. * * Mirrors the encoded type of `typeof(SqlValueType).Type`. * * @since 0.1.0 * @category Models */ export type SqlValueType = typeof SqlValueType.Type; /** * Simple SQL identifier pattern. * * Must start with letter or underscore, followed by letters, digits, or underscores. * * @since 0.1.0 * @category Schema */ export declare const Identifier: S.filter; /** * Pre-serialized crsql_changes row for transport (IO boundary shape). * * Represents a change row as returned by CR-SQLite with all fields serialized * for transport across boundaries: * * - `pk`: hex string of BLOB primary key * - `val`: null | string | number based on val_type: * - if val_type === 'blob' then `val` is a hex string (SQL hex(val)) * - if val_type in ('integer', 'real') then `val` is a number * - if val_type === 'text' then `val` is a string * - `col_version`/`db_version`: bigint encoded as base-10 string (CAST AS TEXT in SQL) * - `site_id`: hex string for site identity * - `cl`/`seq`: non-negative integers * * @since 0.1.0 * @category Schema */ export declare const ChangeRowSerialized: S.Struct<{ table: S.refine; pk: S.refine; cid: S.refine; val: S.Union<[typeof S.Null, typeof S.String, typeof S.Number]>; val_type: S.Literal<["null", "text", "integer", "real", "blob"]>; col_version: S.refine; db_version: S.refine; site_id: S.refine; cl: S.refine; seq: S.refine; }>; /** * @since 0.1.0 * @category Models */ export type ChangeRowSerialized = typeof ChangeRowSerialized.Type; /** * Fast guard that checks an unknown value has the object shape of * {@link ChangeRowSerialized} by verifying the presence of all expected keys. * This does not perform deep type validation; use the schema for that. * * @since 0.1.0 * @category Schema */ export declare const isChangeRowSerializedQuick: (it: unknown) => it is ChangeRowSerialized; /** * Tuple (array) form of a serialized crsql_changes row. * * Same fields and order as {@link ChangeRowSerialized}, but represented as a * positional array instead of an object. Useful for compact transport formats * or drivers that emit rows as arrays. * * Field order: * [table, pk, cid, val, val_type, col_version, db_version, site_id, cl, seq] * * @since 0.1.0 * @category Schema */ export declare const ChangeArray: S.Tuple<[S.filter, S.filter, S.filter, S.Union<[typeof S.Null, typeof S.String, typeof S.Number]>, S.Literal<["null", "text", "integer", "real", "blob"]>, S.refine, S.refine, S.filter, S.refine, S.refine]>; /** * @since 0.1.0 * @category Models */ export type ChangeArray = typeof ChangeArray.Type; /** * Fast guard that checks an unknown value is a tuple of length 10 in the * order defined by {@link ChangeArray}. This does not validate element types. * * @since 0.1.0 * @category Schema */ export declare const isChangeArrayQuick: (it: unknown) => it is ChangeArray; /** * Converts either an object-shaped change ({@link ChangeRowSerialized}) or a * tuple-shaped change ({@link ChangeArray}) into the tuple form. * * @since 0.1.0 * @category Schema */ export declare const toChangeArray: (c: ChangeRowSerialized | ChangeArray) => ChangeArray; /** * Convenience schemas for batches of changes in both shapes. * * These mirror the two common transport encodings: * - Array of objects: `ChangeRowSerialized[]` * - Array of arrays: `ChangeArray[]` * * @since 0.1.0 * @category Schema */ export declare const ChangesObjects: S.Array$; pk: S.refine; cid: S.refine; val: S.Union<[typeof S.Null, typeof S.String, typeof S.Number]>; val_type: S.Literal<["null", "text", "integer", "real", "blob"]>; col_version: S.refine; db_version: S.refine; site_id: S.refine; cl: S.refine; seq: S.refine; }>>; /** * @since 0.1.0 * @category Models */ export type ChangesObjects = typeof ChangesObjects.Type; /** * @since 0.1.0 * @category Schema */ export declare const ChangesArray: S.Array$, S.filter, S.filter, S.Union<[typeof S.Null, typeof S.String, typeof S.Number]>, S.Literal<["null", "text", "integer", "real", "blob"]>, S.refine, S.refine, S.filter, S.refine, S.refine]>>; /** * @since 0.1.0 * @category Models */ export type ChangesArray = typeof ChangesArray.Type; /** * Union schema accepting either array-of-objects or array-of-arrays encodings. * * @since 0.1.0 * @category Schema */ export declare const Changes: S.Union<[S.Array$; pk: S.refine; cid: S.refine; val: S.Union<[typeof S.Null, typeof S.String, typeof S.Number]>; val_type: S.Literal<["null", "text", "integer", "real", "blob"]>; col_version: S.refine; db_version: S.refine; site_id: S.refine; cl: S.refine; seq: S.refine; }>>, S.Array$, S.filter, S.filter, S.Union<[typeof S.Null, typeof S.String, typeof S.Number]>, S.Literal<["null", "text", "integer", "real", "blob"]>, S.refine, S.refine, S.filter, S.refine, S.refine]>>]>; /** * @since 0.1.0 * @category Models */ export type Changes = typeof Changes.Type; /** * Pre-serialized crsql_tracked_peers row for transport (per-peer cursor). * * Represents a tracked peer as returned by CR-SQLite with serialized fields: * - `site_id`: hex string (16 bytes) * - `version`: bigint encoded as base-10 string (CAST AS TEXT in SQL) * - `seq`: non-negative integer * * @since 0.1.0 * @category Schema */ export declare const TrackedPeerSerialized: S.Struct<{ site_id: S.filter; version: S.refine; seq: S.refine; }>; /** * @since 0.1.0 * @category Models */ export type TrackedPeerSerialized = typeof TrackedPeerSerialized.Type; /** * Complete information about a loaded CR-SQLite extension. * * Contains both SQL-queryable information (SHA, site ID) and loading metadata * (filesystem path, timestamp). Used when the extension has been successfully * loaded and is ready for use. * * @since 0.1.0 * @category Schema */ export declare const ExtInfo: S.Struct<{ sha: S.SchemaClass; siteId: S.filter; path: S.NullOr; loadedAt: S.transformOrFail, typeof S.DateTimeUtcFromSelf, never>; }>; /** * @since 0.1.0 * @category Models */ export type ExtInfo = typeof ExtInfo.Type; /** * SQL-queryable information about the CR-SQLite extension. * * Contains only the information that can be retrieved by querying the * extension directly via SQL functions like `crsql_sha()` and `crsql_site_id()`. * Does not include loading metadata like filesystem path or timestamp. * * @since 0.1.0 * @category Schema */ export declare const ExtInfoSql: S.Struct<{ sha: S.SchemaClass; siteId: S.filter; }>; /** * @since 0.1.0 * @category Models */ export type ExtInfoSql = typeof ExtInfoSql.Type; /** * Loading metadata for the CR-SQLite extension. * * Contains information about when and from where the extension was loaded, * but not the SQL-queryable information like SHA or site ID. Useful for * debugging and auditing extension loading operations. * * @since 0.1.0 * @category Schema */ export declare const ExtInfoLoaded: S.Struct<{ path: S.NullOr; loadedAt: S.transformOrFail, typeof S.DateTimeUtcFromSelf, never>; }>; /** * @since 0.1.0 * @category Models */ export type ExtInfoLoaded = typeof ExtInfoLoaded.Type; //# sourceMappingURL=CrSqlSchema.d.ts.map