@temporalio/client
Advanced tools
Comparing version 0.1.5 to 0.2.0
@@ -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" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29492
591
+ Addedgrpc@^1.24.9
+ Added@mapbox/node-pre-gyp@1.0.11(transitive)
+ Added@temporalio/core-bridge@0.2.0(transitive)
+ Added@temporalio/proto@0.2.4(transitive)
+ Added@temporalio/workflow@0.2.1(transitive)
+ Added@types/bytebuffer@5.0.49(transitive)
+ Added@types/long@3.0.32(transitive)
+ Addedabbrev@1.1.1(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.0(transitive)
+ Addedascli@1.0.1(transitive)
+ Addedbytebuffer@5.0.1(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcargo-cp-artifact@0.1.9(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedcliui@3.2.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcolour@0.7.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedgauge@3.0.2(transitive)
+ Addedgrpc@1.24.11(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedinvert-kv@1.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedlcid@1.0.0(transitive)
+ Addedlodash.clone@4.5.0(transitive)
+ Addedlong@3.2.0(transitive)
+ Addedmake-dir@3.1.0(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addednan@2.20.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedoptjs@3.2.2(transitive)
+ Addedos-locale@1.4.0(transitive)
+ Addedprotobufjs@5.0.3(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@6.3.17.6.3(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwindow-size@0.1.4(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs@3.32.0(transitive)
- Removed@grpc/grpc-js@^1.2.12
- Removed@grpc/grpc-js@1.11.2(transitive)
- Removed@grpc/proto-loader@0.7.13(transitive)
- Removed@js-sdsl/ordered-map@4.4.2(transitive)
- Removed@temporalio/proto@0.1.5(transitive)
- Removed@temporalio/workflow@0.1.5(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedcliui@8.0.1(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedescalade@3.2.0(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedlong@5.2.3(transitive)
- Removedprotobufjs@7.4.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyargs@17.7.2(transitive)
- Removedyargs-parser@21.1.1(transitive)
Updated@temporalio/proto@^0.2.0
Updated@temporalio/workflow@^0.2.0