/** * Flowcore rejects a single event whose payload exceeds this many bytes * (`400 Event size exceeds maximum limit of 64000 bytes`). The limit is 64 000, not 65 536. */ export declare const DEFAULT_MAX_EVENT_BYTES = 64000; /** * Default byte budget for one serialized part payload. Kept well under * {@link DEFAULT_MAX_EVENT_BYTES} so the metadata header and any server-side * framing never push a part over the cap. */ export declare const DEFAULT_PART_BUDGET_BYTES = 45000; /** Payload field that carries the chunk header on every part event. */ export declare const CHUNK_ENVELOPE_FIELD = "pathwaysChunk"; /** Payload field that carries the slice (plaintext or ciphertext) on every part event. */ export declare const CHUNK_DATA_FIELD = "data"; /** Metadata marker present on every part event. */ export declare const PATHWAY_CHUNKED_METADATA_KEY = "pathways/chunked"; /** Transport scheme identifier written into every chunk header. */ export declare const PATHWAY_CHUNK_SCHEME = "utf8-split-sha256-v1"; /** Plaintext header carried on every part event. */ export interface ChunkHeader { /** Full UUID shared by every part of one logical event. */ id: string; /** 1-based part number. */ part: number; /** Total number of parts. */ totalParts: number; /** SHA-256 hex digest of the full plaintext JSON. */ digest: string; /** Transport scheme, see {@link PATHWAY_CHUNK_SCHEME}. */ scheme: string; } /** Wire shape of one part event payload. */ export interface ChunkEnvelope { [CHUNK_ENVELOPE_FIELD]: ChunkHeader; [CHUNK_DATA_FIELD]: string; } /** Options for automatic event chunking on the write side. */ export interface PathwayChunkingConfig { /** * Turns automatic chunking off even when a chunk store is configured. * Default `true`. Chunking is never active without a chunk store. */ enabled?: boolean; /** * Serialized payload size above which an event is split. Default * {@link DEFAULT_MAX_EVENT_BYTES}. */ maxEventBytes?: number; /** * Maximum serialized size of one part payload. Default * {@link DEFAULT_PART_BUDGET_BYTES}. Must be below `maxEventBytes`. */ partBudgetBytes?: number; } /** Fully resolved chunking configuration. */ export interface ResolvedPathwayChunkingConfig { enabled: boolean; maxEventBytes: number; partBudgetBytes: number; } /** * Applies defaults to a chunking configuration and validates the budgets. * * @throws {Error} When `partBudgetBytes` is not below `maxEventBytes`, or either is not positive. */ export declare function resolvePathwayChunkingConfig(config?: PathwayChunkingConfig): ResolvedPathwayChunkingConfig; /** Size in bytes of the JSON serialization of `value`. */ export declare function serializedByteLength(value: unknown): number; /** SHA-256 hex digest of a UTF-8 string. */ export declare function sha256Hex(text: string): string; /** * Splits a string into slices whose UTF-8 encoding is at most `maxBytes` long. * Never splits inside a multi-byte character or a surrogate pair. * * @throws {Error} When `maxBytes` is smaller than 4 (the largest UTF-8 character). */ export declare function splitUtf8(text: string, maxBytes: number): string[]; /** * Builds one part envelope. Exported for tests and for custom transports. */ export declare function buildChunkEnvelope(header: ChunkHeader, data: string): ChunkEnvelope; /** * Splits a plaintext payload into part envelopes that each serialize to at most * `partBudgetBytes`. * * `transform` runs on every slice before it is placed in the envelope. Pass the * encryption function for encrypted pathways. The transformed slice, not the * plaintext slice, is measured against the budget, so ciphertext expansion is * accounted for automatically. * * @param payload The full plaintext payload (any JSON value) * @param partBudgetBytes Maximum serialized size of one part payload * @param transform Optional per-slice transform, e.g. encryption * @param chunkId Optional fixed chunk id (defaults to a fresh UUID) * @returns The ordered part envelopes * @throws {Error} When no slice size satisfies the budget */ export declare function buildChunkParts(payload: unknown, partBudgetBytes: number, transform?: (slice: string) => string, chunkId?: string): ChunkEnvelope[]; /** * Returns the chunk header when `payload` is a part envelope, otherwise `null`. * * A payload without the envelope field is a plain event. A payload that carries the envelope * field but does not form a valid envelope is malformed and throws, so a corrupted part can * never fall through to schema validation as if it were a plain event. * * @throws {Error} When the envelope field is present but malformed, or the scheme is unknown */ export declare function parseChunkEnvelope(payload: unknown): { header: ChunkHeader; data: string; } | null; /** * Joins ordered plaintext slices, verifies the digest and parses the JSON. * * @throws {Error} When the digest does not match or the text is not valid JSON */ export declare function joinChunkParts(slices: string[], expectedDigest: string): unknown; /** True when the metadata carries the chunk marker. */ export declare function hasChunkedMetadata(metadata: unknown): boolean; /** * Removes the chunk marker from event metadata. Returns a new object; the input is untouched. * The marker describes the wire form. Once the event is reassembled it no longer holds, and a * later pass (cluster mode re-enters `process()`) must not try to reassemble again. */ export declare function stripPathwayChunkMetadata(metadata: unknown): unknown; //# sourceMappingURL=chunking.d.ts.map