/** * Worker-boundary transport for `IfcDataStore`. * * `IfcDataStore` carries closures (`entities.getName`, `relationships.getRelated`, * `spatialHierarchy.getPath`, …) that the structured-clone algorithm strips * silently. This module separates the clone-safe column data from the * closures: `toTransport` returns a POJO + transferable list to ship across * a `postMessage` boundary; `fromTransport` reconstructs a live `IfcDataStore` * with closures rebuilt on the receiving thread. * * The `source` buffer is intentionally NOT included in the transferable list * because both the parser worker and the geometry workers read from the same * `SharedArrayBuffer` upstream of the parser. Callers are responsible for * keeping a `Uint8Array` view of that SAB on the main thread and supplying * it to `fromTransport`. */ import { type EntityTable, type EntityTableColumns, type PropertyTable, type PropertyTableColumns, type QuantityTable, type QuantityTableColumns, type RelationshipGraph, type RelationshipGraphColumns, type SpatialHierarchy } from '@ifc-lite/data'; import type { EntityRef } from './types.js'; import type { IfcDataStore } from './columnar-parser.js'; /** * Plain-data column representation of a `CompactEntityIndex`. Holds the * five backing arrays plus the deduplicated type-string list. All four * typed arrays are transferable. */ export interface CompactEntityIndexColumns { expressIds: Uint32Array; byteOffsets: Uint32Array; byteLengths: Uint32Array; typeIndices: Uint16Array; typeStrings: string[]; } interface SerializedSpatialNode { expressId: number; type: number; name: string; elevation?: number; children: SerializedSpatialNode[]; elements: number[]; } export interface SpatialHierarchyColumns { project: SerializedSpatialNode; byStorey: Array<[number, number[]]>; byBuilding: Array<[number, number[]]>; bySite: Array<[number, number[]]>; bySpace: Array<[number, number[]]>; storeyElevations: Array<[number, number]>; storeyHeights: Array<[number, number]>; elementToStorey: Array<[number, number]>; } export declare function spatialHierarchyToColumns(hierarchy: SpatialHierarchy): SpatialHierarchyColumns; export declare function spatialHierarchyFromColumns(columns: SpatialHierarchyColumns): SpatialHierarchy; export interface ParserMemorySnapshot { /** `performance.memory.usedJSHeapSize` from inside the parser worker (Chromium). */ jsHeapBytes?: number; /** Per-realm bytes from `performance.measureUserAgentSpecificMemory()` (cross-origin-isolated). */ uaMemoryBytes?: number; /** Total byte length of all transferable typed arrays in the payload. */ transportBytes: number; /** Source buffer byteLength (unchanged by parse, included for the receiver's overall accounting). */ sourceBytes: number; /** Wall-clock parse duration in milliseconds. */ parseTimeMs: number; } export interface DataStoreTransport { fileSize: number; schemaVersion: IfcDataStore['schemaVersion']; sourceHeader?: IfcDataStore['sourceHeader']; entityCount: number; parseTime: number; lengthUnitScale?: number; entityIndex: { byId: CompactEntityIndexColumns; byType: Array<[string, number[]]>; }; deferredEntityIndex?: CompactEntityIndexColumns; strings: string[]; entities: EntityTableColumns; properties: PropertyTableColumns; quantities: QuantityTableColumns; relationships: RelationshipGraphColumns; spatialHierarchy?: SpatialHierarchyColumns; onDemandPropertyMap: Array<[number, number[]]>; onDemandQuantityMap: Array<[number, number[]]>; onDemandClassificationMap: Array<[number, number[]]>; onDemandMaterialMap: Array<[number, number]>; onDemandDocumentMap: Array<[number, number[]]>; memory?: ParserMemorySnapshot; } /** * Shape of the value `toTransport` returns: the cloneable payload plus the * list of `Transferable` buffers that should be moved (rather than copied) * via `postMessage(payload, transfers)`. */ export interface DataStoreTransportEnvelope { payload: DataStoreTransport; transfers: Transferable[]; } /** * Pull every typed-array buffer out of a `DataStoreTransport` into a flat * array suitable for the `postMessage` transfer list. Order is not * meaningful — the structured-clone algorithm matches by buffer identity. * * Exported so the parser worker can append additional buffers (e.g. memory * snapshot byte arrays) before posting. */ export declare function collectTransferables(payload: DataStoreTransport): Transferable[]; /** * Convert a live `IfcDataStore` into a structured-clone-safe payload plus a * list of buffers to move via `postMessage(payload, transfers)`. * * `source` is dropped from the payload because the parser worker and main * thread both view the same upstream `SharedArrayBuffer`. Callers must * reattach `source` on the receiving side when calling `fromTransport`. */ export declare function toTransport(store: IfcDataStore): DataStoreTransportEnvelope; /** * Reconstruct a live `IfcDataStore` (closures rebuilt) from a * `DataStoreTransport` payload and the `source` buffer view that lives on * the receiving thread. */ export declare function fromTransport(payload: DataStoreTransport, source: Uint8Array): IfcDataStore; /** * Convenience: compute the byte-size of the transferable payload so the * receiver can record it in the memory accounting snapshot. */ export declare function transportByteSize(payload: DataStoreTransport): number; export type { EntityTable, PropertyTable, QuantityTable, RelationshipGraph, SpatialHierarchy }; export type { EntityRef }; //# sourceMappingURL=data-store-transport.d.ts.map