Skip to content

Commit d686105

Browse files
committed
move sink check, change constant var name
1 parent 66d9456 commit d686105

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

packages/common/src/reserved.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const TEMPORAL_RESERVED_PREFIX = '__temporal_';
2-
export const STACK_TRACE_RESERVED_NAME = '__stack_trace';
3-
export const ENHANCED_STACK_TRACE_RESERVED_NAME = '__enhanced_stack_trace';
2+
export const STACK_TRACE_QUERY_NAME = '__stack_trace';
3+
export const ENHANCED_STACK_TRACE_QUERY_NAME = '__enhanced_stack_trace';
44

55
/**
66
* Valid entity types that can be checked for reserved name violations
@@ -20,7 +20,7 @@ export function throwIfReservedName(type: ReservedNameEntityType, name: string):
2020
throw new TypeError(`Cannot use ${type} name: '${name}', with reserved prefix: '${TEMPORAL_RESERVED_PREFIX}'`);
2121
}
2222

23-
if (name === STACK_TRACE_RESERVED_NAME || name === ENHANCED_STACK_TRACE_RESERVED_NAME) {
23+
if (name === STACK_TRACE_QUERY_NAME || name === ENHANCED_STACK_TRACE_QUERY_NAME) {
2424
throw new TypeError(`Cannot use ${type} name: '${name}', which is a reserved name`);
2525
}
2626
}

packages/test/src/test-integration-workflows.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import {
3232
} from '@temporalio/common';
3333
import {
3434
TEMPORAL_RESERVED_PREFIX,
35-
STACK_TRACE_RESERVED_NAME,
36-
ENHANCED_STACK_TRACE_RESERVED_NAME,
35+
STACK_TRACE_QUERY_NAME,
36+
ENHANCED_STACK_TRACE_QUERY_NAME,
3737
} from '@temporalio/common/lib/reserved';
3838
import { signalSchedulingWorkflow } from './activities/helpers';
3939
import { activityStartedSignal } from './workflows/definitions';
@@ -1456,7 +1456,7 @@ test('Workflow can return root workflow', async (t) => {
14561456
});
14571457
});
14581458

1459-
const reservedNames = [TEMPORAL_RESERVED_PREFIX, STACK_TRACE_RESERVED_NAME, ENHANCED_STACK_TRACE_RESERVED_NAME];
1459+
const reservedNames = [TEMPORAL_RESERVED_PREFIX, STACK_TRACE_QUERY_NAME, ENHANCED_STACK_TRACE_QUERY_NAME];
14601460

14611461
test('Cannot register activities using reserved prefixes', async (t) => {
14621462
const { createWorker } = helpers(t);

packages/worker/src/worker-options.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,16 @@ export function compileWorkerOptions(
932932
logger: Logger,
933933
metricMeter: MetricMeter
934934
): CompiledWorkerOptions {
935+
// Validate sink names to ensure they don't use reserved prefixes/names
936+
if (rawOpts.sinks) {
937+
for (const sinkName of Object.keys(rawOpts.sinks)) {
938+
// Allow internal sinks used by the SDK
939+
if (sinkName !== '__temporal_logger' && sinkName !== '__temporal_metrics') {
940+
throwIfReservedName('sink', sinkName);
941+
}
942+
}
943+
}
944+
935945
const opts = addDefaultWorkerOptions(rawOpts, logger, metricMeter);
936946
if (opts.maxCachedWorkflows !== 0 && opts.maxCachedWorkflows < 2) {
937947
logger.warn('maxCachedWorkflows must be either 0 (ie. cache is disabled) or greater than 1. Defaulting to 2.');
@@ -958,16 +968,6 @@ export function compileWorkerOptions(
958968
throwIfReservedName('activity', activityName);
959969
}
960970

961-
// Validate sink names to ensure they don't use reserved prefixes/names
962-
if (opts.sinks) {
963-
for (const sinkName of Object.keys(opts.sinks)) {
964-
// Allow internal sinks used by the SDK
965-
if (sinkName !== '__temporal_logger' && sinkName !== '__temporal_metrics') {
966-
throwIfReservedName('sink', sinkName);
967-
}
968-
}
969-
}
970-
971971
const tuner = asNativeTuner(opts.tuner, logger);
972972

973973
return {

packages/workflow/src/internals.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflo
3434
import type { coresdk, temporal } from '@temporalio/proto';
3535
import {
3636
TEMPORAL_RESERVED_PREFIX,
37-
STACK_TRACE_RESERVED_NAME,
38-
ENHANCED_STACK_TRACE_RESERVED_NAME,
37+
STACK_TRACE_QUERY_NAME,
38+
ENHANCED_STACK_TRACE_QUERY_NAME,
3939
} from '@temporalio/common/lib/reserved';
4040
import { alea, RNG } from './alea';
4141
import { RootCancellationScope } from './cancellation-scope';
@@ -266,7 +266,7 @@ export class Activator implements ActivationHandler {
266266
*/
267267
public readonly queryHandlers = new Map<string, WorkflowQueryAnnotatedType>([
268268
[
269-
STACK_TRACE_RESERVED_NAME,
269+
STACK_TRACE_QUERY_NAME,
270270
{
271271
handler: () => {
272272
return new RawValue<string>(
@@ -279,7 +279,7 @@ export class Activator implements ActivationHandler {
279279
},
280280
],
281281
[
282-
ENHANCED_STACK_TRACE_RESERVED_NAME,
282+
ENHANCED_STACK_TRACE_QUERY_NAME,
283283
{
284284
handler: (): RawValue => {
285285
const { sourceMap } = this;
@@ -695,8 +695,8 @@ export class Activator implements ActivationHandler {
695695
// Skip interceptors if it's an internal query.
696696
const isInternalQuery =
697697
queryType.startsWith(TEMPORAL_RESERVED_PREFIX) ||
698-
queryType === STACK_TRACE_RESERVED_NAME ||
699-
queryType === ENHANCED_STACK_TRACE_RESERVED_NAME;
698+
queryType === STACK_TRACE_QUERY_NAME ||
699+
queryType === ENHANCED_STACK_TRACE_QUERY_NAME;
700700
const interceptors = isInternalQuery ? [] : this.interceptors.inbound;
701701
const execute = composeInterceptors(interceptors, 'handleQuery', this.queryWorkflowNextHandler.bind(this));
702702
execute({
@@ -730,8 +730,8 @@ export class Activator implements ActivationHandler {
730730
// Skip interceptors if it's an internal update.
731731
const isInternalUpdate =
732732
name.startsWith(TEMPORAL_RESERVED_PREFIX) ||
733-
name === STACK_TRACE_RESERVED_NAME ||
734-
name === ENHANCED_STACK_TRACE_RESERVED_NAME;
733+
name === STACK_TRACE_QUERY_NAME ||
734+
name === ENHANCED_STACK_TRACE_QUERY_NAME;
735735
const interceptors = isInternalUpdate ? [] : this.interceptors.inbound;
736736

737737
const entry =
@@ -896,8 +896,8 @@ export class Activator implements ActivationHandler {
896896
// Skip interceptors if it's an internal signal.
897897
const isInternalSignal =
898898
signalName.startsWith(TEMPORAL_RESERVED_PREFIX) ||
899-
signalName === STACK_TRACE_RESERVED_NAME ||
900-
signalName === ENHANCED_STACK_TRACE_RESERVED_NAME;
899+
signalName === STACK_TRACE_QUERY_NAME ||
900+
signalName === ENHANCED_STACK_TRACE_QUERY_NAME;
901901
const interceptors = isInternalSignal ? [] : this.interceptors.inbound;
902902

903903
if (!this.signalHandlers.has(signalName) && !this.defaultSignalHandler) {

0 commit comments

Comments
 (0)