UNPKG

3.75 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Observable } from 'rxjs';
9import { Path, PathFragment } from '../path';
10import { FileBuffer, Host, HostCapabilities, HostWatchOptions, ReadonlyHost, Stats } from './interface';
11import { SimpleMemoryHost } from './memory';
12export interface CordHostCreate {
13 kind: 'create';
14 path: Path;
15 content: FileBuffer;
16}
17export interface CordHostOverwrite {
18 kind: 'overwrite';
19 path: Path;
20 content: FileBuffer;
21}
22export interface CordHostRename {
23 kind: 'rename';
24 from: Path;
25 to: Path;
26}
27export interface CordHostDelete {
28 kind: 'delete';
29 path: Path;
30}
31export type CordHostRecord = CordHostCreate | CordHostOverwrite | CordHostRename | CordHostDelete;
32/**
33 * A Host that records changes to the underlying Host, while keeping a record of Create, Overwrite,
34 * Rename and Delete of files.
35 *
36 * This is fully compatible with Host, but will keep a staging of every changes asked. That staging
37 * follows the principle of the Tree (e.g. can create a file that already exists).
38 *
39 * Using `create()` and `overwrite()` will force those operations, but using `write` will add
40 * the create/overwrite records IIF the files does/doesn't already exist.
41 */
42export declare class CordHost extends SimpleMemoryHost {
43 protected _back: ReadonlyHost;
44 protected _filesToCreate: Set<Path>;
45 protected _filesToRename: Map<Path, Path>;
46 protected _filesToRenameRevert: Map<Path, Path>;
47 protected _filesToDelete: Set<Path>;
48 protected _filesToOverwrite: Set<Path>;
49 constructor(_back: ReadonlyHost);
50 get backend(): ReadonlyHost;
51 get capabilities(): HostCapabilities;
52 /**
53 * Create a copy of this host, including all actions made.
54 * @returns {CordHost} The carbon copy.
55 */
56 clone(): CordHost;
57 /**
58 * Commit the changes recorded to a Host. It is assumed that the host does have the same structure
59 * as the host that was used for backend (could be the same host).
60 * @param host The host to create/delete/rename/overwrite files to.
61 * @param force Whether to skip existence checks when creating/overwriting. This is
62 * faster but might lead to incorrect states. Because Hosts natively don't support creation
63 * versus overwriting (it's only writing), we check for existence before completing a request.
64 * @returns An observable that completes when done, or error if an error occured.
65 */
66 commit(host: Host, force?: boolean): Observable<void>;
67 records(): CordHostRecord[];
68 /**
69 * Specialized version of {@link CordHost#write} which forces the creation of a file whether it
70 * exists or not.
71 * @param {} path
72 * @param {FileBuffer} content
73 * @returns {Observable<void>}
74 */
75 create(path: Path, content: FileBuffer): Observable<void>;
76 overwrite(path: Path, content: FileBuffer): Observable<void>;
77 write(path: Path, content: FileBuffer): Observable<void>;
78 read(path: Path): Observable<FileBuffer>;
79 delete(path: Path): Observable<void>;
80 rename(from: Path, to: Path): Observable<void>;
81 list(path: Path): Observable<PathFragment[]>;
82 exists(path: Path): Observable<boolean>;
83 isDirectory(path: Path): Observable<boolean>;
84 isFile(path: Path): Observable<boolean>;
85 stat(path: Path): Observable<Stats | null> | null;
86 watch(path: Path, options?: HostWatchOptions): null;
87 willCreate(path: Path): boolean;
88 willOverwrite(path: Path): boolean;
89 willDelete(path: Path): boolean;
90 willRename(path: Path): boolean;
91 willRenameTo(path: Path, to: Path): boolean;
92}