skipcheck

TM1 client · Docs · The client

Tm1Batch

import { Tm1Batch } from "@skipcheck/tm1-client";

A JSON $batch being put together, from Tm1Client.batch: calls made through client are queued rather than sent, and run sends them together. Each call's result is there once the batch has run. Every service's methods work through it unchanged. TM1 (11.8) runs the calls in the order they were made, so a later call sees an earlier one's writes. See Tm1SessionBatch for what else TM1 does with a batch.

Read three things in one round trip:

// Each call is queued as it's made, and has its result once the batch has run
const batch = tm1.batch();
const sales = batch.client.cubes.get("Sales");
const region = batch.client.dimensions.get("Region");
const processes = batch.client.processes.list(ODataQuery.none().select(Process.Fields.Name)).toArray();
await batch.run();
return Promise.all([sales, region, processes]);

Create many elements in batches of 200, each failure kept to its own element:

// One request per element, 200 to a $batch; one element's failure is its own
const batch = tm1.batch();
const results = cities.map((city) =>
  batch.client.elements.create("City", "City", ElementPatch.builder().name(city).build()).then(
    (element) => element.Name ?? city,
    (e: unknown) => `${city} failed: ${String(e)}`,
  ),
);
await batch.run(200);
return Promise.all(results);

Members

client propertyThe client whose calls join this batch.
Tm1Batch constructor@internal
sizeHow many requests have joined.
runSends the queued requests (Tm1SessionBatch.run), at most perRequest to a $batch request.

client

property
client: Tm1Client

The client whose calls join this batch.

Tm1Batch

constructor
constructor(private readonly batch: Tm1SessionBatch)

@internal

size

size(): number

How many requests have joined.

run

run(perRequest?: number, options?: Tm1CallOptions): Promise<void>

Sends the queued requests (Tm1SessionBatch.run), at most perRequest to a $batch request. Resolves when every call has its result.