Skip to content

Commit 256cd27

Browse files
authored
refactor(decode-payload): clean up decode-payload.ts API surface (#3302)
* docs: add decode-payload usage report and refactoring recommendations * refactor(decode-payload): remove convertPayloadToJsonWithCodec and decodeAllPotentialPayloadsWithCodec Replace all call sites with cloneAllPotentialPayloadsWithCodec directly, eliminating the duplicate recursive walker and its named-param wrapper. * refactor(decode-payload): rename functions for clarity decodePayload → decodeRawPayload decodePayloads → applyCodecToPayloads decodeReadablePayloads → decodePayloadsWithCodec decodeSingleReadablePayloadWithCodec → decodeUserMetadataPayload cloneAllPotentialPayloadsWithCodec → decodeEventAttributes isSinglePayload → isRawPayload * refactor(decode-payload): remove namespace param from decodeEventAttributes The namespace argument was unused inside the function body. Removing it simplifies all call sites and makes the signature match actual behavior. * refactor(decode-payload): isolate returnDataOnly=false into decodeEventAttributesForExport Remove the returnDataOnly parameter from the public decodeEventAttributes API. Extract a dedicated decodeEventAttributesForExport function for the two callers (export-history, workflow-service) that need to preserve the full payload structure with metadata. * refactor(decode-payload): unify searchAttributes decode branches Collapse the two separate branches in decodePayloadAttributes — one for indexedFields and one for flat searchAttributes — into a single branch that selects the correct target object via ternary. Fix stale test mocks in get-event-attributes and to-event-history that still referenced the removed convertPayloadToJsonWithCodec export. * refactor(decode-payload): remove settings from decode-payload/data-encoder cascade data-encoder.ts now reads settings and namespace directly from page state instead of accepting them as parameters. This removes the need to thread settings through every call site in the chain: components → services → decode-payload → data-encoder. - codeServerRequest/decodePayloadsWithCodec/encodePayloadsWithCodec drop settings+namespace params - decodeEventAttributes/decodeEventAttributesForExport drop settings param - getEventAttributes takes HistoryEvent directly instead of EventWithMetadata - EventRequestMetadata.settings field removed - pending-activities model deleted (settings removal collapsed it to a no-op wrapper) - All tests updated to set codecEndpoint/passAccessToken/includeCredentials stores directly * add call site map * add phases * rename * fix tests * fix workflow query and metadata call sites * remove AI generated docs * Add inline comments to decode-payload utils
1 parent 55767fc commit 256cd27

35 files changed

Lines changed: 413 additions & 789 deletions

src/lib/components/event/event-summary-row.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,12 @@
187187
188188
onMount(async () => {
189189
if (isLocalActivityMarkerEvent(event)) {
190-
primaryLocalAttribute = await decodeLocalActivity(event, {
191-
namespace: page.params.namespace,
192-
settings: page.data.settings,
193-
});
190+
primaryLocalAttribute = await decodeLocalActivity(event);
194191
} else if (
195192
isEventGroup(event) &&
196193
isLocalActivityMarkerEvent(event.initialEvent)
197194
) {
198-
primaryLocalAttribute = await decodeLocalActivity(event.initialEvent, {
199-
namespace: page.params.namespace,
200-
settings: page.data.settings,
201-
});
195+
primaryLocalAttribute = await decodeLocalActivity(event.initialEvent);
202196
}
203197
});
204198
</script>

src/lib/components/event/metadata-decoder.svelte

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
3-
42
import type { Payload } from '$lib/types';
5-
import { decodeSingleReadablePayloadWithCodec } from '$lib/utilities/decode-payload';
6-
import {
7-
getCodecEndpoint,
8-
getCodecIncludeCredentials,
9-
getCodecPassAccessToken,
10-
} from '$lib/utilities/get-codec';
3+
import { decodeUserMetadata } from '$lib/utilities/decode-payload';
114
125
export let value: Payload | undefined = undefined;
136
export let fallback: string = '';
@@ -18,19 +11,6 @@
1811
1912
let decodedValue = '';
2013
21-
$: endpoint = getCodecEndpoint($page.data.settings);
22-
$: passAccessToken = getCodecPassAccessToken($page.data.settings);
23-
$: includeCredentials = getCodecIncludeCredentials($page.data.settings);
24-
$: settings = {
25-
...$page.data.settings,
26-
codec: {
27-
...$page.data.settings?.codec,
28-
endpoint,
29-
passAccessToken,
30-
includeCredentials,
31-
},
32-
};
33-
3414
const setPrefix = (metadata: string) => {
3515
if (prefix) {
3616
metadata = `${prefix} • ${metadata}`;
@@ -44,10 +24,7 @@
4424
if (!_value) return fallback;
4525
if (decodedValue) return decodedValue;
4626
47-
const metadata = await decodeSingleReadablePayloadWithCodec(
48-
_value,
49-
settings,
50-
);
27+
const metadata = await decodeUserMetadata(_value);
5128
5229
if (typeof metadata === 'string') {
5330
decodedValue = setPrefix(metadata);

src/lib/components/event/payload-decoder.svelte

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
<script lang="ts">
22
import { onMount, type Snippet } from 'svelte';
33
4-
import { page } from '$app/stores';
5-
64
import type { Memo } from '$lib/types';
75
import type { EventAttribute, WorkflowEvent } from '$lib/types/events';
86
import {
9-
cloneAllPotentialPayloadsWithCodec,
10-
decodePayloadAttributes,
7+
decodeEventAttributes,
8+
parsePayloadAttributes,
119
type PotentiallyDecodable,
1210
} from '$lib/utilities/decode-payload';
13-
import {
14-
getCodecEndpoint,
15-
getCodecIncludeCredentials,
16-
getCodecPassAccessToken,
17-
} from '$lib/utilities/get-codec';
1811
import { stringifyWithBigInt } from '$lib/utilities/parse-with-big-int';
1912
2013
interface Props {
@@ -36,22 +29,9 @@
3629
const decodePayloads = async (
3730
_value: PotentiallyDecodable | EventAttribute | WorkflowEvent | Memo,
3831
) => {
39-
const settings = {
40-
...$page.data.settings,
41-
codec: {
42-
...$page.data.settings?.codec,
43-
endpoint: getCodecEndpoint($page.data.settings),
44-
passAccessToken: getCodecPassAccessToken($page.data.settings),
45-
includeCredentials: getCodecIncludeCredentials($page.data.settings),
46-
},
47-
};
4832
try {
49-
const convertedAttributes = await cloneAllPotentialPayloadsWithCodec(
50-
_value,
51-
$page.params.namespace,
52-
settings,
53-
);
54-
const decodedAttributes = decodePayloadAttributes(
33+
const convertedAttributes = await decodeEventAttributes(_value);
34+
const decodedAttributes = parsePayloadAttributes(
5535
convertedAttributes,
5636
) as object;
5737
const keyExists = key && decodedAttributes?.[key];

src/lib/components/lines-and-dots/svg/timeline-graph-row.svelte

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@
6464
const localActivityEvent = getLocalActivityMarkerEvent(group);
6565
if (localActivityEvent) {
6666
try {
67-
decodedLocalActivity = await decodeLocalActivity(localActivityEvent, {
68-
namespace: page.params.namespace,
69-
settings: page.data.settings,
70-
});
67+
decodedLocalActivity = await decodeLocalActivity(localActivityEvent);
7168
7269
if (decodedLocalActivity) {
7370
group.decodedLocalActivity = decodedLocalActivity;

src/lib/components/schedule/schedule-form/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { z } from 'zod/v3';
33
import { searchAttributesSchema } from '$lib/stores/search-attributes';
44
import type { FullSchedule } from '$lib/types/schedule';
55
import type { SearchAttributes } from '$lib/types/workflows';
6-
import { decodePayloadAttributes } from '$lib/utilities/decode-payload';
6+
import { parsePayloadAttributes } from '$lib/utilities/decode-payload';
77

88
import type { SearchAttribute } from '$types';
99

@@ -61,8 +61,8 @@ export const getDefaultValues = (params: {
6161
scheduleId,
6262
} = params;
6363

64-
const decodedSearchAttributes = decodePayloadAttributes({ searchAttributes });
65-
const decodedWorkflowSearchAttributes = decodePayloadAttributes({
64+
const decodedSearchAttributes = parsePayloadAttributes({ searchAttributes });
65+
const decodedWorkflowSearchAttributes = parsePayloadAttributes({
6666
searchAttributes: schedule?.action?.startWorkflow?.searchAttributes ?? {},
6767
});
6868

src/lib/components/schedule/schedule-search-attributes.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import Accordion from '$lib/holocene/accordion/accordion.svelte';
33
import { translate } from '$lib/i18n/translate';
44
import type { SearchAttribute } from '$lib/types';
5-
import { decodePayloadAttributes } from '$lib/utilities/decode-payload';
5+
import { parsePayloadAttributes } from '$lib/utilities/decode-payload';
66
import { payloadToString } from '$lib/utilities/payload-to-string';
77
import { pluralize } from '$lib/utilities/pluralize';
88
99
export let searchAttributes: SearchAttribute;
1010
11-
$: decodedSearchAttributes = decodePayloadAttributes({ searchAttributes });
11+
$: decodedSearchAttributes = parsePayloadAttributes({ searchAttributes });
1212
$: indexedFields =
1313
decodedSearchAttributes?.searchAttributes.indexedFields ?? {};
1414
$: searchAttributeCount = Object.keys(indexedFields).length;

src/lib/components/schedule/schedules-table-row.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import Link from '$lib/holocene/link.svelte';
77
import { translate } from '$lib/i18n/translate';
88
import type { ConfigurableTableHeader } from '$lib/stores/configurable-table-columns';
9-
import { decodePayloadAttributes } from '$lib/utilities/decode-payload';
9+
import { parsePayloadAttributes } from '$lib/utilities/decode-payload';
1010
import { routeForSchedule, routeForWorkflow } from '$lib/utilities/route-for';
1111
1212
import ScheduleFrequency from './schedule-frequency.svelte';
@@ -25,7 +25,7 @@
2525
const spec = $derived(schedule?.info?.spec);
2626
const searchAttributes = $derived(schedule?.searchAttributes ?? {});
2727
const decodedAttributes = $derived(
28-
decodePayloadAttributes({ searchAttributes }),
28+
parsePayloadAttributes({ searchAttributes }),
2929
);
3030
3131
const sortRecentActions = (recentActions: ScheduleActionResult[]) => {

src/lib/components/workflow/download-event-history-modal.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
3-
42
import Modal from '$lib/holocene/modal.svelte';
53
import RadioGroup from '$lib/holocene/radio-input/radio-group.svelte';
64
import RadioInput from '$lib/holocene/radio-input/radio-input.svelte';
@@ -21,7 +19,6 @@
2119
namespace,
2220
workflowId,
2321
runId,
24-
settings: $page.data.settings,
2522
decodeSetting: $downloadEventHistorySetting,
2623
});
2724
};

src/lib/components/workflow/metadata/workflow-current-details.svelte

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@
2323
if (!workflow || loading) return;
2424
loading = true;
2525
try {
26-
const { settings } = page.data;
27-
const metadata = await getWorkflowMetadata(
28-
{
29-
namespace,
30-
workflow: {
31-
id: workflow.id,
32-
runId: workflow.runId,
33-
},
26+
const metadata = await getWorkflowMetadata({
27+
namespace,
28+
workflow: {
29+
id: workflow.id,
30+
runId: workflow.runId,
3431
},
35-
settings,
36-
);
32+
});
3733
$workflowRun.metadata = metadata;
3834
lastFetched = new Date();
3935
} catch (error) {

src/lib/layouts/workflow-run-layout.svelte

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import type { NetworkError } from '$lib/types/global';
3333
import type { WorkflowExecution } from '$lib/types/workflows';
3434
import { copyToClipboard } from '$lib/utilities/copy-to-clipboard';
35-
import { decodeSingleReadablePayloadWithCodec } from '$lib/utilities/decode-payload';
35+
import { decodeUserMetadata } from '$lib/utilities/decode-payload';
3636
import { stringifyWithBigInt } from '$lib/utilities/parse-with-big-int';
3737
3838
$: ({ namespace, workflow: workflowId, run: runId } = $page.params);
@@ -49,21 +49,17 @@
4949
copy(e, stringifyWithBigInt(fullJson));
5050
};
5151
52-
const decodeUserMetadata = async (workflow: WorkflowExecution) => {
52+
const decodeWorkflowUserMetadata = async (workflow: WorkflowExecution) => {
5353
const userMetadata = { summary: '', details: '' };
5454
try {
5555
if (workflow?.summary) {
56-
const decodedSummary = await decodeSingleReadablePayloadWithCodec(
57-
workflow.summary,
58-
);
56+
const decodedSummary = await decodeUserMetadata(workflow.summary);
5957
if (typeof decodedSummary === 'string') {
6058
userMetadata.summary = decodedSummary;
6159
}
6260
}
6361
if (workflow?.details) {
64-
const decodedDetails = await decodeSingleReadablePayloadWithCodec(
65-
workflow.details,
66-
);
62+
const decodedDetails = await decodeUserMetadata(workflow.details);
6763
if (typeof decodedDetails === 'string') {
6864
userMetadata.details = decodedDetails;
6965
}
@@ -96,7 +92,7 @@
9692
return;
9793
}
9894
99-
await decodeUserMetadata(workflow);
95+
await decodeWorkflowUserMetadata(workflow);
10096
10197
const { taskQueue } = workflow;
10298
const workers = await getPollers({ queue: taskQueue, namespace });
@@ -114,7 +110,6 @@
114110
runId,
115111
},
116112
},
117-
settings,
118113
workflowRunController.signal,
119114
).then((metadata) => {
120115
$workflowRun.metadata = metadata;

0 commit comments

Comments
 (0)