Tm1Session
import { Tm1Session } from "@skipcheck/tm1-client";Used in the walkthroughs Connect and list your cubes, Test your code against a real TM1, Add TM1 to a Spring Boot application.
One TM1 session, shared by every service. Thread-safe, and safe to share between any number of concurrent callers: TM1 runs requests on one session in parallel.
- Login is lazy and happens once. The first request logs in, and concurrent first requests share that login. Only the login carries the credentials; every other request carries just the session cookie, since a request with credentials and no cookie makes TM1 open another session.
- Close it.
closeends the TM1 session. Otherwise it stays open on the server, counting against its sessions, until it times out. - Any request.
executeandstreamsend anyTm1Request, so anything the services don't cover yet is still reachable.
Build a session with CAM security and a label:
// CAM security, with a label that shows in Sessions and Threads
return Tm1Session.builder()
.address("https://tm1.example.com:8010")
.authenticator(Tm1Authenticator.camNamespace("alice", password, "LDAP"))
.sessionContext("Sales planning")
.build();
Or log in with a CAM passport, such as one from exchanging an OIDC token with Cognos:
// CAM passports expire, so the session asks for a current one on every login
return Tm1Session.builder().address("https://tm1.example.com:8010").authenticator(Tm1Authenticator.camPassport(cognos)).build();
Send a request no service covers yet, here streaming a collection:
// GET MessageLogEntries, sent as a request of your own: the latest 20 entries
const latest = ODataQuery.none().orderByDescending(MessageLogEntry.Fields.TimeStamp).top(20);
return session.stream(Tm1Request.list(ODataPath.of("MessageLogEntries"), latest, MessageLogEntry));
Run a service's requests in a sandbox by giving it a sandbox view of the session:
// The cell: every dimension, in the cube's order
const cell = { Region: "North", Month: "Jan" };
await new SandboxService(session).create(SandboxPatch.builder().name("What-if").build());
await new CellService(session.withSandbox("What-if")).update("Sales", cell, 1200);
Members
Tm1Session constructor | @internal |
connection property | @internal |
builder static | The settings one by one, as the Java client's Tm1Session.builder(). |
serviceRoot | The REST API's root, such as http://tm1:8010/api/v1/. |
sandbox | The sandbox this view's requests run in, if any. |
changeSet | The change set this view's writes are recorded in, if any. |
async | How often this view polls an async request's monitor, in milliseconds, or undefined. |
isClosed | Whether close has been called. |
isBusy | @internal Whether a request is running on the session, through any view of it. |
withSandbox | A view of this session whose requests run in sandbox name. |
withoutSandbox | A view of this session whose requests run outside any sandbox, in base data. |
withChangeSet | A view of this session whose writes are recorded in change set id (from BeginChangeSet). |
withoutChangeSet | A view of this session whose writes go into no change set. |
withAsync | @param every how often to poll, in milliseconds |
withoutAsync | A view of this session whose requests run synchronously, as usual. |
batch | Starts a JSON $batch. |
connect | Logs in now, rather than on the first request. |
sessionId | The session's ID on TM1 (ActiveSession), logging in if needed. |
close | Ends the session on the server, for every view. |
[Symbol.asyncDispose] | Ends the session on the server, for await using. |
version | The server's product version, such as 11.8.03500.6, read from Server.ProductVersion once per login. |
capabilities | What the server supports, from its own $metadata. |
execute | Sends a request and reads its answer. |
stream | The items of a collection, fetching pages as they're needed (Java's stream). |
check | @internal Fails if the server doesn't define what a request requires, unless the session was told not to check. |
target | @internal The URL of a path and query, with the view's !sandbox and !ChangeSet unless the request sets its own. |
contextual | @internal |
read | @internal |
toString | The session, its service root and its view (sandbox, change set, async), for logs. |
Tm1Session
constructorconstructor( readonly connection: Connection, private readonly sandboxName: string | undefined, private readonly changeSetId: string | undefined, private readonly asyncEvery: number | undefined, private readonly queue: BatchQueue | undefined, )@internal
connection
propertyreadonly connection: Connection@internal
builder
staticstatic builder(): Tm1SessionBuilderThe settings one by one, as the Java client's Tm1Session.builder().
serviceRoot
serviceRoot(): stringThe REST API's root, such as http://tm1:8010/api/v1/.
sandbox
sandbox(): string | undefinedThe sandbox this view's requests run in, if any: its name, or undefined for base data.
changeSet
changeSet(): string | undefinedThe change set this view's writes are recorded in, if any: its ID, or undefined.
async
async(): number | undefinedHow often this view polls an async request's monitor, in milliseconds, or undefined.
isClosed
isClosed(): booleanWhether close has been called.
isBusy
isBusy(): boolean@internal Whether a request is running on the session, through any view of it.
withSandbox
withSandbox(name: string): Tm1SessionA view of this session whose requests run in sandbox name: each gets TM1's !sandbox query option, unless the request sets its own. The view shares this session's login, cookie and connections, so it costs nothing; closing either closes both. Derived rather than set on the session, so one caller's sandbox can't leak into another caller's requests. TM1 evaluates NON EMPTY and filters in the request's sandbox, so every request of an operation needs it, cellset reads and deletes included; a service given this view gets that for free. @throws RangeError if name is blank
withoutSandbox
withoutSandbox(): Tm1SessionA view of this session whose requests run outside any sandbox, in base data: this session if it has no sandbox.
withChangeSet
withChangeSet(id: string): Tm1SessionA view of this session whose writes are recorded in change set id (from BeginChangeSet): each request gets TM1's !ChangeSet query option, unless it sets its own, so UndoChangeSet can revert them together. Like withSandbox, the view shares this session's login and connections; it keeps the sandbox, if any. @throws RangeError if id is blank
withoutChangeSet
withoutChangeSet(): Tm1SessionA view of this session whose writes go into no change set: this session if it has none.
withAsync
withAsync(every: number): Tm1Session@param every how often to poll, in milliseconds
withoutAsync
withoutAsync(): Tm1SessionA view of this session whose requests run synchronously, as usual: this session if it isn't async.
batch
batch(): Tm1SessionBatchStarts a JSON $batch: its Tm1SessionBatch.session is a view of this one whose requests are queued, and run() sends them.
connect
connect(options?: Tm1CallOptions): Promise<Tm1Session>Logs in now, rather than on the first request.
sessionId
sessionId(options?: Tm1CallOptions): Promise<number>The session's ID on TM1 (ActiveSession), logging in if needed.
close
close(): Promise<void>Ends the session on the server, for every view.
[Symbol.asyncDispose]
[Symbol.asyncDispose](): Promise<void>Ends the session on the server, for await using: the same as close.
version
version(options?: Tm1CallOptions): Promise<Tm1Version>The server's product version, such as 11.8.03500.6, read from Server.ProductVersion once per login. Logs in first if needed.
capabilities
capabilities(options?: Tm1CallOptions): Promise<Tm1Capabilities>What the server supports, from its own $metadata. Fetched once per server version and shared by every session built from the same settings, a pool's included. A request that declares Tm1Request.requires is checked against it before it's sent.
execute
execute<T>(request: Tm1Request<T>, options?: Tm1CallOptions): Promise<T>Sends a request and reads its answer. Collections are read with stream. In a batch, the promise settles once the batch has run.
stream
stream<T>(request: Tm1Request<T>, options?: Tm1CallOptions): Tm1Stream<T>The items of a collection, fetching pages as they're needed (Java's stream). In a batch, the request joins the batch at once, and its items are there once the batch has run.
A next link is followed with ordinary requests on the same session, in every view: the pages after the first aren't part of an async request or of a batch. (TM1 11.8 doesn't page, so that is untested against a server.)
check
check(requirement: Tm1Capability | undefined, options: Tm1CallOptions | undefined): Promise<void>@internal Fails if the server doesn't define what a request requires, unless the session was told not to check.
target
target(relative: string): string@internal The URL of a path and query, with the view's !sandbox and !ChangeSet unless the request sets its own.
contextual
contextual(relative: string): string@internal
read
read<T>(request: Tm1Request<T>, reply: Reply): T@internal
toString
toString(): stringThe session, its service root and its view (sandbox, change set, async), for logs. No credentials.