@temporalio/client
Version:
Temporal.io SDK Client sub-package
74 lines • 3.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseClient = void 0;
exports.defaultBaseClientOptions = defaultBaseClientOptions;
const node_os_1 = __importDefault(require("node:os"));
const internal_non_workflow_1 = require("@temporalio/common/lib/internal-non-workflow");
const connection_1 = require("./connection");
function defaultBaseClientOptions() {
return {
dataConverter: {},
identity: `${process.pid}@${node_os_1.default.hostname()}`,
namespace: 'default',
};
}
class BaseClient {
constructor(options) {
this.connection = options?.connection ?? connection_1.Connection.lazy();
const dataConverter = options?.dataConverter ?? {};
this.loadedDataConverter = (0, internal_non_workflow_1.isLoadedDataConverter)(dataConverter) ? dataConverter : (0, internal_non_workflow_1.loadDataConverter)(dataConverter);
}
/**
* Set a deadline for any service requests executed in `fn`'s scope.
*
* The deadline is a point in time after which any pending gRPC request will be considered as failed;
* this will locally result in the request call throwing a {@link _grpc.ServiceError|ServiceError}
* with code {@link _grpc.status.DEADLINE_EXCEEDED|DEADLINE_EXCEEDED}; see {@link isGrpcDeadlineError}.
*
* It is stronly recommended to explicitly set deadlines. If no deadline is set, then it is
* possible for the client to end up waiting forever for a response.
*
* This method is only a convenience wrapper around {@link Connection.withDeadline}.
*
* @param deadline a point in time after which the request will be considered as failed; either a
* Date object, or a number of milliseconds since the Unix epoch (UTC).
* @returns the value returned from `fn`
*
* @see https://grpc.io/docs/guides/deadlines/
*/
async withDeadline(deadline, fn) {
return await this.connection.withDeadline(deadline, fn);
}
/**
* Set an {@link AbortSignal} that, when aborted, cancels any ongoing service requests executed in
* `fn`'s scope. This will locally result in the request call throwing a {@link _grpc.ServiceError|ServiceError}
* with code {@link _grpc.status.CANCELLED|CANCELLED}; see {@link isGrpcCancelledError}.
*
* This method is only a convenience wrapper around {@link Connection.withAbortSignal}.
*
* @returns value returned from `fn`
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
*/
async withAbortSignal(abortSignal, fn) {
return await this.connection.withAbortSignal(abortSignal, fn);
}
/**
* Set metadata for any service requests executed in `fn`'s scope.
*
* This method is only a convenience wrapper around {@link Connection.withMetadata}.
*
* @returns returned value of `fn`
*/
async withMetadata(metadata, fn) {
return await this.connection.withMetadata(metadata, fn);
}
get dataConverter() {
return this.loadedDataConverter;
}
}
exports.BaseClient = BaseClient;
//# sourceMappingURL=base-client.js.map