interface ViewReference { type: "view"; space: string; externalId: string; version: string; } interface ViewPropertyType { type?: string; source?: ViewReference; list?: boolean; values?: Record; } interface ViewPropertyDefinition { container: unknown; containerPropertyIdentifier: string; type: ViewPropertyType; nullable?: boolean; } interface ReverseDirectRelationConnection { through: { source: ViewReference; identifier: string; }; source: ViewReference; connectionType?: string; targetsList?: boolean; } interface EdgeConnection { type: unknown; source: ViewReference; direction?: "outwards" | "inwards"; } type ViewDefinitionProperty = ViewPropertyDefinition | ReverseDirectRelationConnection | EdgeConnection; interface ViewDefinition { space: string; externalId: string; version: string; usedFor?: "node" | "edge"; properties: Record; } type FilterDefinition = { and: FilterDefinition[]; } | { or: FilterDefinition[]; } | { not: FilterDefinition; } | { equals: { property: string[]; value: string | number | boolean | NodeId; }; } | { in: { property: string[]; values: (string | number | boolean | NodeId)[]; }; } | { range: { property: string[]; gt?: number | string; gte?: number | string; lt?: number | string; lte?: number | string; }; } | { exists: { property: string[]; }; } | { prefix: { property: string[]; value: string; }; } | { containsAll: { property: string[]; values: (string | number | boolean)[]; }; } | { containsAny: { property: string[]; values: (string | number | boolean)[]; }; } | { nested: { scope: string[]; filter: FilterDefinition; }; } | { instanceReferences: Array<{ space: string; externalId: string; }>; } | { hasData: ViewReference[]; }; type TableExpressionFilter = FilterDefinition | { and: FilterDefinition[]; }; interface PropertySort { property: string[]; direction: SortDirection; nullsFirst: boolean; } interface QuerySelectExpression { sources?: Array<{ source: ViewReference; properties: string[]; }>; } interface QueryNodeTableExpression { nodes: { filter?: TableExpressionFilter; from?: string; direction?: "outwards" | "inwards"; through?: { view: ViewReference; identifier: string; } | { source: ViewReference; identifier: string; }; }; sort?: PropertySort[]; limit?: number; } interface QueryEdgeTableExpression { edges: { from?: string; maxDistance?: number; filter?: TableExpressionFilter; direction?: "outwards" | "inwards"; }; sort?: PropertySort[]; limit?: number; } type QueryTableExpression = QueryNodeTableExpression | QueryEdgeTableExpression; interface InstancesQueryRequest { with: Record; select: Record>; cursors?: Record; } interface InstancesApplySource { source: ViewReference; properties: Record; } interface InstancesApplyNodeWrite { instanceType: "node"; space: string; externalId: string; existingVersion?: number; sources?: InstancesApplySource[]; } interface InstancesApplyEdgeWrite { instanceType: "edge"; space: string; externalId: string; type: unknown; startNode: NodeId; endNode: NodeId; existingVersion?: number; sources?: InstancesApplySource[]; } interface InstancesApplyDelete { instanceType: "node" | "edge"; space: string; externalId: string; } interface InstancesApplyRequest { items: Array; delete?: InstancesApplyDelete[]; replace?: boolean; } interface InstancesApplyResultItem { instanceType: "node" | "edge"; version?: number; wasModified?: boolean; space: string; externalId: string; createdTime?: number; lastUpdatedTime?: number; } interface InstancesApplyResponse { items: InstancesApplyResultItem[]; } interface NodeDefinition { instanceType: "node"; version?: number; space: string; externalId: string; properties?: Record>>; createdTime?: number; deletedTime?: number; lastUpdatedTime?: number; } interface EdgeDefinition { instanceType: "edge"; version?: number; space: string; externalId: string; type?: { space: string; externalId: string; }; startNode: { space: string; externalId: string; }; endNode: { space: string; externalId: string; }; properties?: Record>>; createdTime?: number; deletedTime?: number; lastUpdatedTime?: number; } type NodeOrEdge = NodeDefinition | EdgeDefinition; interface InstancesQueryResponse { items: Record; nextCursor: Record; } interface InstancesSearchRequest { view: ViewReference; query: string; instanceType: "node" | "edge"; properties: string[]; operator?: "OR" | "AND"; filter?: FilterDefinition; limit?: number; } interface InstancesSearchResponse { items: NodeOrEdge[]; } interface DataModelRetrieveItem { views?: ViewDefinition[]; createdTime: number; } interface DataModelRetrieveOptions { inlineViews?: boolean; } type AggregateFunctionName = "avg" | "min" | "max" | "sum" | "count"; type InstancesAggregateDefinition = { avg: { property: string; }; } | { min: { property: string; }; } | { max: { property: string; }; } | { sum: { property: string; }; } | { count: { property?: string; }; }; interface InstancesAggregateRequest { view: ViewReference; instanceType: "node"; limit: number; filter?: FilterDefinition; groupBy?: string[]; aggregates?: InstancesAggregateDefinition[]; } interface InstancesAggregateValue { aggregate: AggregateFunctionName; property?: string; value?: number; } interface InstancesAggregateResultItem { aggregates: InstancesAggregateValue[]; group?: Record; instanceType: "node" | "edge"; } interface InstancesAggregateResponse { items: InstancesAggregateResultItem[]; } /** Numeric datapoint from a raw (non-aggregate) time series query. */ type CogniteDoubleDatapoint = { timestamp: Date; value: number; }; /** Numeric datapoint from an aggregate time series query. * Each field corresponds to one aggregate function as defined by the Cognite API. */ type CogniteAggregateDatapoint = { timestamp: Date; } & { [K in DatapointAggregate]?: number; }; /** A numeric datapoint as returned by the Cognite API. * String time series datapoints are excluded — they are filtered out before processing. */ type CogniteNumericDatapoint = CogniteDoubleDatapoint | CogniteAggregateDatapoint; interface CogniteDatapointResultItem { space?: string; externalId?: string; isString: boolean; unit?: string; datapoints: CogniteNumericDatapoint[]; nextCursor?: string; } interface CogniteDatapointRetrieveItem extends NodeId { start?: string | number | Date; end?: string | number | Date; limit?: number; cursor?: string; aggregates?: DatapointAggregate[]; granularity?: string; includeOutsidePoints?: boolean; targetUnit?: string; targetUnitSystem?: string; timeZone?: string; } interface CogniteDatapointRetrieveOptions { items: CogniteDatapointRetrieveItem[]; start?: string | number | Date; end?: string | number | Date; limit?: number; aggregates?: DatapointAggregate[]; granularity?: string; includeOutsidePoints?: boolean; ignoreUnknownIds?: boolean; timeZone?: string; } interface CogniteDatapointLatestItem extends NodeId { before?: string | Date | number; } interface CogniteDatapointInsertItem extends NodeId { datapoints: Array<{ timestamp: number | Date; value: number; }>; } interface CogniteDatapointDeleteItem extends NodeId { inclusiveBegin: number | Date; exclusiveEnd?: number | Date; } interface CogniteFileInstanceId { space?: string; externalId?: string; } interface CogniteFileInfo { instanceId?: CogniteFileInstanceId; name: string; uploaded: boolean; uploadedTime?: Date; createdTime: Date; lastUpdatedTime: Date; mimeType?: string; directory?: string; source?: string; } interface CogniteFileUploadResult extends CogniteFileInfo { uploadUrl?: string; } interface CogniteFileUploadInfo { instanceId: { space: string; externalId: string; }; name: string; mimeType?: string; directory?: string; source?: string; metadata?: Record; } interface CogniteFileDownloadUrl { instanceId?: CogniteFileInstanceId; downloadUrl: string; } interface CognitePort { retrieveDataModels(ids: DataModelId[], options?: DataModelRetrieveOptions): Promise<{ items: DataModelRetrieveItem[]; }>; retrieveViews(ids: Array<{ space: string; externalId: string; version: string; }>): Promise<{ items: ViewDefinition[]; }>; queryInstances(request: InstancesQueryRequest): Promise; searchInstances(request: InstancesSearchRequest): Promise; aggregateInstances(request: InstancesAggregateRequest): Promise; applyInstances(request: InstancesApplyRequest): Promise; retrieveDatapoints(options: CogniteDatapointRetrieveOptions): Promise<{ items: CogniteDatapointResultItem[]; }>; retrieveLatestDatapoints(items: CogniteDatapointLatestItem[], options?: { ignoreUnknownIds?: boolean; }): Promise<{ items: CogniteDatapointResultItem[]; }>; insertDatapoints(items: CogniteDatapointInsertItem[]): Promise; deleteDatapoints(items: CogniteDatapointDeleteItem[]): Promise; uploadFile(fileInfo: CogniteFileUploadInfo, content?: unknown): Promise; getFileDownloadUrls(ids: Array<{ instanceId: { space: string; externalId: string; }; }>): Promise; } declare class ViewMapper { private readonly cognite; private readonly dataModelId; private readonly resolver; constructor(cognite: CognitePort, dataModelId: DataModelId); getView(externalId: string): Promise; getViews(): Promise; protected loadViews(): Promise>; private cacheKey; private fetchViews; private loadDependencyViews; } /** * A `ViewMapper` preloaded with view definitions captured at package generation * time. `getView` / `getViews` never call CDF. */ declare class ViewMapperCache extends ViewMapper { private readonly viewsByExternalId; constructor(views: Iterable | Map); static fromViews(views: readonly object[]): ViewMapperCache; protected loadViews(): Promise>; } type NodeId = { externalId: string; space: string; }; type DataModelId = NodeId & { version: string; }; type SortDirection = "ascending" | "descending"; type IndustrialModelClientOptions = { validateResults?: boolean; /** Preloaded view definitions. When set, the client does not fetch views from CDF. */ viewMapperCache?: ViewMapperCache; }; type Simplify = { [K in keyof T]: T[K]; } & {}; type Merge = Simplify & B>; type NonNull = Exclude; type ArrayItem = T extends readonly (infer U)[] ? U : never; type QueryDepth = 0 | 1 | 2 | 3; type PrevDepth = { 0: 0; 1: 0; 2: 1; 3: 2; }; declare const MODEL_RELATIONS: unique symbol; declare const MODEL_INSTANCE_TYPE: unique symbol; type IndustrialModel = Simplify; type ModelProps = Simplify>; type ModelRelations = TModel extends { readonly [MODEL_RELATIONS]?: infer TRelations; } ? NonNull : never; type RelationKeys = [ModelRelations] extends [never] ? never : keyof ModelRelations; type IsOptionalKey = K extends keyof T ? {} extends Pick ? true : false : false; type UnwrapRelationTarget = NonNull extends readonly unknown[] ? ArrayItem> : NonNull; type BaseSelectFor = [NonNull] extends [NodeId] ? boolean : NonNull extends readonly unknown[] ? [ArrayItem>] extends [NodeId] ? boolean : TDepth extends 0 ? boolean : NonNull>> extends object ? boolean | QuerySelect>>, PrevDepth[TDepth]> : boolean : TDepth extends 0 ? boolean : NonNull extends object ? boolean | QuerySelect, PrevDepth[TDepth]> : boolean; type RelationSelectFor = TDepth extends 0 ? never : QuerySelect, PrevDepth[TDepth]>; type QuerySelectValue = K extends RelationKeys ? K extends keyof ModelProps ? boolean | RelationSelectFor[K], TDepth> : RelationSelectFor[K], TDepth> : K extends keyof ModelProps ? BaseSelectFor[K], TDepth> : never; type QuerySelect = { _all?: true; } & { [K in keyof ModelProps | RelationKeys]?: QuerySelectValue; }; type ModelInstanceType = TModel extends { readonly [MODEL_INSTANCE_TYPE]?: "edge"; } ? "edge" : "node"; type SortInput = { [K in keyof ModelProps as NonNull[K]> extends string | number | boolean | Date | NodeId ? K : never]?: SortDirection; } & (ModelInstanceType extends "edge" ? { startNode?: SortDirection; endNode?: SortDirection; type?: SortDirection; } : {}); type QueryOptions | undefined = QuerySelect | undefined> = { viewExternalId: string; select?: TSelect; filters?: WhereInput; sort?: SortInput; limit?: number; cursor?: string | null; }; type NodeResultMetadata = Pick; type EdgeResultMetadata = Pick; type QueryResultMetadata = ModelInstanceType extends "edge" ? EdgeResultMetadata : NodeResultMetadata; type ResultShapeForKey = K extends keyof ModelProps ? ModelProps[K] : K extends RelationKeys ? ModelRelations[K] : never; type ResultEntityForKey = K extends RelationKeys ? ModelRelations[K] : K extends keyof ModelProps ? ModelProps[K] : never; type WrapResultValue = [NonNull] extends [readonly unknown[]] ? TValue[] : TValue; type AsQuerySelect = TSelect extends QuerySelect ? TSelect : never; type SelectedValue = TValue extends true ? K extends keyof ModelProps ? ModelProps[K] : never : TDepth extends 0 ? never : TValue extends object ? WrapResultValue, QueryResultItem>, AsQuerySelect>, TValue>, PrevDepth[TDepth]>> : never; type ExplicitSelectionResult = Simplify<{ [K in keyof NonNull as K extends "_all" ? never : SelectedValue[K], TDepth> extends never ? never : IsOptionalKey, K> extends true ? never : IsOptionalKey, K> extends true ? never : K]-?: SelectedValue[K], TDepth>; } & { [K in keyof NonNull as K extends "_all" ? never : SelectedValue[K], TDepth> extends never ? never : IsOptionalKey, K> extends true ? K : IsOptionalKey, K> extends true ? K : never]?: SelectedValue[K], TDepth>; }>; type QueryResultItem | undefined = undefined, TDepth extends QueryDepth = 3> = [TSelect] extends [undefined] ? Merge, ModelProps> : Merge, ModelProps> : QueryResultMetadata, ExplicitSelectionResult>; type QueryResult> = { items: TItem[]; cursor: string | null; }; type QueryExecutor = { >(options: Omit, "select"> & { select: TSelect & QuerySelect; }): Promise>>; (options: Omit, "select"> & { select?: undefined; }): Promise>>; }; type GroupableValue = [NonNull] extends [NodeId] ? true : [NonNull] extends [readonly NodeId[]] ? true : [NonNull] extends [string | number | boolean] ? true : [NonNull] extends [readonly string[]] ? true : [NonNull] extends [readonly number[]] ? true : [NonNull] extends [readonly boolean[]] ? true : false; type GroupByKey = { [K in keyof ModelProps]: GroupableValue[K]> extends true ? K : never; }[keyof ModelProps]; type AggregateGroupBy = { [K in GroupByKey]?: true; }; type NumericKey = { [K in keyof ModelProps]: [NonNull[K]>] extends [number] ? K : never; }[keyof ModelProps]; type ScalarGroupByKey = { [K in keyof ModelProps]: GroupableValue[K]> extends true ? [NonNull[K]>] extends [readonly unknown[]] ? never : K : never; }[keyof ModelProps]; type CountableKey = ScalarGroupByKey | "externalId" | "space"; type AggregateDefinition = { avg: NumericKey; } | { min: NumericKey; } | { max: NumericKey; } | { sum: NumericKey; } | { count: CountableKey | Record; }; type SelectedGroupKeys = Extract<{ [K in keyof TGroupBy & string]: TGroupBy[K] extends true ? K : never; }[keyof TGroupBy & string], string>; /** Cognite explodes list properties: each group row carries a single element, not an array. */ type GroupValueForProp = NonNull extends readonly unknown[] ? NonNull extends readonly NodeId[] ? NodeId : ArrayItem> : T; type GroupValues | undefined> = TGroupBy extends AggregateGroupBy ? Simplify<{ [K in SelectedGroupKeys & keyof ModelProps]: GroupValueForProp[K]>; }> : undefined; type AggregateValue = TDef extends { avg: infer P extends PropertyKey; } ? { aggregate: "avg"; property: P; value: number; } : TDef extends { min: infer P extends PropertyKey; } ? { aggregate: "min"; property: P; value: number; } : TDef extends { max: infer P extends PropertyKey; } ? { aggregate: "max"; property: P; value: number; } : TDef extends { sum: infer P extends PropertyKey; } ? { aggregate: "sum"; property: P; value: number; } : TDef extends { count: infer P; } ? Record extends P ? { aggregate: "count"; value: number; } : { aggregate: "count"; property: P; value: number; } : never; /** Request-order slots. A missing Cognite `value` is `undefined` in that index. */ type AggregateValuesTuple = TAggregates extends readonly unknown[] ? { readonly [I in keyof TAggregates]: AggregateValue | undefined; } : undefined; type NormalizedAggregates = [T] extends [undefined] ? undefined : T extends readonly unknown[] ? T : readonly [T]; type ResolvedAggregateDefs = TOptions extends { aggregates: infer A; } ? NormalizedAggregates : TOptions extends { aggregate: infer D; } ? readonly [D] : undefined; type FirstAggregateValue = TAggregates extends readonly [infer First, ...unknown[]] ? AggregateValue : TAggregates extends readonly (infer Element)[] ? AggregateValue : undefined; type AggregateOptions = { viewExternalId: string; filters?: WhereInput; groupBy?: AggregateGroupBy; /** * One or more Cognite aggregate ops (order preserved in the request and results). * A single definition may be passed as an object: `aggregates: { count: {} }`. */ aggregates?: AggregateDefinition | readonly AggregateDefinition[]; /** * @deprecated Use `aggregates`. Still accepted as a single-op alias. * Cannot be set together with `aggregates`. */ aggregate?: AggregateDefinition; }; type AggregateResultItem | undefined = undefined, TAggregates extends readonly AggregateDefinition[] | undefined = undefined> = { group?: GroupValues; } & ([TAggregates] extends [undefined] ? { aggregates?: undefined; aggregate?: undefined; } : { aggregates: AggregateValuesTuple; /** @deprecated Prefer `aggregates[0]`. First requested op, when that slot has a value. */ aggregate?: FirstAggregateValue; }); type AggregateResultItemForOptions> = AggregateResultItem>; type AggregateResult> = { items: TItem[]; }; type AggregateExecutor = >(options: TOptions) => Promise>>; type RelationReferenceValue = [NonNull] extends [readonly unknown[]] ? NodeId[] : NodeId; type NodeIdLike = { space: string; externalId: string; }; type ArrayReferencePropertyKeys = { [K in keyof ModelProps]: [NonNull[K]>] extends [readonly unknown[]] ? [ArrayItem[K]>>] extends [NodeIdLike] ? K : never : never; }[keyof ModelProps]; type ArrayRelationKeys = { [K in RelationKeys]: [NonNull[K]>] extends [readonly unknown[]] ? K : never; }[RelationKeys]; type UpsertProperties = Simplify> & { [K in RelationKeys]?: RelationReferenceValue[K]>; }>; type UpsertNode = Simplify, keyof NodeId>>>; type EdgeCreationContext = { startNode: NodeId; endNode: NodeId; edgeType: NodeId; }; type EdgeCreationCallback = (context: EdgeCreationContext) => NodeId; type EdgeCreationCallbacks = Partial>; type OnEdgeCreation = EdgeCreationCallbacks | ArrayRelationKeys, string>>; type EdgeMode = "append" | "replace"; type UpsertOptions = { viewExternalId: string; items: UpsertNode[]; onEdgeCreation?: OnEdgeCreation; replace?: boolean; edgeMode?: EdgeMode; }; type UpsertResultItem = { instanceType: "node" | "edge"; version?: number; wasModified?: boolean; space: string; externalId: string; createdTime?: number; lastUpdatedTime?: number; }; type UpsertResult = { items: UpsertResultItem[]; }; type UpsertExecutor = (options: UpsertOptions) => Promise; type DeleteResultItem = Omit & { instanceType: "node"; }; type DeleteResult = { items: DeleteResultItem[]; }; type DeleteExecutor = (items: TItem[]) => Promise; type DatapointAggregate = "average" | "max" | "min" | "count" | "sum" | "interpolation" | "stepInterpolation" | "totalVariation" | "continuousVariance" | "discreteVariance"; type RawDatapoint = { timestamp: Date; value: number; }; type DatapointSeriesResult = { timeSeries: NodeId; unit?: string; datapoints: RawDatapoint[]; cursor: string | null; }; type DatapointsResult = { items: DatapointSeriesResult[]; }; type DatapointsRetrieveOptions = { timeSeries: NodeId[]; start?: Date; end?: Date; /** Number of datapoints to return per time series, or -1 to auto-paginate all pages. */ limit?: number; aggregate?: DatapointAggregate; granularity?: string; includeOutsidePoints?: boolean; ignoreUnknownIds?: boolean; timeZone?: string; }; type DatapointsLatestSeries = NodeId & { before?: Date; }; type DatapointsLatestOptions = { timeSeries: DatapointsLatestSeries[]; ignoreUnknownIds?: boolean; }; type DatapointsInsertItem = { timeSeries: NodeId; datapoints: Array<{ timestamp: Date; value: number; }>; }; type DatapointsDeleteRange = { timeSeries: NodeId; start: Date; end?: Date; }; type DatapointsExecutor = { retrieve(options: DatapointsRetrieveOptions): Promise; latest(options: DatapointsLatestOptions): Promise; insert(items: DatapointsInsertItem[]): Promise; delete(ranges: DatapointsDeleteRange[]): Promise; }; type FileUploadInfo = NodeId & { name: string; mimeType?: string; directory?: string; source?: string; metadata?: Record; }; type FileUploadResult = NodeId & { name: string; uploaded: boolean; mimeType?: string; directory?: string; source?: string; uploadedTime?: Date; createdTime: Date; lastUpdatedTime: Date; uploadUrl?: string; }; type FileDownloadUrl = NodeId & { downloadUrl: string; }; type FilesExecutor = { upload(fileInfo: FileUploadInfo, content?: unknown): Promise; getDownloadUrls(nodeIds: NodeId[]): Promise; }; type SearchFilter = { query: string; operator?: "OR" | "AND"; }; type StringFilters = { eq?: string; in?: string[]; prefix?: string; search?: SearchFilter; exists?: boolean; }; type NumberFilters = { eq?: number; in?: number[]; gt?: number; gte?: number; lt?: number; lte?: number; exists?: boolean; }; type BooleanFilters = { eq?: boolean; exists?: boolean; }; type DateFilters = { eq?: string | Date; in?: Array; gt?: string | Date; gte?: string | Date; lt?: string | Date; lte?: string | Date; exists?: boolean; }; type NodeIdFilters = { eq?: NodeId; in?: NodeId[]; exists?: boolean; }; type ListFilters = { containsAny?: T[]; containsAll?: T[]; exists?: boolean; } & (T extends string ? { search?: SearchFilter; } : unknown); type BaseFilterFor = T extends NodeId ? NodeIdFilters : T extends string ? StringFilters : T extends number ? NumberFilters : T extends boolean ? BooleanFilters : T extends Date ? DateFilters : T extends Array ? ListFilters : T extends object ? NodeIdFilters | WhereInput : never; type RelationFilterFor = UnwrapRelationTarget extends object ? WhereInput> : never; type QueryFilterValue = K extends RelationKeys ? K extends keyof ModelProps ? BaseFilterFor[K]> | RelationFilterFor[K]> : RelationFilterFor[K]> : K extends keyof ModelProps ? BaseFilterFor[K]> : never; type WhereInput = { AND?: WhereInput | WhereInput[]; OR?: WhereInput[]; NOT?: WhereInput | WhereInput[]; } & { [K in keyof ModelProps | RelationKeys]?: QueryFilterValue; } & (ModelInstanceType extends "edge" ? { startNode?: NodeIdFilters; endNode?: NodeIdFilters; type?: NodeIdFilters; } : {}); export { type AggregateExecutor as A, type QueryResultItem as B, type QuerySelect as C, type DataModelId as D, type EdgeCreationCallback as E, type FilesExecutor as F, type UpsertNode as G, type UpsertOptions as H, type IndustrialModelClientOptions as I, type UpsertProperties as J, type UpsertResult as K, type UpsertResultItem as L, type ModelProps as M, type NodeId as N, type OnEdgeCreation as O, type CognitePort as P, type QueryExecutor as Q, type RawDatapoint as R, type UpsertExecutor as U, ViewMapperCache as V, type DatapointsExecutor as a, type DeleteResult as b, type AggregateOptions as c, type AggregateResult as d, type AggregateResultItem as e, type AggregateResultItemForOptions as f, type DatapointAggregate as g, type DatapointSeriesResult as h, type DatapointsDeleteRange as i, type DatapointsInsertItem as j, type DatapointsLatestOptions as k, type DatapointsLatestSeries as l, type DatapointsResult as m, type DatapointsRetrieveOptions as n, type DeleteExecutor as o, type DeleteResultItem as p, type EdgeCreationCallbacks as q, type EdgeCreationContext as r, type EdgeMode as s, type FileDownloadUrl as t, type FileUploadInfo as u, type FileUploadResult as v, type IndustrialModel as w, type ModelRelations as x, type QueryOptions as y, type QueryResult as z };