Skip to content

Commit 71d10a8

Browse files
bergundylorensr
andauthored
chore: Deprecate internal functions that should have never been exported (#893)
* chore: Deprecate internal functions that should have never been exported * use arduino/setup-protoc instead of @protobuf-ts/protoc * point sdk-features at protoc branch * add token Co-authored-by: Loren 🤓 <lorensr@gmail.com>
1 parent 3be5ab7 commit 71d10a8

28 files changed

+235
-106
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ jobs:
3030
- uses: actions/setup-node@v1
3131
with:
3232
node-version: ${{ matrix.node }}
33+
- name: Install protoc
34+
uses: arduino/setup-protoc@v1
35+
with:
36+
version: '3.x'
37+
repo-token: ${{ secrets.GITHUB_TOKEN }}
3338
- uses: Swatinem/rust-cache@v1
3439
with:
3540
working-directory: packages/core-bridge
@@ -79,6 +84,11 @@ jobs:
7984
- uses: actions/setup-node@v1
8085
with:
8186
node-version: 16
87+
- name: Install protoc
88+
uses: arduino/setup-protoc@v1
89+
with:
90+
version: '3.x'
91+
repo-token: ${{ secrets.GITHUB_TOKEN }}
8292
# Don't build during install phase since we're going to explicitly build
8393
- run: npm ci --ignore-scripts
8494
- run: npm run build -- --ignore @temporalio/core-bridge
@@ -149,6 +159,11 @@ jobs:
149159
- uses: actions/setup-node@v1
150160
with:
151161
node-version: 16
162+
- name: Install protoc
163+
uses: arduino/setup-protoc@v1
164+
with:
165+
version: '3.x'
166+
repo-token: ${{ secrets.GITHUB_TOKEN }}
152167
- name: Add ${{ matrix.target }} rust target
153168
run: rustup target add ${{ matrix.target }}
154169
- name: Print libc version
@@ -276,7 +291,7 @@ jobs:
276291

277292
# Runs the sdk features repo tests with this repo's current SDK code
278293
sdk-features-tests:
279-
uses: temporalio/sdk-features/.github/workflows/typescript.yaml@main
294+
uses: temporalio/sdk-features/.github/workflows/typescript.yaml@protoc
280295
with:
281296
typescript-repo-path: ${{github.event.pull_request.head.repo.full_name}}
282297
typescript-repo-ref: ${{github.event.pull_request.head.ref}}

.github/workflows/stress.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ jobs:
3030
- uses: actions/setup-node@v1
3131
with:
3232
node-version: ${{ matrix.node }}
33+
- name: Install protoc
34+
uses: arduino/setup-protoc@v1
35+
with:
36+
version: '3.x'
37+
repo-token: ${{ secrets.GITHUB_TOKEN }}
3338
- uses: Swatinem/rust-cache@v1
3439
with:
3540
working-directory: packages/core-bridge

package-lock.json

Lines changed: 13 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"@opentelemetry/core": "^1.3.1",
5454
"@opentelemetry/sdk-node": "^0.32.0",
5555
"@opentelemetry/semantic-conventions": "^1.3.1",
56-
"@protobuf-ts/protoc": "^2.8.1",
5756
"@tsconfig/node14": "^1.0.3",
5857
"@types/dedent": "^0.7.0",
5958
"@types/fs-extra": "^9.0.13",

packages/activity/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@
7171

7272
import { AbortSignal } from 'abort-controller';
7373
import { AsyncLocalStorage } from 'async_hooks';
74-
import { msToNumber } from '@temporalio/common';
74+
import { msToNumber } from '@temporalio/common/lib/time';
7575

7676
export {
7777
ActivityFunction,
7878
ActivityInterface, // eslint-disable-line deprecation/deprecation
7979
ApplicationFailure,
8080
CancelledFailure,
8181
UntypedActivities,
82-
msToNumber,
8382
} from '@temporalio/common';
8483

8584
/**

packages/client/src/workflow-client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ import {
2525
import {
2626
BaseWorkflowHandle,
2727
compileRetryPolicy,
28-
optionalTsToDate,
2928
QueryDefinition,
3029
SearchAttributes,
3130
SignalDefinition,
32-
tsToDate,
3331
WithWorkflowArgs,
3432
Workflow,
3533
WorkflowNotFoundError,
3634
WorkflowResultType,
3735
} from '@temporalio/common';
36+
import { optionalTsToDate, tsToDate } from '@temporalio/common/lib/time';
3837
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
3938
import { Replace } from '@temporalio/common/lib/type-helpers';
4039
import { temporal } from '@temporalio/proto';

packages/common/src/converter/payload-converter.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Payload } from '../interfaces';
1+
import { decode, encode } from '../encoding';
22
import { IllegalStateError, PayloadConverterError, ValueError } from '../errors';
3-
import { encodingKeys, encodingTypes, METADATA_ENCODING_KEY, str, u8 } from './types';
3+
import { Payload } from '../interfaces';
4+
import { encodingKeys, encodingTypes, METADATA_ENCODING_KEY } from './types';
45

56
/**
67
* Used by the framework to serialize/deserialize data like parameters and return values.
@@ -150,13 +151,13 @@ export class CompositePayloadConverter implements PayloadConverter {
150151
}
151152

152153
/**
153-
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the {@link encodingTypes | encoding type} of the {@link Payload}.
154+
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the `encoding` metadata of the {@link Payload}.
154155
*/
155156
public fromPayload<T>(payload: Payload): T {
156157
if (payload.metadata === undefined || payload.metadata === null) {
157158
throw new ValueError('Missing payload metadata');
158159
}
159-
const encoding = str(payload.metadata[METADATA_ENCODING_KEY]);
160+
const encoding = decode(payload.metadata[METADATA_ENCODING_KEY]);
160161
const converter = this.converterByEncoding.get(encoding);
161162
if (converter === undefined) {
162163
throw new ValueError(`Unknown encoding: ${encoding}`);
@@ -234,15 +235,15 @@ export class JsonPayloadConverter implements PayloadConverterWithEncoding {
234235
metadata: {
235236
[METADATA_ENCODING_KEY]: encodingKeys.METADATA_ENCODING_JSON,
236237
},
237-
data: u8(json),
238+
data: encode(json),
238239
};
239240
}
240241

241242
public fromPayload<T>(content: Payload): T {
242243
if (content.data === undefined || content.data === null) {
243244
throw new ValueError('Got payload with no data');
244245
}
245-
return JSON.parse(str(content.data));
246+
return JSON.parse(decode(content.data));
246247
}
247248
}
248249

@@ -305,7 +306,7 @@ export class SearchAttributePayloadConverter implements PayloadConverter {
305306
const value = this.jsonConverter.fromPayload(payload);
306307
let arrayWrappedValue = value instanceof Array ? value : [value];
307308

308-
const searchAttributeType = str(payload.metadata.type);
309+
const searchAttributeType = decode(payload.metadata.type);
309310
if (searchAttributeType === 'Datetime') {
310311
arrayWrappedValue = arrayWrappedValue.map((dateString) => new Date(dateString));
311312
}

packages/common/src/converter/protobuf-payload-converters.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import { PayloadConverterError, ValueError } from '../errors';
2-
import { errorMessage, hasOwnProperties, hasOwnProperty, isRecord } from '../type-helpers';
31
import * as protoJsonSerializer from 'proto3-json-serializer';
42
import type { Message, Namespace, Root, Type } from 'protobufjs';
3+
import { decode, encode } from '../encoding';
4+
import { PayloadConverterError, ValueError } from '../errors';
5+
import { Payload } from '../interfaces';
6+
import { errorMessage, hasOwnProperties, hasOwnProperty, isRecord } from '../type-helpers';
57
import {
68
BinaryPayloadConverter,
79
CompositePayloadConverter,
810
JsonPayloadConverter,
911
PayloadConverterWithEncoding,
1012
UndefinedPayloadConverter,
1113
} from './payload-converter';
12-
import { Payload } from '../interfaces';
1314

14-
import { EncodingType, encodingTypes, METADATA_ENCODING_KEY, METADATA_MESSAGE_TYPE_KEY, str, u8 } from './types';
15+
import { encodingTypes, METADATA_ENCODING_KEY, METADATA_MESSAGE_TYPE_KEY } from './types';
1516

1617
abstract class ProtobufPayloadConverter implements PayloadConverterWithEncoding {
1718
protected readonly root: Root | undefined;
18-
public abstract encodingType: EncodingType;
19+
public abstract encodingType: string;
1920

2021
public abstract toPayload<T>(value: T): Payload | undefined;
2122
public abstract fromPayload<T>(payload: Payload): T;
@@ -42,7 +43,7 @@ abstract class ProtobufPayloadConverter implements PayloadConverterWithEncoding
4243
throw new PayloadConverterError('Unable to deserialize protobuf message without `root` being provided');
4344
}
4445

45-
const messageTypeName = str(content.metadata[METADATA_MESSAGE_TYPE_KEY]);
46+
const messageTypeName = decode(content.metadata[METADATA_MESSAGE_TYPE_KEY]);
4647
let messageType;
4748
try {
4849
messageType = this.root.lookupType(messageTypeName);
@@ -62,8 +63,8 @@ abstract class ProtobufPayloadConverter implements PayloadConverterWithEncoding
6263
protected constructPayload({ messageTypeName, message }: { messageTypeName: string; message: Uint8Array }): Payload {
6364
return {
6465
metadata: {
65-
[METADATA_ENCODING_KEY]: u8(this.encodingType),
66-
[METADATA_MESSAGE_TYPE_KEY]: u8(messageTypeName),
66+
[METADATA_ENCODING_KEY]: encode(this.encodingType),
67+
[METADATA_MESSAGE_TYPE_KEY]: encode(messageTypeName),
6768
},
6869
data: message,
6970
};
@@ -122,13 +123,13 @@ export class ProtobufJsonPayloadConverter extends ProtobufPayloadConverter {
122123

123124
return this.constructPayload({
124125
messageTypeName: getNamespacedTypeName(value.$type),
125-
message: u8(JSON.stringify(jsonValue)),
126+
message: encode(JSON.stringify(jsonValue)),
126127
});
127128
}
128129

129130
public fromPayload<T>(content: Payload): T {
130131
const { messageType, data } = this.validatePayload(content);
131-
return protoJsonSerializer.fromProto3JSON(messageType, JSON.parse(str(data))) as unknown as T;
132+
return protoJsonSerializer.fromProto3JSON(messageType, JSON.parse(decode(data))) as unknown as T;
132133
}
133134
}
134135

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
import { TextDecoder, TextEncoder } from './encoding';
2-
3-
/**
4-
* Transform an *ascii* string into a Uint8Array
5-
*/
6-
export function u8(s: string): Uint8Array {
7-
return new TextEncoder().encode(s);
8-
}
9-
10-
export function str(a: Uint8Array): string {
11-
return new TextDecoder().decode(a);
12-
}
1+
import { encode } from '../encoding';
132

143
export const METADATA_ENCODING_KEY = 'encoding';
154
export const encodingTypes = {
@@ -22,11 +11,11 @@ export const encodingTypes = {
2211
export type EncodingType = typeof encodingTypes[keyof typeof encodingTypes];
2312

2413
export const encodingKeys = {
25-
METADATA_ENCODING_NULL: u8(encodingTypes.METADATA_ENCODING_NULL),
26-
METADATA_ENCODING_RAW: u8(encodingTypes.METADATA_ENCODING_RAW),
27-
METADATA_ENCODING_JSON: u8(encodingTypes.METADATA_ENCODING_JSON),
28-
METADATA_ENCODING_PROTOBUF_JSON: u8(encodingTypes.METADATA_ENCODING_PROTOBUF_JSON),
29-
METADATA_ENCODING_PROTOBUF: u8(encodingTypes.METADATA_ENCODING_PROTOBUF),
14+
METADATA_ENCODING_NULL: encode(encodingTypes.METADATA_ENCODING_NULL),
15+
METADATA_ENCODING_RAW: encode(encodingTypes.METADATA_ENCODING_RAW),
16+
METADATA_ENCODING_JSON: encode(encodingTypes.METADATA_ENCODING_JSON),
17+
METADATA_ENCODING_PROTOBUF_JSON: encode(encodingTypes.METADATA_ENCODING_PROTOBUF_JSON),
18+
METADATA_ENCODING_PROTOBUF: encode(encodingTypes.METADATA_ENCODING_PROTOBUF),
3019
} as const;
3120

3221
export const METADATA_MESSAGE_TYPE_KEY = 'messageType';

0 commit comments

Comments
 (0)