@temporalio/common 0.23.0 → 1.0.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/LICENSE.md +1 -1
- package/README.md +3 -3
- package/lib/converter/data-converter.d.ts +5 -5
- package/lib/converter/data-converter.js +1 -2
- package/lib/converter/data-converter.js.map +1 -1
- package/lib/converter/json-payload-converter.d.ts +10 -0
- package/lib/converter/json-payload-converter.js +39 -0
- package/lib/converter/json-payload-converter.js.map +1 -0
- package/lib/converter/payload-converter.d.ts +11 -15
- package/lib/converter/payload-converter.js +5 -14
- package/lib/converter/payload-converter.js.map +1 -1
- package/lib/converter/payload-converters.d.ts +19 -15
- package/lib/converter/payload-converters.js +10 -41
- package/lib/converter/payload-converters.js.map +1 -1
- package/lib/converter/protobuf-payload-converters.js +2 -1
- package/lib/converter/protobuf-payload-converters.js.map +1 -1
- package/lib/converter/search-attribute-payload-converter.d.ts +12 -0
- package/lib/converter/search-attribute-payload-converter.js +64 -0
- package/lib/converter/search-attribute-payload-converter.js.map +1 -0
- package/lib/converter/types.d.ts +1 -2
- package/lib/converter/types.js.map +1 -1
- package/lib/failure.d.ts +58 -46
- package/lib/failure.js +85 -56
- package/lib/failure.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/otel.d.ts +26 -0
- package/lib/otel.js +87 -0
- package/lib/otel.js.map +1 -0
- package/lib/proto-utils.d.ts +28 -0
- package/lib/proto-utils.js +85 -0
- package/lib/proto-utils.js.map +1 -0
- package/lib/protobufs.d.ts +2 -2
- package/lib/protobufs.js +4 -2
- package/lib/protobufs.js.map +1 -1
- package/package.json +12 -9
- package/src/converter/data-converter.ts +6 -6
- package/src/converter/json-payload-converter.ts +37 -0
- package/src/converter/payload-converter.ts +15 -29
- package/src/converter/payload-converters.ts +24 -43
- package/src/converter/protobuf-payload-converters.ts +1 -1
- package/src/converter/search-attribute-payload-converter.ts +71 -0
- package/src/converter/types.ts +1 -2
- package/src/failure.ts +92 -62
- package/src/index.ts +1 -0
- package/src/otel.ts +63 -0
- package/src/proto-utils.ts +103 -0
- package/src/protobufs.ts +2 -2
- package/lib/converter/patch-protobuf-root.d.ts +0 -1
- package/lib/converter/patch-protobuf-root.js +0 -6
- package/lib/converter/patch-protobuf-root.js.map +0 -1
- package/lib/converter/wrapped-payload-converter.d.ts +0 -12
- package/lib/converter/wrapped-payload-converter.js +0 -28
- package/lib/converter/wrapped-payload-converter.js.map +0 -1
- package/src/converter/patch-protobuf-root.ts +0 -1
- package/src/converter/wrapped-payload-converter.ts +0 -31
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/LICENSE.md
CHANGED
|
@@ -2,7 +2,7 @@ Temporal TypeScript SDK
|
|
|
2
2
|
|
|
3
3
|
MIT License
|
|
4
4
|
|
|
5
|
-
Copyright (c) 2021 Temporal Technologies
|
|
5
|
+
Copyright (c) 2021 Temporal Technologies Inc. All Rights Reserved
|
|
6
6
|
|
|
7
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@temporalio/common)
|
|
4
4
|
|
|
5
|
-
Part of [Temporal](https://temporal.io)'s TypeScript SDK (see [docs](https://docs.temporal.io/
|
|
5
|
+
Part of [Temporal](https://temporal.io)'s TypeScript SDK (see [docs](https://docs.temporal.io/typescript/introduction/) and [samples](https://github.com/temporalio/samples-typescript)).
|
|
6
6
|
|
|
7
7
|
Common library for code that's used across the Client, Worker, and/or Workflow:
|
|
8
8
|
|
|
9
|
-
- [DataConverter docs](https://docs.temporal.io/
|
|
10
|
-
- [Failure docs](https://docs.temporal.io/
|
|
9
|
+
- [DataConverter docs](https://docs.temporal.io/typescript/data-converters)
|
|
10
|
+
- [Failure docs](https://docs.temporal.io/typescript/handling-failure)
|
|
11
11
|
- [API reference](https://typescript.temporal.io/api/namespaces/common)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { PayloadCodec } from './payload-codec';
|
|
2
|
-
import {
|
|
2
|
+
import { PayloadConverter } from './payload-converter';
|
|
3
3
|
/**
|
|
4
4
|
* When your data (arguments and return values) is sent over the wire and stored by Temporal Server, it is encoded in
|
|
5
5
|
* binary in a {@link Payload} Protobuf message.
|
|
6
6
|
*
|
|
7
7
|
* The default `DataConverter` supports `undefined`, `Uint8Array`, and JSON serializables (so if
|
|
8
|
-
*
|
|
9
|
-
* works, the default data converter will work). Protobufs are supported via
|
|
10
|
-
*
|
|
8
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description | `JSON.stringify(yourArgOrRetval)`}
|
|
9
|
+
* works, the default data converter will work). Protobufs are supported via
|
|
10
|
+
* {@link https://docs.temporal.io/typescript/data-converters#protobufs | this API}.
|
|
11
11
|
*
|
|
12
12
|
* Use a custom `DataConverter` to control the contents of your {@link Payload}s. Common reasons for using a custom
|
|
13
13
|
* `DataConverter` are:
|
|
@@ -44,7 +44,7 @@ export interface DataConverter {
|
|
|
44
44
|
* A {@link DataConverter} that has been loaded via {@link loadDataConverter}.
|
|
45
45
|
*/
|
|
46
46
|
export interface LoadedDataConverter {
|
|
47
|
-
payloadConverter:
|
|
47
|
+
payloadConverter: PayloadConverter;
|
|
48
48
|
payloadCodecs: PayloadCodec[];
|
|
49
49
|
}
|
|
50
50
|
export declare const defaultDataConverter: LoadedDataConverter;
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultDataConverter = void 0;
|
|
4
4
|
const payload_converters_1 = require("./payload-converters");
|
|
5
|
-
const wrapped_payload_converter_1 = require("./wrapped-payload-converter");
|
|
6
5
|
exports.defaultDataConverter = {
|
|
7
|
-
payloadConverter:
|
|
6
|
+
payloadConverter: payload_converters_1.defaultPayloadConverter,
|
|
8
7
|
payloadCodecs: [],
|
|
9
8
|
};
|
|
10
9
|
//# sourceMappingURL=data-converter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-converter.js","sourceRoot":"","sources":["../../src/converter/data-converter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"data-converter.js","sourceRoot":"","sources":["../../src/converter/data-converter.ts"],"names":[],"mappings":";;;AAEA,6DAA+D;AAoDlD,QAAA,oBAAoB,GAAwB;IACvD,gBAAgB,EAAE,4CAAuB;IACzC,aAAa,EAAE,EAAE;CAClB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PayloadConverterWithEncoding } from './payload-converters';
|
|
2
|
+
import { Payload } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Converts between non-undefined values and serialized JSON Payload
|
|
5
|
+
*/
|
|
6
|
+
export declare class JsonPayloadConverter implements PayloadConverterWithEncoding {
|
|
7
|
+
encodingType: "json/plain";
|
|
8
|
+
toPayload(value: unknown): Payload | undefined;
|
|
9
|
+
fromPayload<T>(content: Payload): T;
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonPayloadConverter = void 0;
|
|
4
|
+
const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
/**
|
|
7
|
+
* Converts between non-undefined values and serialized JSON Payload
|
|
8
|
+
*/
|
|
9
|
+
class JsonPayloadConverter {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.encodingType = types_1.encodingTypes.METADATA_ENCODING_JSON;
|
|
12
|
+
}
|
|
13
|
+
toPayload(value) {
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
let json;
|
|
18
|
+
try {
|
|
19
|
+
json = JSON.stringify(value);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
metadata: {
|
|
26
|
+
[types_1.METADATA_ENCODING_KEY]: types_1.encodingKeys.METADATA_ENCODING_JSON,
|
|
27
|
+
},
|
|
28
|
+
data: (0, types_1.u8)(json),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
fromPayload(content) {
|
|
32
|
+
if (content.data === undefined || content.data === null) {
|
|
33
|
+
throw new internal_workflow_common_1.ValueError('Got payload with no data');
|
|
34
|
+
}
|
|
35
|
+
return JSON.parse((0, types_1.str)(content.data));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.JsonPayloadConverter = JsonPayloadConverter;
|
|
39
|
+
//# sourceMappingURL=json-payload-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-payload-converter.js","sourceRoot":"","sources":["../../src/converter/json-payload-converter.ts"],"names":[],"mappings":";;;AAAA,mFAAkE;AAElE,mCAA+F;AAE/F;;GAEG;AACH,MAAa,oBAAoB;IAAjC;QACS,iBAAY,GAAG,qBAAa,CAAC,sBAAsB,CAAC;IA4B7D,CAAC;IA1BQ,SAAS,CAAC,KAAc;QAC7B,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,SAAS,CAAC;SAClB;QAED,IAAI,IAAI,CAAC;QACT,IAAI;YACF,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAC9B;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,SAAS,CAAC;SAClB;QAED,OAAO;YACL,QAAQ,EAAE;gBACR,CAAC,6BAAqB,CAAC,EAAE,oBAAY,CAAC,sBAAsB;aAC7D;YACD,IAAI,EAAE,IAAA,UAAE,EAAC,IAAI,CAAC;SACf,CAAC;IACJ,CAAC;IAEM,WAAW,CAAI,OAAgB;QACpC,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE;YACvD,MAAM,IAAI,qCAAU,CAAC,0BAA0B,CAAC,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,WAAG,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC;CACF;AA7BD,oDA6BC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Payload } from './types';
|
|
2
|
-
import { WrappedPayloadConverter } from './wrapped-payload-converter';
|
|
3
2
|
/**
|
|
4
3
|
* Used by the framework to serialize/deserialize data like parameters and return values.
|
|
5
4
|
*
|
|
6
|
-
* This is called inside the
|
|
5
|
+
* This is called inside the {@link https://docs.temporal.io/typescript/determinism | Workflow isolate}.
|
|
7
6
|
* To write async code or use Node APIs (or use packages that use Node APIs), use a {@link PayloadCodec}.
|
|
8
7
|
*/
|
|
9
8
|
export interface PayloadConverter {
|
|
@@ -11,20 +10,17 @@ export interface PayloadConverter {
|
|
|
11
10
|
* Converts a value to a {@link Payload}.
|
|
12
11
|
*
|
|
13
12
|
* @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.
|
|
14
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @returns The {@link Payload}.
|
|
15
|
+
*
|
|
16
|
+
* Should throw {@link ValueError} if unable to convert.
|
|
15
17
|
*/
|
|
16
|
-
toPayload<T>(value: T): Payload
|
|
18
|
+
toPayload<T>(value: T): Payload;
|
|
17
19
|
/**
|
|
18
20
|
* Converts a {@link Payload} back to a value.
|
|
19
21
|
*/
|
|
20
22
|
fromPayload<T>(payload: Payload): T;
|
|
21
23
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Tries to convert `value` to a {@link Payload}. Throws if conversion fails.
|
|
24
|
-
*
|
|
25
|
-
* @throws {@link ValueError}
|
|
26
|
-
*/
|
|
27
|
-
export declare function toPayload(converter: WrappedPayloadConverter, value: unknown): Payload;
|
|
28
24
|
/**
|
|
29
25
|
* Implements conversion of a list of values.
|
|
30
26
|
*
|
|
@@ -34,13 +30,13 @@ export declare function toPayload(converter: WrappedPayloadConverter, value: unk
|
|
|
34
30
|
* @throws {@link ValueError} if conversion of the value passed as parameter failed for any
|
|
35
31
|
* reason.
|
|
36
32
|
*/
|
|
37
|
-
export declare function toPayloads(converter:
|
|
33
|
+
export declare function toPayloads(converter: PayloadConverter, ...values: unknown[]): Payload[] | undefined;
|
|
38
34
|
/**
|
|
39
35
|
* Run {@link PayloadConverter.toPayload} on each value in the map.
|
|
40
36
|
*
|
|
41
37
|
* @throws {@link ValueError} if conversion of any value in the map fails
|
|
42
38
|
*/
|
|
43
|
-
export declare function mapToPayloads<K extends string>(converter:
|
|
39
|
+
export declare function mapToPayloads<K extends string>(converter: PayloadConverter, map: Record<K, any>): Record<K, Payload>;
|
|
44
40
|
/**
|
|
45
41
|
* Implements conversion of an array of values of different types. Useful for deserializing
|
|
46
42
|
* arguments of function invocations.
|
|
@@ -52,9 +48,9 @@ export declare function mapToPayloads<K extends string>(converter: WrappedPayloa
|
|
|
52
48
|
* @throws {@link PayloadConverterError} if conversion of the data passed as parameter failed for any
|
|
53
49
|
* reason.
|
|
54
50
|
*/
|
|
55
|
-
export declare function fromPayloadsAtIndex<T>(converter:
|
|
51
|
+
export declare function fromPayloadsAtIndex<T>(converter: PayloadConverter, index: number, payloads?: Payload[] | null): T;
|
|
56
52
|
/**
|
|
57
53
|
* Run {@link PayloadConverter.fromPayload} on each value in the array.
|
|
58
54
|
*/
|
|
59
|
-
export declare function arrayFromPayloads(converter:
|
|
60
|
-
export declare function mapFromPayloads<K extends string>(converter:
|
|
55
|
+
export declare function arrayFromPayloads(converter: PayloadConverter, payloads?: Payload[] | null): unknown[];
|
|
56
|
+
export declare function mapFromPayloads<K extends string>(converter: PayloadConverter, map?: Record<K, Payload> | null | undefined): Record<K, unknown> | undefined | null;
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapFromPayloads = exports.arrayFromPayloads = exports.fromPayloadsAtIndex = exports.mapToPayloads = exports.toPayloads =
|
|
4
|
-
/**
|
|
5
|
-
* Tries to convert `value` to a {@link Payload}. Throws if conversion fails.
|
|
6
|
-
*
|
|
7
|
-
* @throws {@link ValueError}
|
|
8
|
-
*/
|
|
9
|
-
function toPayload(converter, value) {
|
|
10
|
-
return converter.toPayload(value);
|
|
11
|
-
}
|
|
12
|
-
exports.toPayload = toPayload;
|
|
3
|
+
exports.mapFromPayloads = exports.arrayFromPayloads = exports.fromPayloadsAtIndex = exports.mapToPayloads = exports.toPayloads = void 0;
|
|
13
4
|
/**
|
|
14
5
|
* Implements conversion of a list of values.
|
|
15
6
|
*
|
|
@@ -23,7 +14,7 @@ function toPayloads(converter, ...values) {
|
|
|
23
14
|
if (values.length === 0) {
|
|
24
15
|
return undefined;
|
|
25
16
|
}
|
|
26
|
-
return values.map((value) => toPayload(
|
|
17
|
+
return values.map((value) => converter.toPayload(value));
|
|
27
18
|
}
|
|
28
19
|
exports.toPayloads = toPayloads;
|
|
29
20
|
/**
|
|
@@ -32,7 +23,7 @@ exports.toPayloads = toPayloads;
|
|
|
32
23
|
* @throws {@link ValueError} if conversion of any value in the map fails
|
|
33
24
|
*/
|
|
34
25
|
function mapToPayloads(converter, map) {
|
|
35
|
-
return Object.fromEntries(Object.entries(map).map(([k, v]) => [k, toPayload(
|
|
26
|
+
return Object.fromEntries(Object.entries(map).map(([k, v]) => [k, converter.toPayload(v)]));
|
|
36
27
|
}
|
|
37
28
|
exports.mapToPayloads = mapToPayloads;
|
|
38
29
|
/**
|
|
@@ -65,8 +56,8 @@ function arrayFromPayloads(converter, payloads) {
|
|
|
65
56
|
}
|
|
66
57
|
exports.arrayFromPayloads = arrayFromPayloads;
|
|
67
58
|
function mapFromPayloads(converter, map) {
|
|
68
|
-
if (map
|
|
69
|
-
return
|
|
59
|
+
if (map == null)
|
|
60
|
+
return map;
|
|
70
61
|
return Object.fromEntries(Object.entries(map).map(([k, payload]) => {
|
|
71
62
|
const value = converter.fromPayload(payload);
|
|
72
63
|
return [k, value];
|
|
@@ -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":";;;AA0BA;;;;;;;;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,KAAK,CAAC,CAAC,CAAC;AAChD,CAAC;AAND,kDAMC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,SAA2B,EAAE,QAA2B;IACxF,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,EAAE,CAAC;KACX;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;AAC5E,CAAC;AALD,8CAKC;AAED,SAAgB,eAAe,CAC7B,SAA2B,EAC3B,GAA2C;IAE3C,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,GAAG,CAAC;IAC5B,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAgB,EAAE;QACrD,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,OAAkB,CAAC,CAAC;QACxD,OAAO,CAAC,CAAM,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC,CAAC,CACmB,CAAC;AAC1B,CAAC;AAXD,0CAWC"}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { PayloadConverter } from './payload-converter';
|
|
2
|
+
import { SearchAttributePayloadConverter } from './search-attribute-payload-converter';
|
|
2
3
|
import { Payload } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
export interface PayloadConverterWithEncoding {
|
|
5
|
+
/**
|
|
6
|
+
* Converts a value to a {@link Payload}.
|
|
7
|
+
*
|
|
8
|
+
* @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.
|
|
9
|
+
* @returns The {@link Payload}, or `undefined` if unable to convert.
|
|
10
|
+
*/
|
|
11
|
+
toPayload<T>(value: T): Payload | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Converts a {@link Payload} back to a value.
|
|
14
|
+
*/
|
|
15
|
+
fromPayload<T>(payload: Payload): T;
|
|
5
16
|
readonly encodingType: string;
|
|
6
17
|
}
|
|
7
18
|
/**
|
|
@@ -16,9 +27,9 @@ export declare class CompositePayloadConverter implements PayloadConverter {
|
|
|
16
27
|
constructor(...converters: PayloadConverterWithEncoding[]);
|
|
17
28
|
/**
|
|
18
29
|
* Tries to run `.toPayload(value)` on each converter in the order provided at construction.
|
|
19
|
-
* Returns the first successful result,
|
|
30
|
+
* Returns the first successful result, throws {@link ValueError} if there is no converter that can handle the value.
|
|
20
31
|
*/
|
|
21
|
-
toPayload<T>(value: T): Payload
|
|
32
|
+
toPayload<T>(value: T): Payload;
|
|
22
33
|
/**
|
|
23
34
|
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the {@link encodingTypes | encoding type} of the {@link Payload}.
|
|
24
35
|
*/
|
|
@@ -32,14 +43,6 @@ export declare class UndefinedPayloadConverter implements PayloadConverterWithEn
|
|
|
32
43
|
toPayload(value: unknown): Payload | undefined;
|
|
33
44
|
fromPayload<T>(_content: Payload): T;
|
|
34
45
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Converts between non-undefined values and serialized JSON Payload
|
|
37
|
-
*/
|
|
38
|
-
export declare class JsonPayloadConverter implements PayloadConverterWithEncoding {
|
|
39
|
-
encodingType: "json/plain";
|
|
40
|
-
toPayload(value: unknown): Payload | undefined;
|
|
41
|
-
fromPayload<T>(content: Payload): T;
|
|
42
|
-
}
|
|
43
46
|
/**
|
|
44
47
|
* Converts between binary data types and RAW Payload
|
|
45
48
|
*/
|
|
@@ -48,13 +51,14 @@ export declare class BinaryPayloadConverter implements PayloadConverterWithEncod
|
|
|
48
51
|
toPayload(value: unknown): Payload | undefined;
|
|
49
52
|
fromPayload<T>(content: Payload): T;
|
|
50
53
|
}
|
|
51
|
-
export declare const searchAttributePayloadConverter:
|
|
54
|
+
export declare const searchAttributePayloadConverter: SearchAttributePayloadConverter;
|
|
52
55
|
export declare class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
53
56
|
constructor();
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
56
|
-
* The default {@link PayloadConverter} used by the SDK.
|
|
57
|
-
*
|
|
59
|
+
* The default {@link PayloadConverter} used by the SDK. Supports `Uint8Array` and JSON serializables (so if
|
|
60
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description | `JSON.stringify(yourArgOrRetval)`}
|
|
61
|
+
* works, the default payload converter will work).
|
|
58
62
|
*
|
|
59
63
|
* To also support Protobufs, create a custom payload converter with {@link DefaultPayloadConverter}:
|
|
60
64
|
*
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultPayloadConverter = exports.DefaultPayloadConverter = exports.searchAttributePayloadConverter = exports.BinaryPayloadConverter = exports.
|
|
3
|
+
exports.defaultPayloadConverter = exports.DefaultPayloadConverter = exports.searchAttributePayloadConverter = exports.BinaryPayloadConverter = exports.UndefinedPayloadConverter = exports.CompositePayloadConverter = void 0;
|
|
4
4
|
const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
5
|
+
const json_payload_converter_1 = require("./json-payload-converter");
|
|
6
|
+
const search_attribute_payload_converter_1 = require("./search-attribute-payload-converter");
|
|
5
7
|
const types_1 = require("./types");
|
|
6
|
-
const wrapped_payload_converter_1 = require("./wrapped-payload-converter");
|
|
7
8
|
/**
|
|
8
9
|
* Tries to convert values to {@link Payload}s using the {@link PayloadConverterWithEncoding}s provided to the constructor, in the order provided.
|
|
9
10
|
*
|
|
@@ -23,7 +24,7 @@ class CompositePayloadConverter {
|
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Tries to run `.toPayload(value)` on each converter in the order provided at construction.
|
|
26
|
-
* Returns the first successful result,
|
|
27
|
+
* Returns the first successful result, throws {@link ValueError} if there is no converter that can handle the value.
|
|
27
28
|
*/
|
|
28
29
|
toPayload(value) {
|
|
29
30
|
for (const converter of this.converters) {
|
|
@@ -32,7 +33,7 @@ class CompositePayloadConverter {
|
|
|
32
33
|
return result;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
throw new internal_workflow_common_1.ValueError(`Unable to convert ${value} to payload`);
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the {@link encodingTypes | encoding type} of the {@link Payload}.
|
|
@@ -72,39 +73,6 @@ class UndefinedPayloadConverter {
|
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
exports.UndefinedPayloadConverter = UndefinedPayloadConverter;
|
|
75
|
-
/**
|
|
76
|
-
* Converts between non-undefined values and serialized JSON Payload
|
|
77
|
-
*/
|
|
78
|
-
class JsonPayloadConverter {
|
|
79
|
-
constructor() {
|
|
80
|
-
this.encodingType = types_1.encodingTypes.METADATA_ENCODING_JSON;
|
|
81
|
-
}
|
|
82
|
-
toPayload(value) {
|
|
83
|
-
if (value === undefined) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
let json;
|
|
87
|
-
try {
|
|
88
|
-
json = JSON.stringify(value);
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
metadata: {
|
|
95
|
-
[types_1.METADATA_ENCODING_KEY]: types_1.encodingKeys.METADATA_ENCODING_JSON,
|
|
96
|
-
},
|
|
97
|
-
data: (0, types_1.u8)(json),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
fromPayload(content) {
|
|
101
|
-
if (content.data === undefined || content.data === null) {
|
|
102
|
-
throw new internal_workflow_common_1.ValueError('Got payload with no data');
|
|
103
|
-
}
|
|
104
|
-
return JSON.parse((0, types_1.str)(content.data));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.JsonPayloadConverter = JsonPayloadConverter;
|
|
108
76
|
/**
|
|
109
77
|
* Converts between binary data types and RAW Payload
|
|
110
78
|
*/
|
|
@@ -130,7 +98,7 @@ class BinaryPayloadConverter {
|
|
|
130
98
|
}
|
|
131
99
|
}
|
|
132
100
|
exports.BinaryPayloadConverter = BinaryPayloadConverter;
|
|
133
|
-
exports.searchAttributePayloadConverter = new
|
|
101
|
+
exports.searchAttributePayloadConverter = new search_attribute_payload_converter_1.SearchAttributePayloadConverter();
|
|
134
102
|
class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
135
103
|
// Match the order used in other SDKs, but exclude Protobuf converters so that the code, including
|
|
136
104
|
// `proto3-json-serializer`, doesn't take space in Workflow bundles that don't use Protobufs. To use Protobufs, use
|
|
@@ -139,13 +107,14 @@ class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
|
139
107
|
// Go SDK:
|
|
140
108
|
// https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
141
109
|
constructor() {
|
|
142
|
-
super(new UndefinedPayloadConverter(), new BinaryPayloadConverter(), new JsonPayloadConverter());
|
|
110
|
+
super(new UndefinedPayloadConverter(), new BinaryPayloadConverter(), new json_payload_converter_1.JsonPayloadConverter());
|
|
143
111
|
}
|
|
144
112
|
}
|
|
145
113
|
exports.DefaultPayloadConverter = DefaultPayloadConverter;
|
|
146
114
|
/**
|
|
147
|
-
* The default {@link PayloadConverter} used by the SDK.
|
|
148
|
-
*
|
|
115
|
+
* The default {@link PayloadConverter} used by the SDK. Supports `Uint8Array` and JSON serializables (so if
|
|
116
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description | `JSON.stringify(yourArgOrRetval)`}
|
|
117
|
+
* works, the default payload converter will work).
|
|
149
118
|
*
|
|
150
119
|
* To also support Protobufs, create a custom payload converter with {@link DefaultPayloadConverter}:
|
|
151
120
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload-converters.js","sourceRoot":"","sources":["../../src/converter/payload-converters.ts"],"names":[],"mappings":";;;AA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A6H;IAC7H;QACE,KAAK,CAAC,IAAI,yBAAyB,EAAE,EAAE,IAAI,sBAAsB,EAAE,EAAE,IAAI,6CAAoB,EAAE,CAAC,CAAC;IACnG,CAAC;CACF;AAVD,0DAUC;AAED;;;;;;;;GAQG;AACU,QAAA,uBAAuB,GAAG,IAAI,uBAAuB,EAAE,CAAC"}
|
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.DefaultPayloadConverterWithProtobufs = exports.ProtobufJsonPayloadConverter = exports.ProtobufBinaryPayloadConverter = void 0;
|
|
27
27
|
const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
28
28
|
const protoJsonSerializer = __importStar(require("proto3-json-serializer"));
|
|
29
|
+
const json_payload_converter_1 = require("./json-payload-converter");
|
|
29
30
|
const payload_converters_1 = require("./payload-converters");
|
|
30
31
|
const types_1 = require("./types");
|
|
31
32
|
class ProtobufPayloadConverter {
|
|
@@ -153,7 +154,7 @@ class DefaultPayloadConverterWithProtobufs extends payload_converters_1.Composit
|
|
|
153
154
|
// Go SDK:
|
|
154
155
|
// https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
155
156
|
constructor({ protobufRoot }) {
|
|
156
|
-
super(new payload_converters_1.UndefinedPayloadConverter(), new payload_converters_1.BinaryPayloadConverter(), new ProtobufJsonPayloadConverter(protobufRoot), new ProtobufBinaryPayloadConverter(protobufRoot), new
|
|
157
|
+
super(new payload_converters_1.UndefinedPayloadConverter(), new payload_converters_1.BinaryPayloadConverter(), new ProtobufJsonPayloadConverter(protobufRoot), new ProtobufBinaryPayloadConverter(protobufRoot), new json_payload_converter_1.JsonPayloadConverter());
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
exports.DefaultPayloadConverterWithProtobufs = DefaultPayloadConverterWithProtobufs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protobuf-payload-converters.js","sourceRoot":"","sources":["../../src/converter/protobuf-payload-converters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mFAO8C;AAC9C,4EAA8D;AAE9D,
|
|
1
|
+
{"version":3,"file":"protobuf-payload-converters.js","sourceRoot":"","sources":["../../src/converter/protobuf-payload-converters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mFAO8C;AAC9C,4EAA8D;AAE9D,qEAAgE;AAChE,6DAK8B;AAC9B,mCAQiB;AAEjB,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,qCAAU,CAAC,0BAA0B,CAAC,CAAC;SAClD;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,iCAAyB,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE;YACzE,MAAM,IAAI,qCAAU,CAAC,yCAAyC,iCAAyB,EAAE,CAAC,CAAC;SAC5F;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,MAAM,IAAI,gDAAqB,CAAC,sEAAsE,CAAC,CAAC;SACzG;QAED,MAAM,eAAe,GAAG,IAAA,WAAG,EAAC,OAAO,CAAC,QAAQ,CAAC,iCAAyB,CAAC,CAAC,CAAC;QACzE,IAAI,WAAW,CAAC;QAChB,IAAI;YACF,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;SACrD;QAAC,OAAO,CA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MAAM,KAAK,UAAU,CAClC,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAO,IAAA,mCAAQ,EAAC,KAAK,CAAC,IAAI,IAAA,yCAAc,EAAC,KAAK,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAsB;IACnD,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACvC,OAAO,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;KAC7D;SAAM;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;KAClB;AACH,CAAC;AAED,SAAS,MAAM,CAAC,IAAa;IAC3B,OAAO,IAAA,mCAAQ,EAAC,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM,CAAC;AAC5D,CAAC;AASD,MAAa,oCAAqC,SAAQ,8CAAyB;IACjF,sCAAsC;IACtC,EAAE;IACF,UAAU;IACV,6HAA6H;IAC7H,YAAY,EAAE,YAAY,EAA+C;QACvE,KAAK,CACH,IAAI,8CAAyB,EAAE,EAC/B,IAAI,2CAAsB,EAAE,EAC5B,IAAI,4BAA4B,CAAC,YAAY,CAAC,EAC9C,IAAI,8BAA8B,CAAC,YAAY,CAAC,EAChD,IAAI,6CAAoB,EAAE,CAC3B,CAAC;IACJ,CAAC;CACF;AAdD,oFAcC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PayloadConverter } from './payload-converter';
|
|
2
|
+
import { Payload } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Converts Search Attribute values using JsonPayloadConverter
|
|
5
|
+
*/
|
|
6
|
+
export declare class SearchAttributePayloadConverter implements PayloadConverter {
|
|
7
|
+
toPayload(values: unknown): Payload;
|
|
8
|
+
/**
|
|
9
|
+
* Datetime Search Attribute values are converted to `Date`s
|
|
10
|
+
*/
|
|
11
|
+
fromPayload<T>(payload: Payload): T;
|
|
12
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;A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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"}
|
package/lib/converter/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/converter/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/converter/types.ts"],"names":[],"mappings":";;;AAAA,yCAAsD;AAItD;;GAEG;AACH,SAAgB,EAAE,CAAC,CAAS;IAC1B,OAAO,IAAI,sBAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAFD,gBAEC;AAED,SAAgB,GAAG,CAAC,CAAa;IAC/B,OAAO,IAAI,sBAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAFD,kBAEC;AAEY,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,EAAE,CAAC,qBAAa,CAAC,sBAAsB,CAAC;IAChE,qBAAqB,EAAE,EAAE,CAAC,qBAAa,CAAC,qBAAqB,CAAC;IAC9D,sBAAsB,EAAE,EAAE,CAAC,qBAAa,CAAC,sBAAsB,CAAC;IAChE,+BAA+B,EAAE,EAAE,CAAC,qBAAa,CAAC,+BAA+B,CAAC;IAClF,0BAA0B,EAAE,EAAE,CAAC,qBAAa,CAAC,0BAA0B,CAAC;CAChE,CAAC;AAEE,QAAA,yBAAyB,GAAG,aAAa,CAAC"}
|