@temporalio/common 1.1.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/activity-options.d.ts +138 -0
- package/lib/activity-options.js +15 -0
- package/lib/activity-options.js.map +1 -0
- package/lib/converter/data-converter.d.ts +20 -1
- package/lib/converter/data-converter.js +14 -3
- package/lib/converter/data-converter.js.map +1 -1
- package/lib/converter/failure-converter.d.ts +75 -0
- package/lib/converter/failure-converter.js +239 -0
- package/lib/converter/failure-converter.js.map +1 -0
- package/lib/converter/payload-codec.d.ts +1 -1
- package/lib/converter/payload-converter.d.ts +85 -1
- package/lib/converter/payload-converter.js +210 -1
- package/lib/converter/payload-converter.js.map +1 -1
- package/lib/converter/protobuf-payload-converters.d.ts +3 -3
- package/lib/converter/protobuf-payload-converters.js +20 -19
- package/lib/converter/protobuf-payload-converters.js.map +1 -1
- package/lib/converter/types.d.ts +0 -6
- package/lib/converter/types.js +7 -18
- package/lib/converter/types.js.map +1 -1
- package/lib/deprecated-time.d.ts +52 -0
- package/lib/deprecated-time.js +106 -0
- package/lib/deprecated-time.js.map +1 -0
- package/lib/{converter/encoding.d.ts → encoding.d.ts} +8 -0
- package/lib/{converter/encoding.js → encoding.js} +15 -1
- package/lib/encoding.js.map +1 -0
- package/lib/errors.d.ts +47 -0
- package/lib/errors.js +68 -0
- package/lib/errors.js.map +1 -0
- package/lib/failure.d.ts +0 -27
- package/lib/failure.js +9 -203
- package/lib/failure.js.map +1 -1
- package/lib/index.d.ts +25 -8
- package/lib/index.js +43 -7
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +18 -0
- package/lib/interceptors.js +24 -0
- package/lib/interceptors.js.map +1 -0
- package/lib/interfaces.d.ts +52 -0
- package/lib/interfaces.js +3 -0
- package/lib/interfaces.js.map +1 -0
- package/lib/internal-non-workflow/codec-helpers.d.ts +82 -0
- package/lib/internal-non-workflow/codec-helpers.js +295 -0
- package/lib/internal-non-workflow/codec-helpers.js.map +1 -0
- package/lib/internal-non-workflow/codec-types.d.ts +22 -0
- package/lib/internal-non-workflow/codec-types.js +3 -0
- package/lib/internal-non-workflow/codec-types.js.map +1 -0
- package/lib/internal-non-workflow/data-converter-helpers.d.ts +11 -0
- package/lib/internal-non-workflow/data-converter-helpers.js +66 -0
- package/lib/internal-non-workflow/data-converter-helpers.js.map +1 -0
- package/lib/internal-non-workflow/index.d.ts +10 -0
- package/lib/internal-non-workflow/index.js +27 -0
- package/lib/internal-non-workflow/index.js.map +1 -0
- package/lib/internal-non-workflow/tls-config.d.ts +32 -0
- package/lib/internal-non-workflow/tls-config.js +11 -0
- package/lib/internal-non-workflow/tls-config.js.map +1 -0
- package/lib/internal-non-workflow/utils.d.ts +4 -0
- package/lib/internal-non-workflow/utils.js +11 -0
- package/lib/internal-non-workflow/utils.js.map +1 -0
- package/lib/otel.d.ts +1 -1
- package/lib/otel.js +2 -2
- package/lib/otel.js.map +1 -1
- package/lib/retry-policy.d.ts +48 -0
- package/lib/retry-policy.js +62 -0
- package/lib/retry-policy.js.map +1 -0
- package/lib/time.d.ts +18 -0
- package/lib/time.js +79 -0
- package/lib/time.js.map +1 -0
- package/lib/type-helpers.d.ts +21 -0
- package/lib/type-helpers.js +46 -0
- package/lib/type-helpers.js.map +1 -0
- package/lib/workflow-handle.d.ts +27 -0
- package/lib/workflow-handle.js +3 -0
- package/lib/workflow-handle.js.map +1 -0
- package/lib/workflow-options.d.ts +118 -0
- package/lib/workflow-options.js +53 -0
- package/lib/workflow-options.js.map +1 -0
- package/package.json +5 -4
- package/src/activity-options.ts +159 -0
- package/src/converter/data-converter.ts +24 -3
- package/src/converter/failure-converter.ts +355 -0
- package/src/converter/payload-codec.ts +1 -1
- package/src/converter/payload-converter.ts +246 -1
- package/src/converter/protobuf-payload-converters.ts +14 -25
- package/src/converter/types.ts +6 -19
- package/src/deprecated-time.ts +80 -0
- package/src/{converter/encoding.ts → encoding.ts} +14 -0
- package/src/errors.ts +55 -0
- package/src/failure.ts +3 -251
- package/src/index.ts +34 -8
- package/src/interceptors.ts +32 -0
- package/src/interfaces.ts +64 -0
- package/src/internal-non-workflow/codec-helpers.ts +348 -0
- package/src/internal-non-workflow/codec-types.ts +34 -0
- package/src/internal-non-workflow/data-converter-helpers.ts +81 -0
- package/src/internal-non-workflow/index.ts +10 -0
- package/src/internal-non-workflow/tls-config.ts +35 -0
- package/src/internal-non-workflow/utils.ts +6 -0
- package/src/otel.ts +2 -2
- package/src/retry-policy.ts +101 -0
- package/src/time.ts +79 -0
- package/src/type-helpers.ts +64 -0
- package/src/workflow-handle.ts +30 -0
- package/src/workflow-options.ts +156 -0
- package/lib/converter/encoding.js.map +0 -1
- package/lib/converter/json-payload-converter.d.ts +0 -10
- package/lib/converter/json-payload-converter.js +0 -39
- package/lib/converter/json-payload-converter.js.map +0 -1
- package/lib/converter/payload-converters.d.ts +0 -67
- package/lib/converter/payload-converters.js +0 -124
- package/lib/converter/payload-converters.js.map +0 -1
- package/lib/converter/search-attribute-payload-converter.d.ts +0 -12
- package/lib/converter/search-attribute-payload-converter.js +0 -64
- package/lib/converter/search-attribute-payload-converter.js.map +0 -1
- package/src/converter/json-payload-converter.ts +0 -37
- package/src/converter/payload-converters.ts +0 -148
- package/src/converter/search-attribute-payload-converter.ts +0 -71
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchAttributePayloadConverter = void 0;
|
|
4
|
-
const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
5
|
-
const json_payload_converter_1 = require("./json-payload-converter");
|
|
6
|
-
const types_1 = require("./types");
|
|
7
|
-
const jsonConverter = new json_payload_converter_1.JsonPayloadConverter();
|
|
8
|
-
const validNonDateTypes = ['string', 'number', 'boolean'];
|
|
9
|
-
/**
|
|
10
|
-
* Converts Search Attribute values using JsonPayloadConverter
|
|
11
|
-
*/
|
|
12
|
-
class SearchAttributePayloadConverter {
|
|
13
|
-
toPayload(values) {
|
|
14
|
-
if (!(values instanceof Array)) {
|
|
15
|
-
throw new internal_workflow_common_1.ValueError(`SearchAttribute value must be an array`);
|
|
16
|
-
}
|
|
17
|
-
if (values.length > 0) {
|
|
18
|
-
const firstValue = values[0];
|
|
19
|
-
const firstType = typeof firstValue;
|
|
20
|
-
if (firstType === 'object') {
|
|
21
|
-
for (const idx in values) {
|
|
22
|
-
const value = values[idx];
|
|
23
|
-
if (!(value instanceof Date)) {
|
|
24
|
-
throw new internal_workflow_common_1.ValueError(`SearchAttribute values must arrays of strings, numbers, booleans, or Dates. The value ${value} at index ${idx} is of type ${typeof value}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
if (!validNonDateTypes.includes(firstType)) {
|
|
30
|
-
throw new internal_workflow_common_1.ValueError(`SearchAttribute array values must be: string | number | boolean | Date`);
|
|
31
|
-
}
|
|
32
|
-
for (const idx in values) {
|
|
33
|
-
const value = values[idx];
|
|
34
|
-
if (typeof value !== firstType) {
|
|
35
|
-
throw new internal_workflow_common_1.ValueError(`All SearchAttribute array values must be of the same type. The first value ${firstValue} of type ${firstType} doesn't match value ${value} of type ${typeof value} at index ${idx}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
// JSON.stringify takes care of converting Dates to ISO strings
|
|
41
|
-
const ret = jsonConverter.toPayload(values);
|
|
42
|
-
if (ret === undefined) {
|
|
43
|
-
throw new internal_workflow_common_1.IllegalStateError('Could not convert search attributes to payloads');
|
|
44
|
-
}
|
|
45
|
-
return ret;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Datetime Search Attribute values are converted to `Date`s
|
|
49
|
-
*/
|
|
50
|
-
fromPayload(payload) {
|
|
51
|
-
if (payload.metadata === undefined || payload.metadata === null) {
|
|
52
|
-
throw new internal_workflow_common_1.ValueError('Missing payload metadata');
|
|
53
|
-
}
|
|
54
|
-
const value = jsonConverter.fromPayload(payload);
|
|
55
|
-
let arrayWrappedValue = value instanceof Array ? value : [value];
|
|
56
|
-
const searchAttributeType = (0, types_1.str)(payload.metadata.type);
|
|
57
|
-
if (searchAttributeType === 'Datetime') {
|
|
58
|
-
arrayWrappedValue = arrayWrappedValue.map((dateString) => new Date(dateString));
|
|
59
|
-
}
|
|
60
|
-
return arrayWrappedValue;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.SearchAttributePayloadConverter = SearchAttributePayloadConverter;
|
|
64
|
-
//# sourceMappingURL=search-attribute-payload-converter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-attribute-payload-converter.js","sourceRoot":"","sources":["../../src/converter/search-attribute-payload-converter.ts"],"names":[],"mappings":";;;AAAA,mFAAqF;AAErF,qEAAgE;AAChE,mCAAuC;AAEvC,MAAM,aAAa,GAAG,IAAI,6CAAoB,EAAE,CAAC;AACjD,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAa,+BAA+B;IACnC,SAAS,CAAC,MAAe;QAC9B,IAAI,CAAC,CAAC,MAAM,YAAY,KAAK,CAAC,EAAE;YAC9B,MAAM,IAAI,qCAAU,CAAC,wCAAwC,CAAC,CAAC;SAChE;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACrB,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC7B,MAAM,SAAS,GAAG,OAAO,UAAU,CAAC;YACpC,IAAI,SAAS,KAAK,QAAQ,EAAE;gBAC1B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;oBACxB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;oBAC1B,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,EAAE;wBAC5B,MAAM,IAAI,qCAAU,CAClB,yFAAyF,KAAK,aAAa,GAAG,eAAe,OAAO,KAAK,EAAE,CAC5I,CAAC;qBACH;iBACF;aACF;iBAAM;gBACL,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;oBAC1C,MAAM,IAAI,qCAAU,CAAC,wEAAwE,CAAC,CAAC;iBAChG;gBAED,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;oBACxB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;oBAC1B,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;wBAC9B,MAAM,IAAI,qCAAU,CAClB,8EAA8E,UAAU,YAAY,SAAS,wBAAwB,KAAK,YAAY,OAAO,KAAK,aAAa,GAAG,EAAE,CACrL,CAAC;qBACH;iBACF;aACF;SACF;QAED,+DAA+D;QAC/D,MAAM,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,MAAM,IAAI,4CAAiB,CAAC,iDAAiD,CAAC,CAAC;SAChF;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;OAEG;IACI,WAAW,CAAI,OAAgB;QACpC,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE;YAC/D,MAAM,IAAI,qCAAU,CAAC,0BAA0B,CAAC,CAAC;SAClD;QAED,MAAM,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,iBAAiB,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAEjE,MAAM,mBAAmB,GAAG,IAAA,WAAG,EAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvD,IAAI,mBAAmB,KAAK,UAAU,EAAE;YACtC,iBAAiB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;SACjF;QACD,OAAO,iBAAiC,CAAC;IAC3C,CAAC;CACF;AA3DD,0EA2DC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ValueError } from '@temporalio/internal-workflow-common';
|
|
2
|
-
import { PayloadConverterWithEncoding } from './payload-converters';
|
|
3
|
-
import { encodingKeys, encodingTypes, METADATA_ENCODING_KEY, Payload, str, u8 } from './types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Converts between non-undefined values and serialized JSON Payload
|
|
7
|
-
*/
|
|
8
|
-
export class JsonPayloadConverter implements PayloadConverterWithEncoding {
|
|
9
|
-
public encodingType = encodingTypes.METADATA_ENCODING_JSON;
|
|
10
|
-
|
|
11
|
-
public toPayload(value: unknown): Payload | undefined {
|
|
12
|
-
if (value === undefined) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let json;
|
|
17
|
-
try {
|
|
18
|
-
json = JSON.stringify(value);
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
metadata: {
|
|
25
|
-
[METADATA_ENCODING_KEY]: encodingKeys.METADATA_ENCODING_JSON,
|
|
26
|
-
},
|
|
27
|
-
data: u8(json),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public fromPayload<T>(content: Payload): T {
|
|
32
|
-
if (content.data === undefined || content.data === null) {
|
|
33
|
-
throw new ValueError('Got payload with no data');
|
|
34
|
-
}
|
|
35
|
-
return JSON.parse(str(content.data));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { PayloadConverterError, ValueError } from '@temporalio/internal-workflow-common';
|
|
2
|
-
import { JsonPayloadConverter } from './json-payload-converter';
|
|
3
|
-
import { PayloadConverter } from './payload-converter';
|
|
4
|
-
import { SearchAttributePayloadConverter } from './search-attribute-payload-converter';
|
|
5
|
-
import { encodingKeys, encodingTypes, METADATA_ENCODING_KEY, Payload, str } from './types';
|
|
6
|
-
|
|
7
|
-
export interface PayloadConverterWithEncoding {
|
|
8
|
-
/**
|
|
9
|
-
* Converts a value to a {@link Payload}.
|
|
10
|
-
*
|
|
11
|
-
* @param value The value to convert. Example values include the Workflow args sent from the Client and the values returned by a Workflow or Activity.
|
|
12
|
-
* @returns The {@link Payload}, or `undefined` if unable to convert.
|
|
13
|
-
*/
|
|
14
|
-
toPayload<T>(value: T): Payload | undefined;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Converts a {@link Payload} back to a value.
|
|
18
|
-
*/
|
|
19
|
-
fromPayload<T>(payload: Payload): T;
|
|
20
|
-
|
|
21
|
-
readonly encodingType: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Tries to convert values to {@link Payload}s using the {@link PayloadConverterWithEncoding}s provided to the constructor, in the order provided.
|
|
26
|
-
*
|
|
27
|
-
* Converts Payloads to values based on the `Payload.metadata.encoding` field, which matches the {@link PayloadConverterWithEncoding.encodingType}
|
|
28
|
-
* of the converter that created the Payload.
|
|
29
|
-
*/
|
|
30
|
-
export class CompositePayloadConverter implements PayloadConverter {
|
|
31
|
-
readonly converters: PayloadConverterWithEncoding[];
|
|
32
|
-
readonly converterByEncoding: Map<string, PayloadConverterWithEncoding> = new Map();
|
|
33
|
-
|
|
34
|
-
constructor(...converters: PayloadConverterWithEncoding[]) {
|
|
35
|
-
if (converters.length === 0) {
|
|
36
|
-
throw new PayloadConverterError('Must provide at least one PayloadConverterWithEncoding');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.converters = converters;
|
|
40
|
-
for (const converter of converters) {
|
|
41
|
-
this.converterByEncoding.set(converter.encodingType, converter);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Tries to run `.toPayload(value)` on each converter in the order provided at construction.
|
|
47
|
-
* Returns the first successful result, throws {@link ValueError} if there is no converter that can handle the value.
|
|
48
|
-
*/
|
|
49
|
-
public toPayload<T>(value: T): Payload {
|
|
50
|
-
for (const converter of this.converters) {
|
|
51
|
-
const result = converter.toPayload(value);
|
|
52
|
-
if (result !== undefined) {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
throw new ValueError(`Unable to convert ${value} to payload`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the {@link encodingTypes | encoding type} of the {@link Payload}.
|
|
62
|
-
*/
|
|
63
|
-
public fromPayload<T>(payload: Payload): T {
|
|
64
|
-
if (payload.metadata === undefined || payload.metadata === null) {
|
|
65
|
-
throw new ValueError('Missing payload metadata');
|
|
66
|
-
}
|
|
67
|
-
const encoding = str(payload.metadata[METADATA_ENCODING_KEY]);
|
|
68
|
-
const converter = this.converterByEncoding.get(encoding);
|
|
69
|
-
if (converter === undefined) {
|
|
70
|
-
throw new ValueError(`Unknown encoding: ${encoding}`);
|
|
71
|
-
}
|
|
72
|
-
return converter.fromPayload(payload);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Converts between JS undefined and NULL Payload
|
|
78
|
-
*/
|
|
79
|
-
export class UndefinedPayloadConverter implements PayloadConverterWithEncoding {
|
|
80
|
-
public encodingType = encodingTypes.METADATA_ENCODING_NULL;
|
|
81
|
-
|
|
82
|
-
public toPayload(value: unknown): Payload | undefined {
|
|
83
|
-
if (value !== undefined) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
metadata: {
|
|
89
|
-
[METADATA_ENCODING_KEY]: encodingKeys.METADATA_ENCODING_NULL,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public fromPayload<T>(_content: Payload): T {
|
|
95
|
-
return undefined as any; // Just return undefined
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Converts between binary data types and RAW Payload
|
|
101
|
-
*/
|
|
102
|
-
export class BinaryPayloadConverter implements PayloadConverterWithEncoding {
|
|
103
|
-
public encodingType = encodingTypes.METADATA_ENCODING_RAW;
|
|
104
|
-
|
|
105
|
-
public toPayload(value: unknown): Payload | undefined {
|
|
106
|
-
// TODO: support any DataView or ArrayBuffer?
|
|
107
|
-
if (!(value instanceof Uint8Array)) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
metadata: {
|
|
113
|
-
[METADATA_ENCODING_KEY]: encodingKeys.METADATA_ENCODING_RAW,
|
|
114
|
-
},
|
|
115
|
-
data: value,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public fromPayload<T>(content: Payload): T {
|
|
120
|
-
// TODO: support any DataView or ArrayBuffer?
|
|
121
|
-
return content.data as any;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export const searchAttributePayloadConverter = new SearchAttributePayloadConverter();
|
|
126
|
-
|
|
127
|
-
export class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
128
|
-
// Match the order used in other SDKs, but exclude Protobuf converters so that the code, including
|
|
129
|
-
// `proto3-json-serializer`, doesn't take space in Workflow bundles that don't use Protobufs. To use Protobufs, use
|
|
130
|
-
// {@link DefaultPayloadConverterWithProtobufs}.
|
|
131
|
-
//
|
|
132
|
-
// Go SDK:
|
|
133
|
-
// https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
134
|
-
constructor() {
|
|
135
|
-
super(new UndefinedPayloadConverter(), new BinaryPayloadConverter(), new JsonPayloadConverter());
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* The default {@link PayloadConverter} used by the SDK. Supports `Uint8Array` and JSON serializables (so if
|
|
141
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description | `JSON.stringify(yourArgOrRetval)`}
|
|
142
|
-
* works, the default payload converter will work).
|
|
143
|
-
*
|
|
144
|
-
* To also support Protobufs, create a custom payload converter with {@link DefaultPayloadConverter}:
|
|
145
|
-
*
|
|
146
|
-
* `const myConverter = new DefaultPayloadConverter({ protobufRoot })`
|
|
147
|
-
*/
|
|
148
|
-
export const defaultPayloadConverter = new DefaultPayloadConverter();
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { IllegalStateError, ValueError } from '@temporalio/internal-workflow-common';
|
|
2
|
-
import { PayloadConverter } from './payload-converter';
|
|
3
|
-
import { JsonPayloadConverter } from './json-payload-converter';
|
|
4
|
-
import { Payload, str } from './types';
|
|
5
|
-
|
|
6
|
-
const jsonConverter = new JsonPayloadConverter();
|
|
7
|
-
const validNonDateTypes = ['string', 'number', 'boolean'];
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Converts Search Attribute values using JsonPayloadConverter
|
|
11
|
-
*/
|
|
12
|
-
export class SearchAttributePayloadConverter implements PayloadConverter {
|
|
13
|
-
public toPayload(values: unknown): Payload {
|
|
14
|
-
if (!(values instanceof Array)) {
|
|
15
|
-
throw new ValueError(`SearchAttribute value must be an array`);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (values.length > 0) {
|
|
19
|
-
const firstValue = values[0];
|
|
20
|
-
const firstType = typeof firstValue;
|
|
21
|
-
if (firstType === 'object') {
|
|
22
|
-
for (const idx in values) {
|
|
23
|
-
const value = values[idx];
|
|
24
|
-
if (!(value instanceof Date)) {
|
|
25
|
-
throw new ValueError(
|
|
26
|
-
`SearchAttribute values must arrays of strings, numbers, booleans, or Dates. The value ${value} at index ${idx} is of type ${typeof value}`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
if (!validNonDateTypes.includes(firstType)) {
|
|
32
|
-
throw new ValueError(`SearchAttribute array values must be: string | number | boolean | Date`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
for (const idx in values) {
|
|
36
|
-
const value = values[idx];
|
|
37
|
-
if (typeof value !== firstType) {
|
|
38
|
-
throw new ValueError(
|
|
39
|
-
`All SearchAttribute array values must be of the same type. The first value ${firstValue} of type ${firstType} doesn't match value ${value} of type ${typeof value} at index ${idx}`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// JSON.stringify takes care of converting Dates to ISO strings
|
|
47
|
-
const ret = jsonConverter.toPayload(values);
|
|
48
|
-
if (ret === undefined) {
|
|
49
|
-
throw new IllegalStateError('Could not convert search attributes to payloads');
|
|
50
|
-
}
|
|
51
|
-
return ret;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Datetime Search Attribute values are converted to `Date`s
|
|
56
|
-
*/
|
|
57
|
-
public fromPayload<T>(payload: Payload): T {
|
|
58
|
-
if (payload.metadata === undefined || payload.metadata === null) {
|
|
59
|
-
throw new ValueError('Missing payload metadata');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const value = jsonConverter.fromPayload(payload);
|
|
63
|
-
let arrayWrappedValue = value instanceof Array ? value : [value];
|
|
64
|
-
|
|
65
|
-
const searchAttributeType = str(payload.metadata.type);
|
|
66
|
-
if (searchAttributeType === 'Datetime') {
|
|
67
|
-
arrayWrappedValue = arrayWrappedValue.map((dateString) => new Date(dateString));
|
|
68
|
-
}
|
|
69
|
-
return arrayWrappedValue as unknown as T;
|
|
70
|
-
}
|
|
71
|
-
}
|