/** * Data contracts (ADR-005, ADR-018). The engine asks for capabilities, never for a database. * * Security (Decision 8): providers return data that is ALREADY authorized for the current user. * The browser engine is not a security boundary; anything it filters is visibility, not access control. */ import type { AltitudeReference, Annotation, BoundingBox, Geometry, GeometryFamily, Position, SpatialObject, SpatialQuery, TimeRange, Track, Unsubscribe } from '../core/types.js'; export interface DataCapabilities { supportsSpatialQuery: boolean; supportsHistoricalQuery: boolean; supportsRealtime: boolean; supportsWrite: boolean; } export interface SpatialDataProvider { readonly capabilities: DataCapabilities; /** Objects matching every field of the query. Must honour `signal` (reject with an AbortError). */ query(query: SpatialQuery, signal?: AbortSignal): Promise; getCurrentState(objectIds: string[], signal?: AbortSignal): Promise; } /** A provider that also accepts writes (used by io-maps authoring and by mocks). Read-only providers stay read-only. */ export interface WritableSpatialProvider extends SpatialDataProvider { upsert(object: SpatialObject, meta?: { ontologyType?: string; }): Promise; remove(objectId: string): Promise; } export declare function isWritableProvider(p: SpatialDataProvider): p is WritableSpatialProvider; /** Incremental change from a realtime source. */ export interface SpatialPatch { upserted?: SpatialObject[]; removed?: string[]; } /** Snapshot + stream (ADR-015): callers take a snapshot with `query`, then apply these patches. No RxJS (Decision 12). */ export interface RealtimeProvider { subscribe(query: SpatialQuery, onPatch: (patch: SpatialPatch) => void, onError?: (error: Error) => void): Unsubscribe; } /** How an Ontology type projects into space. Resolved by the Ontology side; the engine only consumes it. */ export interface SpatialBinding { ontologyType: string; geometryProperty: string; geometryType: Geometry['type']; capabilities: DataCapabilities; } export interface MissingCapability { ontologyType: string; missing: 'spatial'; reason: string; } export interface OntologySpatialResolver { resolve(ontologyType: string, signal?: AbortSignal): Promise; } export declare function isMissingCapability(v: SpatialBinding | MissingCapability): v is MissingCapability; /** * Historical positions (doc 07, doc 11 TrackProvider). Returns tracks of objects matching the query whose * positions fall inside `query.bounds` during `range` — including objects no longer present now. */ export interface TrackProvider { getTracks(query: SpatialQuery, range: TimeRange, signal?: AbortSignal): Promise; } /** What a property holds across a dataset, so an application can build pickers and rules without hard-coding names. */ export interface PropertySchema { name: string; type: 'number' | 'string' | 'boolean' | 'mixed'; /** Objects that have a non-null value. */ count: number; /** Distinct values (all types). */ distinct: number; min?: number; max?: number; /** Up to a handful of distinct values, most common first (strings and booleans; small numeric sets too). */ values?: Array; } /** One kind of spatial object a provider can serve: its type, geometry and property schema. */ export interface DatasetInfo { ontologyType: string; label?: string; /** Where it comes from, for display ("Plant telemetry", "Imported file"). */ source?: string; /** The single geometry type, or 'Mixed' when objects differ (e.g. Polygon and MultiPolygon). */ geometryType: Geometry['type'] | 'Mixed'; /** Point, line or area — what kind of layer can draw it. 'mixed' only when the families differ. */ geometryFamily: GeometryFamily | 'mixed'; count: number; properties: PropertySchema[]; bounds?: BoundingBox; /** Position history is available (replay, trails). */ hasHistory: boolean; /** Changes stream live. */ live: boolean; /** Units of properties that have one (e.g. { speed: 'm/s' }), for display. */ units?: Record; /** When the source last had data for this dataset (epoch ms) — lets an app tell stale data from live data. */ lastDataAt?: number; /** Positions carry `altitude`, measured from this reference — so an app can draw them at height correctly. */ altitude?: { reference: AltitudeReference; }; } /** * Ground heights (doc 3D plan, ADR-028): metres above mean sea level under each position, null where unknown. * A terrain service, or the renderer's own terrain when it has one. */ export interface ElevationProvider { sample(positions: Position[], signal?: AbortSignal): Promise>; } /** Optional: providers that can describe what they hold. Applications use it to discover data instead of hard-coding it. */ export interface DatasetCatalog { listDatasets(signal?: AbortSignal): Promise; } export declare function hasCatalog(p: object): p is DatasetCatalog; /** A relation between two objects (UNS neighbours, lineage…). The engine draws it; it never infers one. */ export interface Link { id: string; fromId: string; toId: string; type?: string; properties?: Record; } /** Links touching any of `objectIds`, of the given types (all when omitted). Authorized data only. */ export interface LinkProvider { getLinks(objectIds: string[], types: string[] | undefined, signal?: AbortSignal): Promise; } /** * One entry of the event journal (doc 29 §7): what an object was from `at` on. `object` is its full state then * (or, for `removed`, absent). Sources may add their own `kind`s; the engine only needs created/updated/removed/ * snapshot to rebuild the map at a time. */ export interface JournalEntry { /** ISO 8601. */ at: string; objectId: string; kind: 'snapshot' | 'created' | 'updated' | 'removed' | (string & {}); object?: SpatialObject; /** What changed, for display (e.g. { status: ['ok', 'alarm'] }). */ changes?: Record; source?: string; } /** * The event journal behind replay of whole objects (doc 29 §7–8, doc 28 G5). For a query and a range it returns, * per object, its state as of `range.start` (kind `snapshot`) followed by every change inside the range, oldest * first. The engine rebuilds the map at any time in the range from that; it never stores history itself. */ export interface JournalProvider { getJournal(query: SpatialQuery, range: TimeRange, signal?: AbortSignal): Promise; } /** Where annotations live (doc 28 G10): shared with others when the provider stores them, e.g. as UNS nodes. */ export interface AnnotationProvider { list(signal?: AbortSignal): Promise; save(annotation: Annotation): Promise; remove(id: string): Promise; /** Changes made elsewhere (other users), if the store can stream them. */ subscribe?(onChange: (change: { upserted?: Annotation[]; removed?: string[]; }) => void): Unsubscribe; } /** * Who is looking (doc 28 G13). The engine never decides access; it hands this to every provider that accepts it * (`setAuth`), reloads, and shows what comes back: missing objects are absent, removed properties are listed in * `object.redacted`, and a refused layer (an ACCESS_DENIED error) gets the status 'denied'. */ export interface AuthContext { userId?: string; /** Opaque to the engine; providers send it to their server. */ token?: string; roles?: string[]; attributes?: Record; } export interface AuthAware { setAuth(auth: AuthContext | null): void; } export declare function isAuthAware(p: unknown): p is AuthAware;