Skip to content

Commit 70315ce

Browse files
committed
Flatten trigger specs
1 parent b433ca6 commit 70315ce

File tree

6 files changed

+62
-207
lines changed

6 files changed

+62
-207
lines changed

ts/src/flexible-event/main.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ if (options.json_file !== undefined) {
113113
new Config(
114114
source.maxEventLevelReports,
115115
source.attributionScopes,
116-
source.triggerSpecs.flatMap((spec) =>
117-
new Array<PerTriggerDataConfig>(spec.triggerData.size).fill(
118-
new PerTriggerDataConfig(
119-
spec.eventReportWindows.endTimes.length,
120-
spec.summaryBuckets.length
121-
)
116+
new Array<PerTriggerDataConfig>(source.triggerData.size).fill(
117+
new PerTriggerDataConfig(
118+
source.eventReportWindows.endTimes.length,
119+
source.maxEventLevelReports
122120
)
123121
)
124122
)

ts/src/header-validator/source.test.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SourceType } from '../source-type'
22
import * as vsv from '../vendor-specific-values'
33
import { Maybe } from './maybe'
4-
import { Source, SummaryOperator, TriggerDataMatching } from './source'
4+
import { Source, TriggerDataMatching } from './source'
55
import * as testutil from './util.test'
66
import * as jsontest from './validate-json.test'
77
import * as source from './validate-source'
@@ -69,17 +69,11 @@ const testCases: TestCase[] = [
6969
priority: 2n,
7070
sourceEventId: 3n,
7171
maxEventLevelReports: 2,
72-
triggerSpecs: [
73-
{
74-
eventReportWindows: {
75-
startTime: 0,
76-
endTimes: [3601],
77-
},
78-
summaryBuckets: [1, 2],
79-
summaryOperator: SummaryOperator.count,
80-
triggerData: new Set([0, 1, 2, 3, 4, 5, 6, 7]),
81-
},
82-
],
72+
eventReportWindows: {
73+
startTime: 0,
74+
endTimes: [3601],
75+
},
76+
triggerData: new Set([0, 1, 2, 3, 4, 5, 6, 7]),
8377
triggerDataMatching: TriggerDataMatching.modulus,
8478
aggregatableDebugReporting: {
8579
budget: 1234,

ts/src/header-validator/source.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ export type FilterData = Map<string, Set<string>>
1010
export type AggregationKeys = Map<string, bigint>
1111
export type NamedBudgets = Map<string, number>
1212

13-
export enum SummaryOperator {
14-
count = 'count',
15-
value_sum = 'value_sum',
16-
}
17-
18-
export type TriggerSpec = {
19-
eventReportWindows: EventReportWindows
20-
summaryBuckets: number[]
21-
summaryOperator: SummaryOperator
22-
triggerData: Set<number>
23-
}
24-
2513
export type SourceAggregatableDebugReportingConfig =
2614
reg.AggregatableDebugReportingConfig & {
2715
budget: number
@@ -49,7 +37,8 @@ export type Source = reg.CommonDebug &
4937
maxEventLevelReports: number
5038
sourceEventId: bigint
5139

52-
triggerSpecs: TriggerSpec[]
40+
eventReportWindows: EventReportWindows
41+
triggerData: Set<number>
5342
triggerDataMatching: TriggerDataMatching
5443

5544
eventLevelEpsilon: number

ts/src/header-validator/to-json.ts

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,6 @@ function serializeAggregatableDebugReportingConfig(
8181
}
8282
}
8383

84-
type EventReportWindows = {
85-
event_report_windows: { start_time: number; end_times: number[] }
86-
}
87-
88-
function serializeEventReportWindows(
89-
e: source.EventReportWindows
90-
): EventReportWindows {
91-
return {
92-
event_report_windows: {
93-
start_time: e.startTime,
94-
end_times: [...e.endTimes],
95-
},
96-
}
97-
}
98-
99-
type TriggerData = {
100-
trigger_data: number[]
101-
}
102-
103-
function serializeTriggerData(d: Set<number>): TriggerData {
104-
return { trigger_data: Array.from(d) }
105-
}
106-
10784
type SourceAggregatableDebugReportingConfig =
10885
AggregatableDebugReportingConfig & {
10986
budget: number
@@ -135,53 +112,29 @@ function serializeAttributionScopes(
135112
}
136113
}
137114

138-
type NotFullFlexSource = Partial<EventReportWindows> & {
139-
trigger_data: number[]
140-
}
141-
142-
function serializeFlexSource(s: source.Source): NotFullFlexSource {
143-
if (s.triggerSpecs.length === 0) {
144-
return { trigger_data: [] }
145-
}
146-
147-
if (s.triggerSpecs.length === 1) {
148-
return {
149-
...serializeEventReportWindows(s.triggerSpecs[0]!.eventReportWindows),
150-
...serializeTriggerData(s.triggerSpecs[0]!.triggerData),
151-
}
152-
}
153-
154-
throw new TypeError()
155-
}
156-
157115
type Source = CommonDebug &
158-
Priority &
159-
NotFullFlexSource & {
116+
Priority & {
160117
aggregation_keys: { [key: string]: string }
161118
named_budgets?: { [key: string]: number }
162119
aggregatable_report_window: number
163120
destination: string[]
164121
destination_limit_priority: string
165122
event_level_epsilon: number
123+
event_report_windows: { start_time: number; end_times: number[] }
166124
expiry: number
167125
filter_data: { [key: string]: string[] }
168126
max_event_level_reports: number
169127
source_event_id: string
128+
trigger_data: number[]
170129
trigger_data_matching: string
171130
aggregatable_debug_reporting?: SourceAggregatableDebugReportingConfig
172131
attribution_scopes?: AttributionScopes
173132
}
174133

175-
export interface Options {}
176-
177-
export function serializeSource(
178-
s: source.Source,
179-
_: Readonly<Options>
180-
): string {
134+
export function serializeSource(s: source.Source): string {
181135
const source: Source = {
182136
...serializeCommonDebug(s),
183137
...serializePriority(s),
184-
...serializeFlexSource(s),
185138

186139
aggregation_keys: Object.fromEntries(
187140
Array.from(s.aggregationKeys.entries(), ([key, val]) => [
@@ -201,9 +154,14 @@ export function serializeSource(
201154
destination: Array.from(s.destination),
202155
destination_limit_priority: s.destinationLimitPriority.toString(),
203156
event_level_epsilon: s.eventLevelEpsilon,
157+
event_report_windows: {
158+
start_time: s.eventReportWindows.startTime,
159+
end_times: [...s.eventReportWindows.endTimes],
160+
},
204161
expiry: s.expiry,
205162
max_event_level_reports: s.maxEventLevelReports,
206163
source_event_id: s.sourceEventId.toString(),
164+
trigger_data: Array.from(s.triggerData),
207165
trigger_data_matching: s.triggerDataMatching,
208166
...ifNotNull(
209167
'aggregatable_debug_reporting',
@@ -352,10 +310,7 @@ type Trigger = CommonDebug &
352310
attribution_scopes?: string[]
353311
}
354312

355-
export function serializeTrigger(
356-
t: trigger.Trigger,
357-
_: Readonly<Options>
358-
): string {
313+
export function serializeTrigger(t: trigger.Trigger): string {
359314
const trigger: Trigger = {
360315
...serializeCommonDebug(t),
361316
...serializeFilterPair(t),

0 commit comments

Comments
 (0)