@altostra/core
Version:
Core library for shared types and logic
94 lines (93 loc) • 3.75 kB
TypeScript
/// <reference types="node" />
import { inspect } from 'util';
import type { ResourceId } from "../Blueprint/Blueprint";
import type { Connection, ConnectionByType, ConnectionKindType } from "../Blueprint/Connection";
import type { ConnectionBase, ConnectionType } from "../Connections";
import { ConnectionId } from "../Connections";
import { ParameterPathBuilder } from "../Parameters";
import type { BlueprintHelper } from "./BlueprintHelper";
import type { ConnectionUtilities } from "./ConnectionsUtils";
import type { Parameterized } from "./Parameters";
import type { ResourceHelper } from "./ResourceHelper";
/**
* A ParameterizedConnection<T> has non parameterized basic resource properties
* and parameterized other properties
*/
export declare type ParameterizedConnection<T extends Connection = Connection> = Parameterized<Omit<T, keyof ConnectionBase>> & Pick<T, keyof ConnectionBase>;
export declare type ParameterizedConnectionByType<T extends ConnectionType = ConnectionType> = ParameterizedConnection<ConnectionByType[T]>;
export declare class ConnectionHelper<T extends ConnectionType = ConnectionType> {
#private;
private readonly _blueprint;
private readonly _wrappersCache;
private _connection;
readonly id: ConnectionId;
constructor(_blueprint: BlueprintHelper, _wrappersCache: WeakMap<Connection, ConnectionHelper>, _connection: ConnectionByType[T]);
/**
* Checks whether the connection is valid.
*/
get isValid(): boolean;
get type(): T;
/**
* The source resource of the connection.
*/
get source(): ResourceHelper;
set source(resource: ResourceHelper);
/**
* The target resource of the connection.
*/
get target(): ResourceHelper;
set target(resource: ResourceHelper);
/**
* The source resource id of the connection.
*/
get sourceId(): ResourceId;
/**
* The target resource id of the connection.
*/
get targetId(): ResourceId;
/**
* The connection object in the blueprint.
*/
get connection(): ConnectionByType[T];
get rootPath(): ParameterPathBuilder;
get connectionUtils(): ConnectionUtilities<T>;
/**
* Update connection data.
* @param connection An object with connection properties to update.
* @returns `this`.
*/
edit(connection: Partial<Connection>): this;
/**
* Update connection with parameterized data.
* @param connection Object that contains parameterized connection properties to update.
* @returns `this`.
*/
parameterizedEdit(connection: Partial<ParameterizedConnectionByType<T>>): this;
/**
* Check if this connection's type is one of the specified types.
*/
is<TType extends ConnectionKindType>(...types: readonly [TType, ...TType[]]): this is ConnectionHelperByType<TType>;
getParameterizedConnection(): ParameterizedConnectionByType<T>;
/**
* DO NOT USE
*/
setParameterizedConnection(connection: ParameterizedConnectionByType<T>): ParameterizedConnectionByType<T>;
/**
* Asserts that the connection type is one of the provided type.
* @param type The types to assert the current connection.
*/
assertType<TType extends ConnectionKindType>(...type: [TType, ...TType[]]): asserts this is ConnectionHelperByType<TType>;
/**
* Throws an error if the connection is invalid.
*/
validateConnection(): void;
toJSON(): object;
[inspect.custom](): unknown;
}
/**
* Transforms `T1 | T2` into `ConnectionHelper<T1> | ConnectionHelper<T2>` \
* Use instead of `ConnectionHelper<T1 | T2>`
*/
export declare type ConnectionHelperByType<TType extends ConnectionKindType> = {
[K in TType]: ConnectionHelper<K>;
}[TType];