xref: /aosp_15_r20/external/perfetto/ui/src/public/route_schema.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1// Copyright (C) 2024 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {z} from 'zod';
16
17// We use .catch(undefined) on every field below to make sure that passing an
18// invalid value doesn't invalidate the other keys which might be valid.
19// Zod default behaviour is atomic: either everything validates correctly or
20// the whole parsing fails.
21export const ROUTE_SCHEMA = z
22  .object({
23    // The local_cache_key is special and is persisted across navigations.
24    local_cache_key: z.string().optional().catch(undefined),
25
26    // These are transient and are really set only on startup.
27
28    // Are we loading a trace via ABT.
29    openFromAndroidBugTool: z.boolean().optional().catch(undefined),
30
31    // For permalink hash.
32    s: z.string().optional().catch(undefined),
33
34    // DEPRECATED: for #!/record?p=cpu subpages (b/191255021).
35    p: z.string().optional().catch(undefined),
36
37    // For fetching traces from Cloud Storage or local servers
38    // as with record_android_trace.
39    url: z.string().optional().catch(undefined),
40
41    // For connecting to a trace_processor_shell --httpd instance running on a
42    // non-standard port. This requires the CSP_WS_PERMISSIVE_PORT flag to relax
43    // the Content Security Policy.
44    rpc_port: z.string().regex(/\d+/).optional().catch(undefined),
45
46    // Override the referrer. Useful for scripts such as
47    // record_android_trace to record where the trace is coming from.
48    referrer: z.string().optional().catch(undefined),
49
50    // For the 'mode' of the UI. For example when the mode is 'embedded'
51    // some features are disabled.
52    mode: z.enum(['embedded']).optional().catch(undefined),
53
54    // Should we hide the sidebar?
55    hideSidebar: z.boolean().optional().catch(undefined),
56
57    // A comma-separated list of plugins to enable for the current session.
58    enablePlugins: z.string().optional().catch(undefined),
59
60    // Deep link support
61    table: z.string().optional().catch(undefined),
62    ts: z.string().optional().catch(undefined),
63    dur: z.string().optional().catch(undefined),
64    tid: z.string().optional().catch(undefined),
65    pid: z.string().optional().catch(undefined),
66    query: z.string().optional().catch(undefined),
67    visStart: z.string().optional().catch(undefined),
68    visEnd: z.string().optional().catch(undefined),
69  })
70  // default({}) ensures at compile-time that every entry is either optional or
71  // has a default value.
72  .default({});
73
74export type RouteArgs = z.infer<typeof ROUTE_SCHEMA>;
75