@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,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapFromPayloads = exports.arrayFromPayloads = exports.fromPayloadsAtIndex = exports.mapToPayloads = exports.toPayloads = void 0;
|
|
3
|
+
exports.defaultPayloadConverter = exports.DefaultPayloadConverter = exports.searchAttributePayloadConverter = exports.SearchAttributePayloadConverter = exports.JsonPayloadConverter = exports.BinaryPayloadConverter = exports.UndefinedPayloadConverter = exports.CompositePayloadConverter = exports.mapFromPayloads = exports.arrayFromPayloads = exports.fromPayloadsAtIndex = exports.mapToPayloads = exports.toPayloads = void 0;
|
|
4
|
+
const encoding_1 = require("../encoding");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const types_1 = require("./types");
|
|
4
7
|
/**
|
|
5
8
|
* Implements conversion of a list of values.
|
|
6
9
|
*
|
|
@@ -64,4 +67,210 @@ function mapFromPayloads(converter, map) {
|
|
|
64
67
|
}));
|
|
65
68
|
}
|
|
66
69
|
exports.mapFromPayloads = mapFromPayloads;
|
|
70
|
+
/**
|
|
71
|
+
* Tries to convert values to {@link Payload}s using the {@link PayloadConverterWithEncoding}s provided to the constructor, in the order provided.
|
|
72
|
+
*
|
|
73
|
+
* Converts Payloads to values based on the `Payload.metadata.encoding` field, which matches the {@link PayloadConverterWithEncoding.encodingType}
|
|
74
|
+
* of the converter that created the Payload.
|
|
75
|
+
*/
|
|
76
|
+
class CompositePayloadConverter {
|
|
77
|
+
constructor(...converters) {
|
|
78
|
+
this.converterByEncoding = new Map();
|
|
79
|
+
if (converters.length === 0) {
|
|
80
|
+
throw new errors_1.PayloadConverterError('Must provide at least one PayloadConverterWithEncoding');
|
|
81
|
+
}
|
|
82
|
+
this.converters = converters;
|
|
83
|
+
for (const converter of converters) {
|
|
84
|
+
this.converterByEncoding.set(converter.encodingType, converter);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Tries to run `.toPayload(value)` on each converter in the order provided at construction.
|
|
89
|
+
* Returns the first successful result, throws {@link ValueError} if there is no converter that can handle the value.
|
|
90
|
+
*/
|
|
91
|
+
toPayload(value) {
|
|
92
|
+
for (const converter of this.converters) {
|
|
93
|
+
const result = converter.toPayload(value);
|
|
94
|
+
if (result !== undefined) {
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
throw new errors_1.ValueError(`Unable to convert ${value} to payload`);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the `encoding` metadata of the {@link Payload}.
|
|
102
|
+
*/
|
|
103
|
+
fromPayload(payload) {
|
|
104
|
+
if (payload.metadata === undefined || payload.metadata === null) {
|
|
105
|
+
throw new errors_1.ValueError('Missing payload metadata');
|
|
106
|
+
}
|
|
107
|
+
const encoding = (0, encoding_1.decode)(payload.metadata[types_1.METADATA_ENCODING_KEY]);
|
|
108
|
+
const converter = this.converterByEncoding.get(encoding);
|
|
109
|
+
if (converter === undefined) {
|
|
110
|
+
throw new errors_1.ValueError(`Unknown encoding: ${encoding}`);
|
|
111
|
+
}
|
|
112
|
+
return converter.fromPayload(payload);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.CompositePayloadConverter = CompositePayloadConverter;
|
|
116
|
+
/**
|
|
117
|
+
* Converts between JS undefined and NULL Payload
|
|
118
|
+
*/
|
|
119
|
+
class UndefinedPayloadConverter {
|
|
120
|
+
constructor() {
|
|
121
|
+
this.encodingType = types_1.encodingTypes.METADATA_ENCODING_NULL;
|
|
122
|
+
}
|
|
123
|
+
toPayload(value) {
|
|
124
|
+
if (value !== undefined) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
metadata: {
|
|
129
|
+
[types_1.METADATA_ENCODING_KEY]: types_1.encodingKeys.METADATA_ENCODING_NULL,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
fromPayload(_content) {
|
|
134
|
+
return undefined; // Just return undefined
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.UndefinedPayloadConverter = UndefinedPayloadConverter;
|
|
138
|
+
/**
|
|
139
|
+
* Converts between binary data types and RAW Payload
|
|
140
|
+
*/
|
|
141
|
+
class BinaryPayloadConverter {
|
|
142
|
+
constructor() {
|
|
143
|
+
this.encodingType = types_1.encodingTypes.METADATA_ENCODING_RAW;
|
|
144
|
+
}
|
|
145
|
+
toPayload(value) {
|
|
146
|
+
if (!(value instanceof Uint8Array)) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
metadata: {
|
|
151
|
+
[types_1.METADATA_ENCODING_KEY]: types_1.encodingKeys.METADATA_ENCODING_RAW,
|
|
152
|
+
},
|
|
153
|
+
data: value,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
fromPayload(content) {
|
|
157
|
+
return content.data;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.BinaryPayloadConverter = BinaryPayloadConverter;
|
|
161
|
+
/**
|
|
162
|
+
* Converts between non-undefined values and serialized JSON Payload
|
|
163
|
+
*/
|
|
164
|
+
class JsonPayloadConverter {
|
|
165
|
+
constructor() {
|
|
166
|
+
this.encodingType = types_1.encodingTypes.METADATA_ENCODING_JSON;
|
|
167
|
+
}
|
|
168
|
+
toPayload(value) {
|
|
169
|
+
if (value === undefined) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
let json;
|
|
173
|
+
try {
|
|
174
|
+
json = JSON.stringify(value);
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
metadata: {
|
|
181
|
+
[types_1.METADATA_ENCODING_KEY]: types_1.encodingKeys.METADATA_ENCODING_JSON,
|
|
182
|
+
},
|
|
183
|
+
data: (0, encoding_1.encode)(json),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
fromPayload(content) {
|
|
187
|
+
if (content.data === undefined || content.data === null) {
|
|
188
|
+
throw new errors_1.ValueError('Got payload with no data');
|
|
189
|
+
}
|
|
190
|
+
return JSON.parse((0, encoding_1.decode)(content.data));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.JsonPayloadConverter = JsonPayloadConverter;
|
|
194
|
+
/**
|
|
195
|
+
* Converts Search Attribute values using JsonPayloadConverter
|
|
196
|
+
*/
|
|
197
|
+
class SearchAttributePayloadConverter {
|
|
198
|
+
constructor() {
|
|
199
|
+
this.jsonConverter = new JsonPayloadConverter();
|
|
200
|
+
this.validNonDateTypes = ['string', 'number', 'boolean'];
|
|
201
|
+
}
|
|
202
|
+
toPayload(values) {
|
|
203
|
+
if (!(values instanceof Array)) {
|
|
204
|
+
throw new errors_1.ValueError(`SearchAttribute value must be an array`);
|
|
205
|
+
}
|
|
206
|
+
if (values.length > 0) {
|
|
207
|
+
const firstValue = values[0];
|
|
208
|
+
const firstType = typeof firstValue;
|
|
209
|
+
if (firstType === 'object') {
|
|
210
|
+
for (const idx in values) {
|
|
211
|
+
const value = values[idx];
|
|
212
|
+
if (!(value instanceof Date)) {
|
|
213
|
+
throw new errors_1.ValueError(`SearchAttribute values must arrays of strings, numbers, booleans, or Dates. The value ${value} at index ${idx} is of type ${typeof value}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
if (!this.validNonDateTypes.includes(firstType)) {
|
|
219
|
+
throw new errors_1.ValueError(`SearchAttribute array values must be: string | number | boolean | Date`);
|
|
220
|
+
}
|
|
221
|
+
for (const idx in values) {
|
|
222
|
+
const value = values[idx];
|
|
223
|
+
if (typeof value !== firstType) {
|
|
224
|
+
throw new errors_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}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// JSON.stringify takes care of converting Dates to ISO strings
|
|
230
|
+
const ret = this.jsonConverter.toPayload(values);
|
|
231
|
+
if (ret === undefined) {
|
|
232
|
+
throw new errors_1.IllegalStateError('Could not convert search attributes to payloads');
|
|
233
|
+
}
|
|
234
|
+
return ret;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Datetime Search Attribute values are converted to `Date`s
|
|
238
|
+
*/
|
|
239
|
+
fromPayload(payload) {
|
|
240
|
+
if (payload.metadata === undefined || payload.metadata === null) {
|
|
241
|
+
throw new errors_1.ValueError('Missing payload metadata');
|
|
242
|
+
}
|
|
243
|
+
const value = this.jsonConverter.fromPayload(payload);
|
|
244
|
+
let arrayWrappedValue = value instanceof Array ? value : [value];
|
|
245
|
+
const searchAttributeType = (0, encoding_1.decode)(payload.metadata.type);
|
|
246
|
+
if (searchAttributeType === 'Datetime') {
|
|
247
|
+
arrayWrappedValue = arrayWrappedValue.map((dateString) => new Date(dateString));
|
|
248
|
+
}
|
|
249
|
+
return arrayWrappedValue;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.SearchAttributePayloadConverter = SearchAttributePayloadConverter;
|
|
253
|
+
exports.searchAttributePayloadConverter = new SearchAttributePayloadConverter();
|
|
254
|
+
class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
255
|
+
// Match the order used in other SDKs, but exclude Protobuf converters so that the code, including
|
|
256
|
+
// `proto3-json-serializer`, doesn't take space in Workflow bundles that don't use Protobufs. To use Protobufs, use
|
|
257
|
+
// {@link DefaultPayloadConverterWithProtobufs}.
|
|
258
|
+
//
|
|
259
|
+
// Go SDK:
|
|
260
|
+
// https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
261
|
+
constructor() {
|
|
262
|
+
super(new UndefinedPayloadConverter(), new BinaryPayloadConverter(), new JsonPayloadConverter());
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
exports.DefaultPayloadConverter = DefaultPayloadConverter;
|
|
266
|
+
/**
|
|
267
|
+
* The default {@link PayloadConverter} used by the SDK. Supports `Uint8Array` and JSON serializables (so if
|
|
268
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description | `JSON.stringify(yourArgOrRetval)`}
|
|
269
|
+
* works, the default payload converter will work).
|
|
270
|
+
*
|
|
271
|
+
* To also support Protobufs, create a custom payload converter with {@link DefaultPayloadConverter}:
|
|
272
|
+
*
|
|
273
|
+
* `const myConverter = new DefaultPayloadConverter({ protobufRoot })`
|
|
274
|
+
*/
|
|
275
|
+
exports.defaultPayloadConverter = new DefaultPayloadConverter();
|
|
67
276
|
//# sourceMappingURL=payload-converter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload-converter.js","sourceRoot":"","sources":["../../src/converter/payload-converter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"payload-converter.js","sourceRoot":"","sources":["../../src/converter/payload-converter.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAC7C,sCAAiF;AAEjF,mCAA6E;AA0B7E;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,SAA2B,EAAE,GAAG,MAAiB;IAC1E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3D,CAAC;AAND,gCAMC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAmB,SAA2B,EAAE,GAAmB;IAC9F,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,CAAM,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAC9D,CAAC;AAC1B,CAAC;AAJD,sCAIC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAI,SAA2B,EAAE,KAAa,EAAE,QAA2B;IAC5G,yDAAyD;IACzD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE;QAC3E,OAAO,SAAgB,CAAC;KACzB;IACD,OAAO,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,KA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 'protobufjs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Payload } from '../interfaces';
|
|
3
|
+
import { CompositePayloadConverter, PayloadConverterWithEncoding } from './payload-converter';
|
|
4
4
|
declare abstract class ProtobufPayloadConverter implements PayloadConverterWithEncoding {
|
|
5
5
|
protected readonly root: Root | undefined;
|
|
6
|
-
abstract encodingType:
|
|
6
|
+
abstract encodingType: string;
|
|
7
7
|
abstract toPayload<T>(value: T): Payload | undefined;
|
|
8
8
|
abstract fromPayload<T>(payload: Payload): T;
|
|
9
9
|
constructor(root?: unknown);
|
|
@@ -24,10 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.DefaultPayloadConverterWithProtobufs = exports.ProtobufJsonPayloadConverter = exports.ProtobufBinaryPayloadConverter = void 0;
|
|
27
|
-
const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
28
27
|
const protoJsonSerializer = __importStar(require("proto3-json-serializer"));
|
|
29
|
-
const
|
|
30
|
-
const
|
|
28
|
+
const encoding_1 = require("../encoding");
|
|
29
|
+
const errors_1 = require("../errors");
|
|
30
|
+
const type_helpers_1 = require("../type-helpers");
|
|
31
|
+
const payload_converter_1 = require("./payload-converter");
|
|
31
32
|
const types_1 = require("./types");
|
|
32
33
|
class ProtobufPayloadConverter {
|
|
33
34
|
// Don't use type Root here because root.d.ts doesn't export Root, so users would have to type assert
|
|
@@ -41,22 +42,22 @@ class ProtobufPayloadConverter {
|
|
|
41
42
|
}
|
|
42
43
|
validatePayload(content) {
|
|
43
44
|
if (content.data === undefined || content.data === null) {
|
|
44
|
-
throw new
|
|
45
|
+
throw new errors_1.ValueError('Got payload with no data');
|
|
45
46
|
}
|
|
46
47
|
if (!content.metadata || !(types_1.METADATA_MESSAGE_TYPE_KEY in content.metadata)) {
|
|
47
|
-
throw new
|
|
48
|
+
throw new errors_1.ValueError(`Got protobuf payload without metadata.${types_1.METADATA_MESSAGE_TYPE_KEY}`);
|
|
48
49
|
}
|
|
49
50
|
if (!this.root) {
|
|
50
|
-
throw new
|
|
51
|
+
throw new errors_1.PayloadConverterError('Unable to deserialize protobuf message without `root` being provided');
|
|
51
52
|
}
|
|
52
|
-
const messageTypeName = (0,
|
|
53
|
+
const messageTypeName = (0, encoding_1.decode)(content.metadata[types_1.METADATA_MESSAGE_TYPE_KEY]);
|
|
53
54
|
let messageType;
|
|
54
55
|
try {
|
|
55
56
|
messageType = this.root.lookupType(messageTypeName);
|
|
56
57
|
}
|
|
57
58
|
catch (e) {
|
|
58
|
-
if ((0,
|
|
59
|
-
throw new
|
|
59
|
+
if ((0, type_helpers_1.errorMessage)(e)?.includes('no such type')) {
|
|
60
|
+
throw new errors_1.PayloadConverterError(`Got a \`${messageTypeName}\` protobuf message but cannot find corresponding message class in \`root\``);
|
|
60
61
|
}
|
|
61
62
|
throw e;
|
|
62
63
|
}
|
|
@@ -65,8 +66,8 @@ class ProtobufPayloadConverter {
|
|
|
65
66
|
constructPayload({ messageTypeName, message }) {
|
|
66
67
|
return {
|
|
67
68
|
metadata: {
|
|
68
|
-
[types_1.METADATA_ENCODING_KEY]: (0,
|
|
69
|
-
[types_1.METADATA_MESSAGE_TYPE_KEY]: (0,
|
|
69
|
+
[types_1.METADATA_ENCODING_KEY]: (0, encoding_1.encode)(this.encodingType),
|
|
70
|
+
[types_1.METADATA_MESSAGE_TYPE_KEY]: (0, encoding_1.encode)(messageTypeName),
|
|
70
71
|
},
|
|
71
72
|
data: message,
|
|
72
73
|
};
|
|
@@ -116,26 +117,26 @@ class ProtobufJsonPayloadConverter extends ProtobufPayloadConverter {
|
|
|
116
117
|
const jsonValue = protoJsonSerializer.toProto3JSON(value);
|
|
117
118
|
return this.constructPayload({
|
|
118
119
|
messageTypeName: getNamespacedTypeName(value.$type),
|
|
119
|
-
message: (0,
|
|
120
|
+
message: (0, encoding_1.encode)(JSON.stringify(jsonValue)),
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
123
|
fromPayload(content) {
|
|
123
124
|
const { messageType, data } = this.validatePayload(content);
|
|
124
|
-
return protoJsonSerializer.fromProto3JSON(messageType, JSON.parse((0,
|
|
125
|
+
return protoJsonSerializer.fromProto3JSON(messageType, JSON.parse((0, encoding_1.decode)(data)));
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
exports.ProtobufJsonPayloadConverter = ProtobufJsonPayloadConverter;
|
|
128
129
|
function isProtobufType(type) {
|
|
129
|
-
return ((0,
|
|
130
|
+
return ((0, type_helpers_1.isRecord)(type) &&
|
|
130
131
|
type.constructor.name === 'Type' &&
|
|
131
|
-
(0,
|
|
132
|
+
(0, type_helpers_1.hasOwnProperties)(type, ['parent', 'name', 'create', 'encode', 'decode']) &&
|
|
132
133
|
typeof type.name === 'string' &&
|
|
133
134
|
typeof type.create === 'function' &&
|
|
134
135
|
typeof type.encode === 'function' &&
|
|
135
136
|
typeof type.decode === 'function');
|
|
136
137
|
}
|
|
137
138
|
function isProtobufMessage(value) {
|
|
138
|
-
return (0,
|
|
139
|
+
return (0, type_helpers_1.isRecord)(value) && (0, type_helpers_1.hasOwnProperty)(value, '$type') && isProtobufType(value.$type);
|
|
139
140
|
}
|
|
140
141
|
function getNamespacedTypeName(node) {
|
|
141
142
|
if (node.parent && !isRoot(node.parent)) {
|
|
@@ -146,15 +147,15 @@ function getNamespacedTypeName(node) {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
function isRoot(root) {
|
|
149
|
-
return (0,
|
|
150
|
+
return (0, type_helpers_1.isRecord)(root) && root.constructor.name === 'Root';
|
|
150
151
|
}
|
|
151
|
-
class DefaultPayloadConverterWithProtobufs extends
|
|
152
|
+
class DefaultPayloadConverterWithProtobufs extends payload_converter_1.CompositePayloadConverter {
|
|
152
153
|
// Match the order used in other SDKs.
|
|
153
154
|
//
|
|
154
155
|
// Go SDK:
|
|
155
156
|
// https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
156
157
|
constructor({ protobufRoot }) {
|
|
157
|
-
super(new
|
|
158
|
+
super(new payload_converter_1.UndefinedPayloadConverter(), new payload_converter_1.BinaryPayloadConverter(), new ProtobufJsonPayloadConverter(protobufRoot), new ProtobufBinaryPayloadConverter(protobufRoot), new payload_converter_1.JsonPayloadConverter());
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
exports.DefaultPayloadConverterWithProtobufs = DefaultPayloadConverterWithProtobufs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protobuf-payload-converters.js","sourceRoot":"","sources":["../../src/converter/protobuf-payload-converters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"protobuf-payload-converters.js","sourceRoot":"","sources":["../../src/converter/protobuf-payload-converters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4EAA8D;AAE9D,0CAA6C;AAC7C,sCAA8D;AAE9D,kDAA2F;AAC3F,2DAM6B;AAE7B,mCAA0F;AAE1F,MAAe,wBAAwB;IAOrC,qGAAqG;IACrG,YAAY,IAAc;QACxB,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;gBACjB,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAC;aACtE;YAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SAClB;IACH,CAAC;IAES,eAAe,CAAC,OAAgB;QACxC,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE;YACvD,MAAM,IAAI,mBAAU,CAAC,0BAA0B,CAAC,CAAC;SAClD;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,iCAAyB,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE;YACz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AAI,4BAA4B,CAAC,YAAY,CAAC,EAC9C,IAAI,8BAA8B,CAAC,YAAY,CAAC,EAChD,IAAI,wCAAoB,EAAE,CAC3B,CAAC;IACJ,CAAC;CACF;AAdD,oFAcC"}
|
package/lib/converter/types.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export { Payload } from '@temporalio/internal-workflow-common';
|
|
2
|
-
/**
|
|
3
|
-
* Transform an *ascii* string into a Uint8Array
|
|
4
|
-
*/
|
|
5
|
-
export declare function u8(s: string): Uint8Array;
|
|
6
|
-
export declare function str(a: Uint8Array): string;
|
|
7
1
|
export declare const METADATA_ENCODING_KEY = "encoding";
|
|
8
2
|
export declare const encodingTypes: {
|
|
9
3
|
readonly METADATA_ENCODING_NULL: "binary/null";
|
package/lib/converter/types.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.METADATA_MESSAGE_TYPE_KEY = exports.encodingKeys = exports.encodingTypes = exports.METADATA_ENCODING_KEY =
|
|
4
|
-
const encoding_1 = require("
|
|
5
|
-
/**
|
|
6
|
-
* Transform an *ascii* string into a Uint8Array
|
|
7
|
-
*/
|
|
8
|
-
function u8(s) {
|
|
9
|
-
return new encoding_1.TextEncoder().encode(s);
|
|
10
|
-
}
|
|
11
|
-
exports.u8 = u8;
|
|
12
|
-
function str(a) {
|
|
13
|
-
return new encoding_1.TextDecoder().decode(a);
|
|
14
|
-
}
|
|
15
|
-
exports.str = str;
|
|
3
|
+
exports.METADATA_MESSAGE_TYPE_KEY = exports.encodingKeys = exports.encodingTypes = exports.METADATA_ENCODING_KEY = void 0;
|
|
4
|
+
const encoding_1 = require("../encoding");
|
|
16
5
|
exports.METADATA_ENCODING_KEY = 'encoding';
|
|
17
6
|
exports.encodingTypes = {
|
|
18
7
|
METADATA_ENCODING_NULL: 'binary/null',
|
|
@@ -22,11 +11,11 @@ exports.encodingTypes = {
|
|
|
22
11
|
METADATA_ENCODING_PROTOBUF: 'binary/protobuf',
|
|
23
12
|
};
|
|
24
13
|
exports.encodingKeys = {
|
|
25
|
-
METADATA_ENCODING_NULL:
|
|
26
|
-
METADATA_ENCODING_RAW:
|
|
27
|
-
METADATA_ENCODING_JSON:
|
|
28
|
-
METADATA_ENCODING_PROTOBUF_JSON:
|
|
29
|
-
METADATA_ENCODING_PROTOBUF:
|
|
14
|
+
METADATA_ENCODING_NULL: (0, encoding_1.encode)(exports.encodingTypes.METADATA_ENCODING_NULL),
|
|
15
|
+
METADATA_ENCODING_RAW: (0, encoding_1.encode)(exports.encodingTypes.METADATA_ENCODING_RAW),
|
|
16
|
+
METADATA_ENCODING_JSON: (0, encoding_1.encode)(exports.encodingTypes.METADATA_ENCODING_JSON),
|
|
17
|
+
METADATA_ENCODING_PROTOBUF_JSON: (0, encoding_1.encode)(exports.encodingTypes.METADATA_ENCODING_PROTOBUF_JSON),
|
|
18
|
+
METADATA_ENCODING_PROTOBUF: (0, encoding_1.encode)(exports.encodingTypes.METADATA_ENCODING_PROTOBUF),
|
|
30
19
|
};
|
|
31
20
|
exports.METADATA_MESSAGE_TYPE_KEY = 'messageType';
|
|
32
21
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/converter/types.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/converter/types.ts"],"names":[],"mappings":";;;AAAA,0CAAqC;AAExB,QAAA,qBAAqB,GAAG,UAAU,CAAC;AACnC,QAAA,aAAa,GAAG;IAC3B,sBAAsB,EAAE,aAAa;IACrC,qBAAqB,EAAE,cAAc;IACrC,sBAAsB,EAAE,YAAY;IACpC,+BAA+B,EAAE,eAAe;IAChD,0BAA0B,EAAE,iBAAiB;CACrC,CAAC;AAGE,QAAA,YAAY,GAAG;IAC1B,sBAAsB,EAAE,IAAA,iBAAM,EAAC,qBAAa,CAAC,sBAAsB,CAAC;IACpE,qBAAqB,EAAE,IAAA,iBAAM,EAAC,qBAAa,CAAC,qBAAqB,CAAC;IAClE,sBAAsB,EAAE,IAAA,iBAAM,EAAC,qBAAa,CAAC,sBAAsB,CAAC;IACpE,+BAA+B,EAAE,IAAA,iBAAM,EAAC,qBAAa,CAAC,+BAA+B,CAAC;IACtF,0BAA0B,EAAE,IAAA,iBAAM,EAAC,qBAAa,CAAC,0BAA0B,CAAC;CACpE,CAAC;AAEE,QAAA,yBAAyB,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Timestamp } from './time';
|
|
2
|
+
/**
|
|
3
|
+
* Lossy conversion function from Timestamp to number due to possible overflow.
|
|
4
|
+
* If ts is null or undefined returns undefined.
|
|
5
|
+
*
|
|
6
|
+
* @hidden
|
|
7
|
+
* @deprecated - meant for internal use only
|
|
8
|
+
*/
|
|
9
|
+
export declare function optionalTsToMs(ts: Timestamp | null | undefined): number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Lossy conversion function from Timestamp to number due to possible overflow
|
|
12
|
+
*
|
|
13
|
+
* @hidden
|
|
14
|
+
* @deprecated - meant for internal use only
|
|
15
|
+
* @deprecated - meant for internal use only
|
|
16
|
+
*/
|
|
17
|
+
export declare function tsToMs(ts: Timestamp | null | undefined): number;
|
|
18
|
+
/**
|
|
19
|
+
* @hidden
|
|
20
|
+
* @deprecated - meant for internal use only
|
|
21
|
+
*/
|
|
22
|
+
export declare function msNumberToTs(millis: number): Timestamp;
|
|
23
|
+
/**
|
|
24
|
+
* @hidden
|
|
25
|
+
* @deprecated - meant for internal use only
|
|
26
|
+
*/
|
|
27
|
+
export declare function msToTs(str: string | number): Timestamp;
|
|
28
|
+
/**
|
|
29
|
+
* @hidden
|
|
30
|
+
* @deprecated - meant for internal use only
|
|
31
|
+
*/
|
|
32
|
+
export declare function msOptionalToTs(str: string | number | undefined): Timestamp | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* @hidden
|
|
35
|
+
* @deprecated - meant for internal use only
|
|
36
|
+
*/
|
|
37
|
+
export declare function msOptionalToNumber(val: string | number | undefined): number | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* @hidden
|
|
40
|
+
* @deprecated - meant for internal use only
|
|
41
|
+
*/
|
|
42
|
+
export declare function msToNumber(val: string | number): number;
|
|
43
|
+
/**
|
|
44
|
+
* @hidden
|
|
45
|
+
* @deprecated - meant for internal use only
|
|
46
|
+
*/
|
|
47
|
+
export declare function tsToDate(ts: Timestamp): Date;
|
|
48
|
+
/**
|
|
49
|
+
* @hidden
|
|
50
|
+
* @deprecated - meant for internal use only
|
|
51
|
+
*/
|
|
52
|
+
export declare function optionalTsToDate(ts: Timestamp | null | undefined): Date | undefined;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.optionalTsToDate = exports.tsToDate = exports.msToNumber = exports.msOptionalToNumber = exports.msOptionalToTs = exports.msToTs = exports.msNumberToTs = exports.tsToMs = exports.optionalTsToMs = void 0;
|
|
27
|
+
const time = __importStar(require("./time"));
|
|
28
|
+
/**
|
|
29
|
+
* Lossy conversion function from Timestamp to number due to possible overflow.
|
|
30
|
+
* If ts is null or undefined returns undefined.
|
|
31
|
+
*
|
|
32
|
+
* @hidden
|
|
33
|
+
* @deprecated - meant for internal use only
|
|
34
|
+
*/
|
|
35
|
+
function optionalTsToMs(ts) {
|
|
36
|
+
return time.optionalTsToMs(ts);
|
|
37
|
+
}
|
|
38
|
+
exports.optionalTsToMs = optionalTsToMs;
|
|
39
|
+
/**
|
|
40
|
+
* Lossy conversion function from Timestamp to number due to possible overflow
|
|
41
|
+
*
|
|
42
|
+
* @hidden
|
|
43
|
+
* @deprecated - meant for internal use only
|
|
44
|
+
* @deprecated - meant for internal use only
|
|
45
|
+
*/
|
|
46
|
+
function tsToMs(ts) {
|
|
47
|
+
return time.tsToMs(ts);
|
|
48
|
+
}
|
|
49
|
+
exports.tsToMs = tsToMs;
|
|
50
|
+
/**
|
|
51
|
+
* @hidden
|
|
52
|
+
* @deprecated - meant for internal use only
|
|
53
|
+
*/
|
|
54
|
+
function msNumberToTs(millis) {
|
|
55
|
+
return time.msNumberToTs(millis);
|
|
56
|
+
}
|
|
57
|
+
exports.msNumberToTs = msNumberToTs;
|
|
58
|
+
/**
|
|
59
|
+
* @hidden
|
|
60
|
+
* @deprecated - meant for internal use only
|
|
61
|
+
*/
|
|
62
|
+
function msToTs(str) {
|
|
63
|
+
return time.msToTs(str);
|
|
64
|
+
}
|
|
65
|
+
exports.msToTs = msToTs;
|
|
66
|
+
/**
|
|
67
|
+
* @hidden
|
|
68
|
+
* @deprecated - meant for internal use only
|
|
69
|
+
*/
|
|
70
|
+
function msOptionalToTs(str) {
|
|
71
|
+
return time.msOptionalToTs(str);
|
|
72
|
+
}
|
|
73
|
+
exports.msOptionalToTs = msOptionalToTs;
|
|
74
|
+
/**
|
|
75
|
+
* @hidden
|
|
76
|
+
* @deprecated - meant for internal use only
|
|
77
|
+
*/
|
|
78
|
+
function msOptionalToNumber(val) {
|
|
79
|
+
return time.msOptionalToNumber(val);
|
|
80
|
+
}
|
|
81
|
+
exports.msOptionalToNumber = msOptionalToNumber;
|
|
82
|
+
/**
|
|
83
|
+
* @hidden
|
|
84
|
+
* @deprecated - meant for internal use only
|
|
85
|
+
*/
|
|
86
|
+
function msToNumber(val) {
|
|
87
|
+
return time.msToNumber(val);
|
|
88
|
+
}
|
|
89
|
+
exports.msToNumber = msToNumber;
|
|
90
|
+
/**
|
|
91
|
+
* @hidden
|
|
92
|
+
* @deprecated - meant for internal use only
|
|
93
|
+
*/
|
|
94
|
+
function tsToDate(ts) {
|
|
95
|
+
return time.tsToDate(ts);
|
|
96
|
+
}
|
|
97
|
+
exports.tsToDate = tsToDate;
|
|
98
|
+
/**
|
|
99
|
+
* @hidden
|
|
100
|
+
* @deprecated - meant for internal use only
|
|
101
|
+
*/
|
|
102
|
+
function optionalTsToDate(ts) {
|
|
103
|
+
return time.optionalTsToDate(ts);
|
|
104
|
+
}
|
|
105
|
+
exports.optionalTsToDate = optionalTsToDate;
|
|
106
|
+
//# sourceMappingURL=deprecated-time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecated-time.js","sourceRoot":"","sources":["../src/deprecated-time.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAG/B;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,EAAgC;IAC7D,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AAFD,wCAEC;AAED;;;;;;GAMG;AACH,SAAgB,MAAM,CAAC,EAAgC;IACrD,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC;AAFD,wBAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,MAAM,CAAC,GAAoB;IACzC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAFD,wBAEC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,GAAgC;IAC7D,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAFD,wCAEC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,GAAgC;IACjE,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAFD,gDAEC;AAED;;;GAGG;AACH,SAAgB,UAAU,CAAC,GAAoB;IAC7C,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AAFD,gCAEC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,EAAa;IACpC,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC;AAFD,4BAEC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,EAAgC;IAC/D,OAAO,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC;AAFD,4CAEC"}
|
|
@@ -8,3 +8,11 @@ export declare class TextEncoder {
|
|
|
8
8
|
read: number;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Encode a UTF-8 string into a Uint8Array
|
|
13
|
+
*/
|
|
14
|
+
export declare function encode(s: string): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Decode a Uint8Array into a UTF-8 string
|
|
17
|
+
*/
|
|
18
|
+
export declare function decode(a: Uint8Array): string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Pasted with modifications from: https://raw.githubusercontent.com/anonyco/FastestSmallestTextEncoderDecoder/master/EncoderDecoderTogether.src.js
|
|
3
3
|
/* eslint no-fallthrough: 0 */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.TextEncoder = exports.TextDecoder = void 0;
|
|
5
|
+
exports.decode = exports.encode = exports.TextEncoder = exports.TextDecoder = void 0;
|
|
6
6
|
const fromCharCode = String.fromCharCode;
|
|
7
7
|
const encoderRegexp = /[\x80-\uD7ff\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]?/g;
|
|
8
8
|
const tmpBufferU16 = new Uint16Array(32);
|
|
@@ -257,4 +257,18 @@ class TextEncoder {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
exports.TextEncoder = TextEncoder;
|
|
260
|
+
/**
|
|
261
|
+
* Encode a UTF-8 string into a Uint8Array
|
|
262
|
+
*/
|
|
263
|
+
function encode(s) {
|
|
264
|
+
return TextEncoder.prototype.encode(s);
|
|
265
|
+
}
|
|
266
|
+
exports.encode = encode;
|
|
267
|
+
/**
|
|
268
|
+
* Decode a Uint8Array into a UTF-8 string
|
|
269
|
+
*/
|
|
270
|
+
function decode(a) {
|
|
271
|
+
return TextDecoder.prototype.decode(a);
|
|
272
|
+
}
|
|
273
|
+
exports.decode = decode;
|
|
260
274
|
//# sourceMappingURL=encoding.js.map
|