import { JSONObject } from 'phosphor/lib/algorithm/json'; import { IAjaxSettings } from '../utils'; /** * A namespace for contents interfaces. */ export declare namespace Contents { /** * A contents model. */ interface IModel { /** * Name of the contents file. * * #### Notes * Equivalent to the last part of the `path` field. */ name?: string; /** * The full file path. * * #### Notes * It will *not* start with `/`, and it will be `/`-delimited. */ path?: string; /** * The type of file. */ type?: ContentType; /** * Whether the requester has permission to edit the file. */ writable?: boolean; /** * File creation timestamp. */ created?: string; /** * Last modified timestamp. */ last_modified?: string; /** * Specify the mime-type of file contents. * * #### Notes * Only non-`null` when `content` is present and `type` is `"file"`. */ mimetype?: string; /** * The optional file content. */ content?: any; /** * The format of the file `content`. * * #### Notes * Only relevant for type: 'file' */ format?: FileFormat; } /** * A contents file type. */ type ContentType = 'notebook' | 'file' | 'directory'; /** * A contents file format. */ type FileFormat = 'json' | 'text' | 'base64'; /** * The options used to fetch a file. */ interface IFetchOptions extends JSONObject { /** * The override file type for the request. */ type?: ContentType; /** * The override file format for the request. */ format?: FileFormat; /** * Whether to include the file content. * * The default is `true`. */ content?: boolean; } /** * The options used to create a file. */ interface ICreateOptions extends JSONObject { /** * The directory in which to create the file. */ path?: string; /** * The optional file extension for the new file (e.g. `".txt"`). * * #### Notes * This ignored if `type` is `'notebook'`. */ ext?: string; /** * The file type. */ type?: ContentType; } /** * Checkpoint model. */ interface ICheckpointModel { /** * The unique identifier for the checkpoint. */ id: string; /** * Last modified timestamp. */ last_modified: string; } /** * The interface for a contents manager. */ interface IManager { /** * Get a file or directory. * * @param path: The path to the file. * * @param options: The options used to fetch the file. * * @returns A promise which resolves with the file content. */ get(path: string, options?: IFetchOptions): Promise; /** * Get an encoded download url given a file path. * * @param path - An absolute POSIX file path on the server. */ getDownloadUrl(path: string): string; /** * Create a new untitled file or directory in the specified directory path. * * @param options: The options used to create the file. * * @returns A promise which resolves with the created file content when the * file is created. */ newUntitled(options?: ICreateOptions): Promise; /** * Delete a file. * * @param path - The path to the file. * * @returns A promise which resolves when the file is deleted. */ delete(path: string): Promise; /** * Rename a file or directory. * * @param path - The original file path. * * @param newPath - The new file path. * * @returns A promise which resolves with the new file content model when the * file is renamed. */ rename(path: string, newPath: string): Promise; /** * Save a file. * * @param path - The desired file path. * * @param options - Optional overrrides to the model. * * @returns A promise which resolves with the file content model when the * file is saved. */ save(path: string, options?: IModel): Promise; /** * Copy a file into a given directory. * * @param path - The original file path. * * @param toDir - The destination directory path. * * @returns A promise which resolves with the new content model when the * file is copied. */ copy(path: string, toDir: string): Promise; /** * Create a checkpoint for a file. * * @param path - The path of the file. * * @returns A promise which resolves with the new checkpoint model when the * checkpoint is created. */ createCheckpoint(path: string): Promise; /** * List available checkpoints for a file. * * @param path - The path of the file. * * @returns A promise which resolves with a list of checkpoint models for * the file. */ listCheckpoints(path: string): Promise; /** * Restore a file to a known checkpoint state. * * @param path - The path of the file. * * @param checkpointID - The id of the checkpoint to restore. * * @returns A promise which resolves when the checkpoint is restored. */ restoreCheckpoint(path: string, checkpointID: string): Promise; /** * Delete a checkpoint for a file. * * @param path - The path of the file. * * @param checkpointID - The id of the checkpoint to delete. * * @returns A promise which resolves when the checkpoint is deleted. */ deleteCheckpoint(path: string, checkpointID: string): Promise; /** * Optional default settings for ajax requests, if applicable. */ ajaxSettings?: IAjaxSettings; } } /** * A contents manager that passes file operations to the server. * * This includes checkpointing with the normal file operations. */ export declare class ContentsManager implements Contents.IManager { /** * Construct a new contents manager object. * * @param options - The options used to initialize the object. */ constructor(options?: ContentsManager.IOptions); /** * Get a copy of the default ajax settings for the contents manager. */ /** * Set the default ajax settings for the contents manager. */ ajaxSettings: IAjaxSettings; /** * Get a file or directory. * * @param path: The path to the file. * * @param options: The options used to fetch the file. * * @returns A promise which resolves with the file content. * * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model. */ get(path: string, options?: Contents.IFetchOptions): Promise; /** * Get an encoded download url given a file path. * * @param path - An absolute POSIX file path on the server. * * #### Notes * It is expected that the path contains no relative paths, * use [[ContentsManager.getAbsolutePath]] to get an absolute * path if necessary. */ getDownloadUrl(path: string): string; /** * Create a new untitled file or directory in the specified directory path. * * @param options: The options used to create the file. * * @returns A promise which resolves with the created file content when the * file is created. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model. */ newUntitled(options?: Contents.ICreateOptions): Promise; /** * Delete a file. * * @param path - The path to the file. * * @returns A promise which resolves when the file is deleted. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents). */ delete(path: string): Promise; /** * Rename a file or directory. * * @param path - The original file path. * * @param newPath - The new file path. * * @returns A promise which resolves with the new file contents model when * the file is renamed. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model. */ rename(path: string, newPath: string): Promise; /** * Save a file. * * @param path - The desired file path. * * @param options - Optional overrrides to the model. * * @returns A promise which resolves with the file content model when the * file is saved. * * #### Notes * Ensure that `model.content` is populated for the file. * * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model. */ save(path: string, options?: Contents.IModel): Promise; /** * Copy a file into a given directory. * * @param path - The original file path. * * @param toDir - The destination directory path. * * @returns A promise which resolves with the new contents model when the * file is copied. * * #### Notes * The server will select the name of the copied file. * * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model. */ copy(fromFile: string, toDir: string): Promise; /** * Create a checkpoint for a file. * * @param path - The path of the file. * * @returns A promise which resolves with the new checkpoint model when the * checkpoint is created. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model. */ createCheckpoint(path: string): Promise; /** * List available checkpoints for a file. * * @param path - The path of the file. * * @returns A promise which resolves with a list of checkpoint models for * the file. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model. */ listCheckpoints(path: string): Promise; /** * Restore a file to a known checkpoint state. * * @param path - The path of the file. * * @param checkpointID - The id of the checkpoint to restore. * * @returns A promise which resolves when the checkpoint is restored. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents). */ restoreCheckpoint(path: string, checkpointID: string): Promise; /** * Delete a checkpoint for a file. * * @param path - The path of the file. * * @param checkpointID - The id of the checkpoint to delete. * * @returns A promise which resolves when the checkpoint is deleted. * * #### Notes * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents). */ deleteCheckpoint(path: string, checkpointID: string): Promise; /** * Get a REST url for a file given a path. */ private _getUrl(...args); private _baseUrl; private _ajaxSettings; } /** * A namespace for ContentsManager statics. */ export declare namespace ContentsManager { /** * The options used to intialize a contents manager. */ interface IOptions { /** * The root url of the server. */ baseUrl?: string; /** * The default ajax settings to use for the kernel. */ ajaxSettings?: IAjaxSettings; } /** * Get the absolute POSIX path to a file on the server. * * @param relativePath - The relative POSIX path to the file. * * @param cwd - The optional POSIX current working directory. The default is * an empty string. * * #### Notes * Absolute path in this context is equivalent to a POSIX path without * the initial `'/'` because IPEP 27 paths denote `''` as the root. * If the resulting path is not contained within the server root, * returns `null`, since it cannot be served. */ function getAbsolutePath(relativePath: string, cwd?: string): string; /** * Get the last portion of a path, similar to the Unix basename command. */ function basename(path: string, ext?: string): string; /** * Get the directory name of a path, similar to the Unix dirname command. */ function dirname(path: string): string; /** * Get the extension of the path. * * #### Notes * The extension is the string from the last occurance of the `.` * character to end of string in the last portion of the path. * If there is no `.` in the last portion of the path, or if the first * character of the basename of path [[basename]] is `.`, then an * empty string is returned. */ function extname(path: string): string; /** * Normalize a file extension to be of the type `'.foo'`. * * Adds a leading dot if not present and converts to lower case. */ function normalizeExtension(extension: string): string; }