Rayfin

@microsoft/rayfin-connector-fabric-semanticmodel

Marker, runtime, direct execution, URL parsing, Arrow decoding, and normalized result APIs for Fabric semantic model connectors.

@microsoft/rayfin-connector-fabric-semanticmodel provides the type marker and runtime helpers for fabric-semanticmodel connectors. Register its runtime with connectorsService from @microsoft/rayfin-connectors. See Semantic models for guide-level usage.

Installation

npm install @microsoft/rayfin-connector-fabric-semanticmodel@2.0.0 @microsoft/rayfin-connectors@2.0.0

Marker and operation catalog

FabricSemanticModel<TOps> is the connector marker. It defaults to the full operation union, currently only executeQuery.

import type { OperationDef } from '@microsoft/rayfin-connectors';
import type {
  ExecuteQueryInput,
  FabricSemanticModel,
  SemanticModelQueryResult,
} from '@microsoft/rayfin-connector-fabric-semanticmodel';

interface FabricSemanticModelOperationCatalog {
  executeQuery: OperationDef<ExecuteQueryInput, SemanticModelQueryResult>;
}

type AppConnectorsSchema = {
  salesmodel: FabricSemanticModel<'executeQuery'>;
};

The executeQuery output is the normalized SemanticModelQueryResult union. The runtime folds the wire envelope inside its invoke middleware before the caller receives it.

Changed in 2.0

The marker declares ConnectorConfig & { connector: 'fabric-semanticmodel' } as the configuration it accepts, so connectorsService rejects a config for another connector type under that name. The generated connectorConfig satisfies it.

Query input

interface ExecuteQueryInput {
  query: string;
  resultSetRowCountLimit?: number;
}

query is the DAX text. resultSetRowCountLimit is optional and has no default limit in the input shape; when present on a runtime-processed call, it overrides the runtime option for that call.

Changed in 2.0

executeQuery takes an optional second argument, InvokeOptions. Its timeoutMs shortens the default 5-minute wait for one call; see Request timeouts.

Normalized result

type SemanticModelQueryResult =
  | {
      status: 'success';
      table: QueryTable;
      requestId: string;
    }
  | {
      status: 'error';
      error: QueryError;
      requestId: string;
    };

interface QueryTable {
  columns: QueryColumn[];
  rows: unknown[][];
}

interface QueryColumn {
  name: string;
  dataType: string;
}

interface QueryError {
  category: 'api' | 'query' | 'network' | 'overflow' | 'unknown';
  message: string;
  code?: string;
  details?: string;
  recoveryHint?: string;
}

function toQueryResult(
  response: FabricSemanticModelTabularResponse | SemanticModelQueryResult,
): SemanticModelQueryResult;

toQueryResult accepts the raw tabular envelope or an already-normalized result. It returns success rows as column-aligned arrays and gives failures a category and message.

Int64 and overflow handling

Changed in 1.36.1

parseArrowStream coerces Arrow Int64 values, including Int64 values nested inside Power BI Variant/Union columns, to JavaScript numbers when the value is within the safe integer range.

Values outside that range become an overflow query error instead of leaking a raw bigint that would fail JSON serialization.

Runtime options

fabricSemanticModel(options?) returns the ConnectorRuntime you register in the runtime map of connectorsService, under the same connector name as in the schema.

function fabricSemanticModel(options?: FabricSemanticModelOptions): ConnectorRuntime;

interface FabricSemanticModelOptions {
  target?: FabricSemanticModelTarget | (() => FabricSemanticModelTarget | undefined);
  baseUrl?: string;
  endpoints?: FabricEndpoints;
  getToken?: () => string | undefined | Promise<string | undefined>;
  sessionId?: string;
  culture?: string;
  schemaOnly?: boolean;
  queryTimeout?: number;
  resultSetRowCountLimit?: number;
}

interface FabricSemanticModelTarget {
  workspaceId: string;
  itemId: string;
}

target, baseUrl, endpoints, getToken, and sessionId are used by the direct path, which runs only when the connectors service uses the cli host. culture, schemaOnly, queryTimeout, and resultSetRowCountLimit become DAX query options.

Changed in 2.0

connectorsService defaults to the standalone host even in Node.js, so a local script that needs the direct path passes host: { type: 'cli' } together with a configured target and getToken.

URLs and endpoints

parseFabricUrl(url) parses a portal URL into { workspaceId, itemId, itemType }. parseSemanticModelUrl(url) does the same and rejects URLs that do not address a semantic model.

https://app.fabric.microsoft.com/groups/{workspaceId}/semanticmodels/{itemId}
https://app.powerbi.com/groups/{workspaceId}/modeling/{itemId}
https://app.powerbi.com/onelake/details/{workspaceId}/dataset/{itemId}

Endpoint helpers are exported for runtime configuration:

const DEFAULT_ENDPOINTS: FabricEndpoints;
const DEFAULT_POWER_BI_BASE_URL: string;
function derivePowerBiBaseUrl(endpoints?: FabricEndpoints): string;

DEFAULT_ENDPOINTS.fabricApi is https://api.fabric.microsoft.com/v1. DEFAULT_POWER_BI_BASE_URL is https://api.powerbi.com/v1.0/myorg.

Direct execution helpers

function executeDaxDirect(
  http: InvokeHttpClient,
  target: FabricSemanticModelTarget,
  query: string,
  options?: FabricSemanticModelRuntimeOptions,
): Promise<FabricSemanticModelTabularResponse>;

function resolveTarget(
  target: FabricSemanticModelRuntimeOptions['target'],
): FabricSemanticModelTarget | undefined;

function resolveBaseUrl(
  options: Pick<FabricSemanticModelRuntimeOptions, 'baseUrl' | 'endpoints'>,
): string;

function toNetworkErrorResponse(
  err: unknown,
  requestId: string,
): FabricSemanticModelTabularResponse;

executeDaxDirect never throws. Non-2xx responses, network failures, and parse failures all become a response with status: 'Failed'.

Changed in 2.0

executeDaxDirect calls the model-scoped /datasets/{itemId}/executeDaxQueries endpoint, so the caller needs Read and Build permissions on the semantic model, not write access to the workspace. target.workspaceId is kept as metadata but is not part of the query route. The request's correlation id comes only from the Web Crypto API; a runtime without a usable Web Crypto API gets a failed response, and no request is sent.

Arrow decoding

function parseArrowStream(
  bytes: ArrayBuffer | Uint8Array,
  requestId?: string,
): FabricSemanticModelTabularResponse;

class ArrowOverflowError extends Error {}

parseArrowStream decodes Apache Arrow IPC streams into the tabular envelope. It maps DAX error tables to queryError, represents unsafe numeric coercions as table errors, and preserves column metadata when the stream provides it.

Something wrong on this page?Report an issueEdit this page

On this page