Socket
Socket
Sign inDemoInstall

@temporalio/client

Package Overview
Dependencies
Maintainers
4
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@temporalio/client - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

58

lib/index.d.ts

@@ -11,6 +11,6 @@ /**

*/
import * as grpc from '@grpc/grpc-js';
import * as grpc from 'grpc';
import * as iface from '@temporalio/proto';
import { Workflow, WorkflowSignalType, WorkflowQueryType } from '@temporalio/workflow/commonjs/interfaces';
import { DataConverter } from '@temporalio/workflow/commonjs/converter/data-converter';
import { Workflow, WorkflowSignalType, WorkflowQueryType } from '@temporalio/workflow/lib/interfaces';
import { DataConverter } from '@temporalio/workflow/lib/converter/data-converter';
export declare type DescribeWorkflowExecutionResponse = iface.temporal.api.workflowservice.v1.IDescribeWorkflowExecutionResponse;

@@ -120,12 +120,36 @@ export declare type TerminateWorkflowExecutionResponse = iface.temporal.api.workflowservice.v1.ITerminateWorkflowExecutionResponse;

}
export interface ServiceOptions {
/**
* GRPC + Temporal server connection options
*/
export interface ConnectionOptions {
/**
* Server address and port
*/
address?: string;
/**
* Channel credentials, create using the factory methods defined {@link https://grpc.github.io/grpc/node/grpc.credentials.html | here}
*/
credentials?: grpc.ChannelCredentials;
}
export declare type ServiceOptionsWithDefaults = Required<ServiceOptions>;
export declare function defaultServiceOptions(): ServiceOptionsWithDefaults;
export interface ConnectionOptions {
/**
* Namespace to use in {@link Connection} methods
*
* @default default
*/
namespace?: string;
/**
* Identity to report to the server
*
* @default `${process.pid}@${os.hostname()}`
*/
identity?: string;
/**
* {@link DataConverter} to use for serializing and deserializing payloads
*/
dataConverter?: DataConverter;
/**
* GRPC Channel arguments
*
* @see options {@link https://grpc.github.io/grpc/core/group__grpc__arg__keys.html | here}
*/
channelArgs?: Record<string, any>;
}

@@ -184,3 +208,3 @@ export declare type ConnectionOptionsWithDefaults = Required<ConnectionOptions>;

*
* @format ms formatted string
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
*/

@@ -194,3 +218,3 @@ workflowRunTimeout?: string;

*
* @format ms formatted string
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
*/

@@ -201,3 +225,3 @@ workflowExecutionTimeout?: string;

*
* @format ms formatted string
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
*/

@@ -223,7 +247,15 @@ workflowTaskTimeout?: string;

export declare class Connection {
static readonly Client: import("@grpc/grpc-js/build/src/make-client").ServiceClientConstructor;
static readonly Client: typeof grpc.Client;
readonly options: ConnectionOptionsWithDefaults;
readonly client: grpc.Client;
readonly service: WorkflowService;
constructor(svcOpts?: ServiceOptions, connOpts?: ConnectionOptions);
constructor(options?: ConnectionOptions);
/**
* Wait for successful connection to the server.
*
* @param waitTimeMs milliseconds to wait before giving up.
*
* @see https://grpc.github.io/grpc/node/grpc.Client.html#waitForReady__anchor
*/
untilReady(waitTimeMs?: number): Promise<void>;
startWorkflowExecution(opts: CompiledWorkflowOptionsWithDefaults, name: string, ...args: any[]): Promise<string>;

@@ -230,0 +262,0 @@ untilComplete(workflowId: string, runId: string): Promise<unknown>;

@@ -35,14 +35,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryRejectedError = exports.Connection = exports.compileWorkflowOptions = exports.addDefaults = exports.defaultConnectionOpts = exports.defaultServiceOptions = exports.WorkflowService = void 0;
exports.QueryRejectedError = exports.Connection = exports.compileWorkflowOptions = exports.addDefaults = exports.defaultConnectionOpts = exports.WorkflowService = void 0;
const os_1 = __importDefault(require("os"));
const grpc = __importStar(require("@grpc/grpc-js"));
const grpc = __importStar(require("grpc"));
const uuid_1 = require("uuid");
const ms_1 = __importDefault(require("ms"));
const iface = __importStar(require("@temporalio/proto"));
const time_1 = require("@temporalio/workflow/commonjs/time");
const common_1 = require("@temporalio/workflow/commonjs/common");
const data_converter_1 = require("@temporalio/workflow/commonjs/converter/data-converter");
const errors = __importStar(require("@temporalio/workflow/commonjs/errors"));
const time_1 = require("@temporalio/workflow/lib/time");
const common_1 = require("@temporalio/workflow/lib/common");
const data_converter_1 = require("@temporalio/workflow/lib/converter/data-converter");
const errors = __importStar(require("@temporalio/workflow/lib/errors"));
exports.WorkflowService = iface.temporal.api.workflowservice.v1.WorkflowService;
function defaultServiceOptions() {
function defaultConnectionOpts() {
return {

@@ -52,7 +52,2 @@ // LOCAL_DOCKER_TARGET

credentials: grpc.credentials.createInsecure(),
};
}
exports.defaultServiceOptions = defaultServiceOptions;
function defaultConnectionOpts() {
return {
namespace: 'default',

@@ -62,2 +57,3 @@ dataConverter: data_converter_1.defaultDataConverter,

identity: `${process.pid}@${os_1.default.hostname()}`,
channelArgs: {},
};

@@ -90,6 +86,5 @@ }

class Connection {
constructor(svcOpts, connOpts) {
this.options = { ...defaultConnectionOpts(), ...connOpts };
const serviceOptions = { ...defaultServiceOptions(), ...svcOpts };
this.client = new Connection.Client(serviceOptions.address, serviceOptions.credentials, {});
constructor(options) {
this.options = { ...defaultConnectionOpts(), ...options };
this.client = new Connection.Client(this.options.address, this.options.credentials, this.options.channelArgs);
const rpcImpl = (method, requestData, callback) => {

@@ -102,2 +97,21 @@ return this.client.makeUnaryRequest(`/temporal.api.workflowservice.v1.WorkflowService/${method.name}`, (arg) => arg, (arg) => arg, requestData,

}
/**
* Wait for successful connection to the server.
*
* @param waitTimeMs milliseconds to wait before giving up.
*
* @see https://grpc.github.io/grpc/node/grpc.Client.html#waitForReady__anchor
*/
async untilReady(waitTimeMs = 5000) {
new Promise((resolve, reject) => {
this.client.waitForReady(Date.now() + waitTimeMs, (err) => {
if (err) {
reject(err);
}
else {
resolve();
}
});
});
}
async startWorkflowExecution(opts, name, ...args) {

@@ -133,3 +147,2 @@ const { namespace, identity, dataConverter } = this.options;

async untilComplete(workflowId, runId) {
var _a, _b, _c, _d;
const req = {

@@ -165,13 +178,13 @@ namespace: this.options.namespace,

// Ignore any other payloads in result
const [result] = data_converter_1.arrayFromPayloads(this.options.dataConverter, (_a = ev.workflowExecutionCompletedEventAttributes.result) === null || _a === void 0 ? void 0 : _a.payloads);
const [result] = data_converter_1.arrayFromPayloads(this.options.dataConverter, ev.workflowExecutionCompletedEventAttributes.result?.payloads);
return result;
}
else if (ev.workflowExecutionFailedEventAttributes) {
throw new errors.WorkflowExecutionFailedError(((_b = ev.workflowExecutionFailedEventAttributes.failure) === null || _b === void 0 ? void 0 : _b.message) || 'Workflow failed without failure message');
throw new errors.WorkflowExecutionFailedError(ev.workflowExecutionFailedEventAttributes.failure?.message || 'Workflow failed without failure message');
}
else if (ev.workflowExecutionCanceledEventAttributes) {
throw new errors.WorkflowExecutionCancelledError('Workflow execution cancelled', data_converter_1.arrayFromPayloads(this.options.dataConverter, (_c = ev.workflowExecutionCanceledEventAttributes.details) === null || _c === void 0 ? void 0 : _c.payloads));
throw new errors.WorkflowExecutionCancelledError('Workflow execution cancelled', data_converter_1.arrayFromPayloads(this.options.dataConverter, ev.workflowExecutionCanceledEventAttributes.details?.payloads));
}
else if (ev.workflowExecutionTerminatedEventAttributes) {
throw new errors.WorkflowExecutionTerminatedError(ev.workflowExecutionTerminatedEventAttributes.reason || 'Workflow execution terminated', data_converter_1.arrayFromPayloads(this.options.dataConverter, (_d = ev.workflowExecutionTerminatedEventAttributes.details) === null || _d === void 0 ? void 0 : _d.payloads), time_1.nullToUndefined(ev.workflowExecutionTerminatedEventAttributes.identity));
throw new errors.WorkflowExecutionTerminatedError(ev.workflowExecutionTerminatedEventAttributes.reason || 'Workflow execution terminated', data_converter_1.arrayFromPayloads(this.options.dataConverter, ev.workflowExecutionTerminatedEventAttributes.details?.payloads), time_1.nullToUndefined(ev.workflowExecutionTerminatedEventAttributes.identity));
}

@@ -287,3 +300,2 @@ else if (ev.workflowExecutionTimedOutEventAttributes) {

return async (...args) => {
var _a;
const response = await this.service.queryWorkflow({

@@ -305,3 +317,3 @@ // TODO: queryRejectCondition

// We ignore anything but the first result
return this.options.dataConverter.fromPayloads(0, (_a = response.queryResult) === null || _a === void 0 ? void 0 : _a.payloads);
return this.options.dataConverter.fromPayloads(0, response.queryResult?.payloads);
};

@@ -308,0 +320,0 @@ },

{
"name": "@temporalio/client",
"version": "0.1.5",
"version": "0.2.0",
"description": "Temporal.io SDK Client sub-package",

@@ -16,5 +16,5 @@ "main": "lib/index.js",

"dependencies": {
"@grpc/grpc-js": "^1.2.12",
"@temporalio/proto": "^0.1.5",
"@temporalio/workflow": "^0.1.5",
"@temporalio/proto": "^0.2.0",
"@temporalio/workflow": "^0.2.0",
"grpc": "^1.24.9",
"ms": "^2.1.3",

@@ -34,3 +34,3 @@ "protobufjs": "^6.10.2",

},
"gitHead": "04add82114c495399c4c5d438ea1ce161673fd8b"
"gitHead": "5489bd5bac5ba5c2142c0bb5a081d0eeb90fa53e"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc