// Copyright (C) 2023 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // A single value. These are often retived from trace_processor so // need to map to the related sqlite type: // null = NULL, string = TEXT, number = INTEGER/REAL, boolean = INTEGER export type Primitive = null|string|boolean|number; export const NullType = null; export const NumType = 0 as const; export const StrType = 'str' as const; export const IdType = 'id' as const; export const BoolType = true as const; // Values may be of any of the above types: type KeyType = typeof NumType|typeof StrType|typeof NullType|typeof IdType|typeof BoolType; // KeySet is a specification for the key/value pairs on an Event. // - Every event must have a string ID. // - In addition Events may have 1 or more key/value pairs. // The *specification* for the key/value pair has to be *precisely* one // of the KeySet constants above. So: // const thisTypeChecks: KeySet = { id: IdType, foo: StrType }; // const thisDoesNot: KeySet = { id: IdType, foo: "bar" }; // Since although are is a string it's not a KeySet. export type KeySet = { readonly id: typeof IdType, readonly [key: string]: KeyType, }; export interface EmptyKeySet extends KeySet { readonly id: typeof IdType; } // A particular key/value pair on an Event matches the relevant entry // on the KeySet if the KeyType and the value type 'match': // IdType => string // StrType => string // BoolType => boolean // NullType => null // NumType => number type IsExactly
= P extends Q ? (Q extends P ? any : never) : never;
type IsId = P&Q;
// An EventSet is a:
// - ordered
// - immutable
// - subset
// of events in the trace.
export interface EventSet {
// All possible keys for Events in this EventSet.
readonly keys: KeySet;
// Methods for refining the set.
// Note: these are all synchronous - we expect the cost (and hence
// any asynchronous queries) to be deferred to analysis time.
filter(...filters: Filter[]): EventSet ;
sort(...sorts: Sort[]): EventSet ;
union(other: EventSet
): EventSet
(other: EventSet
): EventSet