import type { ColdCode } from "../core/types.js"; import type { Versionage } from "../tables/table-types.js"; import type { Kind } from "../tables/versions.js"; import type { Primitive } from "./primitive.js"; type ParseDomain = Extract; /** Scalar semantic values representable by CESR-native `Mapper` leaves. */ export type MapperScalar = null | boolean | number | string; /** Recursive semantic map value representable by CESR-native `Mapper`. */ export type MapperValue = MapperScalar | MapperValue[] | MapperMap; /** Semantic map form owned by `Mapper.mad`, aligned with KERIpy `dict` usage. */ export type MapperMap = { [key: string]: MapperValue; }; /** * `Mapper` is the base semantic primitive for CESR-native field maps. * * Read this file as three stacked layers: * 1. syntax probing/tokenization helpers (`parse*Syntax`) * 2. semantic value encode/decode helpers (`serializeValue`/`deserializeValue`) * 3. the `Mapper` class that owns end-to-end map lifecycle * * Disclosure boundary: * - `Mapper` / `Compactor` own arbitrary map disclosure * - `Aggor` owns aggregate-list disclosure * - fixed-field blinded disclosure lives separately in `structing.ts` + * `disclosure.ts` */ /** * Semantic projection of one field in a native map body. * * Maintainer model: * - `label` is the decoded field name from the map key token * - `primitive` is the first token that represents the field value on the wire * - `isCounter` distinguishes scalar primitives from grouped list/map values * - `children` is only populated when the field value is itself a nested map * * This type intentionally sits between two worlds: * syntax-oriented parser artifacts (`MapperBodySyntax`) and fully semantic * `mad` values on `Mapper`. It is the readable middle layer used by tests, * annotators, and maintainers inspecting native structure. */ export interface MapperField { label: string | null; primitive: Primitive; isCounter: boolean; children?: MapperField[]; } /** Label token artifact produced during map payload syntax parsing. */ export interface MapperLabelTokenSyntax { kind: "label"; primitive: Primitive; label: string; consumed: number; } /** Value token artifact produced during map payload syntax parsing. */ export interface MapperValueTokenSyntax { kind: "value"; primitive: Primitive; isCounter: boolean; consumed: number; children?: MapperBodySyntax; } /** Ordered syntax token stream for one map payload. */ export type MapperSyntaxEntry = MapperLabelTokenSyntax | MapperValueTokenSyntax; /** Syntax artifact for a parsed map-body/group token sequence. */ export interface MapperBodySyntax { /** Map/group counter code parsed at the payload head. */ code: string; /** Counter count from map/group header. */ count: number; /** Counter token size in qb64 bytes. */ fullSize: number; /** Counter token size in qb2 bytes. */ fullSizeB2: number; /** Total group span in qb64 bytes (header + payload). */ totalSize: number; /** Total group span in qb2 bytes (header + payload). */ totalSizeB2: number; /** Ordered token artifacts from payload tokenization. */ entries: MapperSyntaxEntry[]; } /** * Supported constructor inputs for `Mapper`. * * The important split is semantic-vs-wire: * - provide `mad` when you already have a semantic map and want mapper-owned * serialization / optional top-level saidification * - provide `raw`/`qb64`/`qb64b`/`qb2` when you want mapper-owned inhale from * an existing wire representation */ export interface MapperInit { mad?: MapperMap; raw?: Uint8Array; qb64?: string; qb64b?: Uint8Array; qb2?: Uint8Array; version?: Versionage; strict?: boolean; saids?: Record; saidive?: boolean; makify?: boolean; verify?: boolean; kind?: Kind; } /** Convert syntax entries into labeled semantic map fields. */ export declare function interpretMapperBodySyntax(syntax: MapperBodySyntax): MapperField[]; /** * Parse map-style native bodies/counters into syntax artifacts. * Parsing is strict: payload boundaries must be exact. */ export declare function parseMapperBodySyntax(input: Uint8Array, version: Versionage, domain: ParseDomain): MapperBodySyntax; /** * Semantic CESR-native map primitive. * * KERIpy substance: `Mapper` is the reusable native field-map engine beneath * compactable ACDC sections. It owns both the semantic map view (`mad`) and the * exact enclosed native group serialization (`raw`, `qb64`, `qb2`). * * Cohesive mental model: * 1. `parseMapperBodySyntax()` tokenizes raw native bytes into syntax artifacts. * 2. `interpretMapperBodySyntax()` pairs those artifacts into readable fields. * 3. `Mapper` owns the full semantic lifecycle: build from `mad`, or inhale * from raw, then expose both semantic (`mad`) and wire (`raw`, `qb64`, * `qb2`) views. * * Put differently: * syntax helpers are for inspection and parser diagnostics; * `Mapper` is for truth. * * Compare carefully: * - use `Mapper` when the disclosed thing is a general map * - do not use it for fixed-field blind/bound/media tuples, which have their * own explicit schema and workflow layer */ export declare class Mapper { code: string; count: number; fullSize: number; fullSizeB2: number; totalSize: number; totalSizeB2: number; fields: MapperField[]; raw: Uint8Array; strict: boolean; saids: Record; saidive: boolean; kind: Kind; _mad: MapperMap; /** * Create one semantic mapper from either a field map (`mad`) or raw bytes. * * Constructor modes: * - semantic mode: caller provides `mad`, optional `makify`, optional * `saidive`, and the constructor serializes deterministically * - native inhale mode: caller provides `raw`/`qb64`/`qb64b`/`qb2` with * `kind="CESR"` and the constructor decodes grouped native content * - non-native inhale mode: caller provides raw JSON/CBOR/MGPK with * `kind!="CESR"` and the constructor decodes via the corresponding codec */ constructor(init?: MapperInit); static fromSad(mad: MapperMap, options?: Omit): Mapper; /** * Serialize one semantic map into an enclosed CESR native map-group. * * The result includes the leading group counter. Nested maps/lists are * recursively enclosed in their own grouped payloads. */ static serializeCesrMap(mad: MapperMap, strict?: boolean, dummy?: boolean, saids?: Record): Uint8Array; static serializeNonNativeMap(mad: MapperMap, kind: Exclude): Uint8Array; static deserializeNonNativeMap(raw: Uint8Array, kind: Exclude): MapperMap; get mad(): MapperMap; get qb64b(): Uint8Array; get qb64(): string; get qb2(): Uint8Array; get said(): string | null; get size(): number; } /** * Parse map-style native bodies/counters into a semantic `Mapper`. * * Compatibility wrapper: existing parser-oriented tests can keep calling this * helper, while newer code can instantiate `Mapper` directly from `mad` or * raw. This wrapper preserves the older parser-friendly feel while the class * itself is the new semantic authority. */ export declare function parseMapperBody(input: Uint8Array, version: Versionage, domain: ParseDomain): Mapper; /** True for counter codes that represent map/list-native aggregate primitives. */ export declare function isMapperCounterCode(code: string): boolean; export {}; //# sourceMappingURL=mapper.d.ts.map