/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type * as nbformat from '@jupyterlab/nbformat';67/**8* Metadata we store in VS Code cell output items.9* This contains the original metadata from the Jupyter outputs.10*/11export interface CellOutputMetadata {12/**13* Cell output metadata.14*/15metadata?: any;1617/**18* Transient data from Jupyter.19*/20transient?: {21/**22* This is used for updating the output in other cells.23* We don't know of other properties, but this is definitely used.24*/25display_id?: string;26} & any;2728/**29* Original cell output type30*/31outputType: nbformat.OutputType | string;3233executionCount?: nbformat.IExecuteResult['ExecutionCount'];3435/**36* Whether the original Mime data is JSON or not.37* This properly only exists in metadata for NotebookCellOutputItems38* (this is something we have added)39*/40__isJson?: boolean;41}424344/**45* Metadata we store in VS Code cells.46* This contains the original metadata from the Jupyter cells.47*/48export interface CellMetadata {49/**50* Cell id for notebooks created with the new 4.5 version of nbformat.51*/52id?: string;53/**54* Stores attachments for cells.55*/56attachments?: nbformat.IAttachments;57/**58* Stores cell metadata.59*/60metadata?: Partial<nbformat.ICellMetadata> & { vscode?: { languageId?: string } };61/**62* The code cell's prompt number. Will be null if the cell has not been run.63*/64execution_count?: number | null;65}66676869type KeysOfUnionType<T> = T extends T ? keyof T : never;70type FilterType<T, TTest> = T extends TTest ? T : never;71type MakeOptionalAndBool<T extends object> = { [K in keyof T]?: boolean };7273/**74* Type guard that checks if an object has specific keys and narrows the type accordingly.75*76* @param x - The object to check77* @param key - An object with boolean values indicating which keys to check for78* @returns true if all specified keys exist in the object, false otherwise79*80* @example81* ```typescript82* type A = { a: string };83* type B = { b: number };84* const obj: A | B = getObject();85*86* if (hasKey(obj, { a: true })) {87* // obj is now narrowed to type A88* console.log(obj.a);89* }90* ```91*/92export function hasKey<T extends object, TKeys>(x: T, key: TKeys & MakeOptionalAndBool<T>): x is FilterType<T, { [K in KeysOfUnionType<T> & keyof TKeys]: unknown }> {93for (const k in key) {94if (!(k in x)) {95return false;96}97}98return true;99}100101102