pulumi/sdk/nodejs/asset/archive.ts
joeduffy d5608f2fee Use x is T return types for isX functions
This change adopts `x is T` style of RTTI inquiry, which fits much
more nicely with TypeScript's typechecking flow.

Thanks to @lukehoban for teaching me a new trick today! :-)
2018-04-16 15:03:23 -07:00

78 lines
2.2 KiB
TypeScript

// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
import { Input } from "../resource";
import { Asset } from "./asset";
/**
* An Archive represents a collection of named assets.
*/
export abstract class Archive {
/**
* A private field to help with RTTI that works in SxS scenarios.
*/
// tslint:disable-next-line:variable-name
private readonly __pulumiArchive: boolean = true;
/**
* Returns true if the given object is an instance of an Archive. This is designed to work even when
* multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is Archive {
return obj && obj.__pulumiArchive;
}
}
/**
* AssetMap is a map of assets.
*/
export type AssetMap = {[name: string]: Asset | Archive};
/**
* An AssetArchive is an archive created from an in-memory collection of named assets or other archives.
*/
export class AssetArchive extends Archive {
/**
* A map of names to assets.
*/
public readonly assets: Promise<AssetMap>;
constructor(assets: AssetMap | Promise<AssetMap>) {
super();
this.assets = Promise.resolve(assets);
}
}
/**
* A FileArchive is a file-based archive, or a collection of file-based assets. This can be a raw directory or a
* single archive file in one of the supported formats (.tar, .tar.gz, or .zip).
*/
export class FileArchive extends Archive {
/**
* The path to the asset file.
*/
public readonly path: Promise<string>;
constructor(path: string | Promise<string>) {
super();
this.path = Promise.resolve(path);
}
}
/**
* A RemoteArchive is a file-based archive fetched from a remote location. The URI's scheme dictates the
* protocol for fetching the archive's contents: `file://` is a local file (just like a FileArchive), `http://` and
* `https://` specify HTTP and HTTPS, respectively, and specific providers may recognize custom schemes.
*/
export class RemoteArchive extends Archive {
/**
* The URI where the archive lives.
*/
public readonly uri: Promise<string>;
constructor(uri: string | Promise<string>) {
super();
this.uri = Promise.resolve(uri);
}
}