New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pulumi/query

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pulumi/query - npm Package Compare versions

Comparing version

to
0.0.1-dev.1558545876

6

asyncQueryable.d.ts
import { IterableBase } from "./base";
import { AsyncQueryable, AsyncQuerySource, Grouping, Operator, OrderKey } from "./interfaces";
import { AsyncQueryable, AsyncQueryableGrouping, AsyncQuerySource, Operator, OrderKey } from "./interfaces";
export declare class AsyncQueryableImpl<TSource> extends IterableBase<TSource> implements AsyncQueryable<TSource> {

@@ -19,3 +19,3 @@ static from<TSource>(source: AsyncQuerySource<TSource>): AsyncQueryableImpl<TSource>;

orderByDescending(keySelector: (t: TSource) => OrderKey | Promise<OrderKey>): AsyncQueryable<TSource>;
groupBy<TKey, TResult = TSource>(keySelector: (t: TSource) => TKey | Promise<TKey>, elementSelector?: (t: TSource) => TResult | Promise<TResult>): AsyncQueryable<Grouping<TKey, TResult>>;
groupBy<TKey, TResult = TSource>(keySelector: (t: TSource) => TKey | Promise<TKey>, elementSelector?: (t: TSource) => TResult | Promise<TResult>): AsyncQueryable<AsyncQueryableGrouping<TKey, TResult>>;
distinct(): AsyncQueryable<TSource>;

@@ -62,5 +62,5 @@ union(second: AsyncQuerySource<TSource>): AsyncQueryable<TSource>;

}
export declare class GroupingImpl<TKey, TSource> extends AsyncQueryableImpl<TSource> implements Grouping<TKey, TSource> {
export declare class GroupingImpl<TKey, TSource> extends AsyncQueryableImpl<TSource> implements AsyncQueryableGrouping<TKey, TSource> {
readonly key: TKey;
constructor(key: TKey, group: AsyncIterableIterator<TSource>);
}
import { AsyncQueryable, AsyncQuerySource } from "./interfaces";
export { AsyncQueryable } from "./interfaces";
export { AsyncQueryable, AsyncQueryableGrouping, OrderKey } from "./interfaces";
/**
* Creates an `AsyncQueryable` from things that look `Iterable` or `AsyncIterable`, even if they're
* wrapped in a `Promise`.
* @param source Object to convert into an `AsyncQueryable`.
*/
export declare function from<TSource>(source: AsyncQuerySource<TSource>): AsyncQueryable<TSource>;
/**
* Generates a (potentially infinite) sequence of integral numbers within a range. The first number
* emitted is `start`, and the last is `stop - 1`. If the enumerated sequence generates zero
* elements (for example, when `stop <= start + 1`), an exception is thrown.
* @param start Beginning of the range
* @param stop Non-inclusive end of the range.
* @example
* const squares = await range(0, 3).map(x => x * x).toArray(); // == [0, 1, 4]
*/
export declare function range(start: number, stop?: number): AsyncQueryable<number>;
/**
* Returns an empty sequence of `TResult`.
* @example
* const noNumbers = await empty<number>().toArray(); // == []
*/
export declare function empty<TResult>(): AsyncIterableIterator<TResult>;
export declare function singleton<TSource>(t: TSource): AsyncIterableIterator<TSource>;
/**
* Generates a (potentially infinite) sequence by repeating a single value.
* @param t Object to repeat
* @example
* const ones = await repeat(1).take(3).toArray(); // == [1, 1, 1]
*/
export declare function repeat<TSource>(t: TSource): void;

@@ -39,2 +39,7 @@ "use strict";

const sources = require("./sources");
/**
* Creates an `AsyncQueryable` from things that look `Iterable` or `AsyncIterable`, even if they're
* wrapped in a `Promise`.
* @param source Object to convert into an `AsyncQueryable`.
*/
function from(source) {

@@ -44,2 +49,11 @@ return asyncQueryable_1.AsyncQueryableImpl.from(source);

exports.from = from;
/**
* Generates a (potentially infinite) sequence of integral numbers within a range. The first number
* emitted is `start`, and the last is `stop - 1`. If the enumerated sequence generates zero
* elements (for example, when `stop <= start + 1`), an exception is thrown.
* @param start Beginning of the range
* @param stop Non-inclusive end of the range.
* @example
* const squares = await range(0, 3).map(x => x * x).toArray(); // == [0, 1, 4]
*/
function range(start, stop) {

@@ -49,2 +63,7 @@ return asyncQueryable_1.AsyncQueryableImpl.from(sources.range(start, stop));

exports.range = range;
/**
* Returns an empty sequence of `TResult`.
* @example
* const noNumbers = await empty<number>().toArray(); // == []
*/
function empty() {

@@ -54,7 +73,9 @@ return asyncQueryable_1.AsyncQueryableImpl.from(sources.from([]));

exports.empty = empty;
function singleton(t) {
return asyncQueryable_1.AsyncQueryableImpl.from(sources.from([t]));
}
exports.singleton = singleton;
function repeat(t) {
/**
* Generates a (potentially infinite) sequence by repeating a single value.
* @param t Object to repeat
* @example
* const ones = await repeat(1).take(3).toArray(); // == [1, 1, 1]
*/
function repeat(t /* TODO: add optional count. */) {
asyncQueryable_1.AsyncQueryableImpl.from((function () {

@@ -61,0 +82,0 @@ return __asyncGenerator(this, arguments, function* () {

@@ -8,45 +8,275 @@ export declare function isAsyncIterable<T>(o: any): o is AsyncIterable<T>;

export interface AsyncQueryable<TSource> extends AsyncIterableIterator<TSource> {
filter(f: (t: TSource, i: number) => boolean | Promise<boolean>): AsyncQueryable<TSource>;
flatMap<TInner, TResult = TInner>(selector: (t: TSource, index: number) => AsyncQuerySource<TInner>, resultSelector?: (t: TSource, ti: TInner) => TResult | Promise<TResult>): AsyncQueryable<TResult>;
map<U>(f: (t: TSource, i: number) => U | Promise<U>): AsyncQueryable<U>;
/**
* Filters out all elements in a sequence for which `predicate` does not return true.
* @param predicate
* @example
* await range(0, 3).filter(x => x < 2).toArray(); // == [0, 1]
*/
filter(predicate: (t: TSource, i: number) => boolean | Promise<boolean>): AsyncQueryable<TSource>;
/**
* Transforms each element in a sequence of `TSource` to some number of `TResult`, flattening
* the result into a single sequence of `TResult`.
*
* `transform` performs this transformation. An optional transformation,
* `intermediateTransform`, pairs each element of the flattened sequence with the input that was
* passed to `transform` to generate it, and returning some arbitrary transformation. See
* examples for where this is useful.
* @param transform Function performing the transformation of one `TSource` element into many
* `TResult`.
* @param intermediateTransform Optionally allows transformation of each element of the
* flattened list resulting from `transform`.
* @example
* await from([[1], [2], [3]]).flatMap(x => x).toArray(); // == [1, 2, 3]
* @example
* // Take a sequence of customers, then for each order, produce a tuple `[customer, order]`.
* await customers.flatMap(customer => customer.orders, (customer, order) => [customer, order]);
*/
flatMap<TInner, TResult = TInner>(transform: (t: TSource, index: number) => AsyncQuerySource<TInner>, // TODO: Make this iterable.
resultTransform?: (t: TSource, ti: TInner) => TResult | Promise<TResult>): AsyncQueryable<TResult>;
/**
* Transforms a sequence of `TSource` into a sequence of `TResult` by calling `transform` on
* every element in the sequence.
* @param transform Function performing the transformation of `TSource` to `TResult`.
* @example
* await range(0, 2).map(x => x * x).toArray(); // == [0, 1, 4]
*/
map<TResult>(transform: (t: TSource, i: number) => TResult | Promise<TResult>): AsyncQueryable<TResult>;
/**
* Skips `n` elements of a sequence, then yields the remainder of the sequence.
* @param n Number of elements to skip
* @example
* await range(0, 3).skip(2).toArray(); // == [2]
*/
skip(n: number): AsyncQueryable<TSource>;
/**
* Skips elements in a sequence while `predicate` returns `true` and then yields the rest of the
* sequence without testing `predicate` again.
* @param predicate Tests whether we should keep skipping elements
* @example
* await from([1, 2, 3, 4]).skipWhile(x => x < 2).toArray() // == [2, 3, 4]
*/
skipWhile(predicate: (t: TSource, i: number) => boolean | Promise<boolean>): AsyncQueryable<TSource>;
/**
* Takes `n` elements of a sequence, then skips the remainder of the sequence.
* @param n Number of elements to take from the sequence
* @example
* await range(0, 3).take(2).toArray(); // == [0, 1]
*/
take(n: number): AsyncQueryable<TSource>;
/**
* Takes elements in a sequence while `predicate` returns `true` and then skips the rest of
* the sequence without testing `predicate` again.
* @param predicate Tests whether we should keep taking elements
* @example
* await from([1, 2, 3, 4]).takeWhile(x => x < 2).toArray() // == [1]
*/
takeWhile(predicate: (t: TSource, i: number) => boolean | Promise<boolean>): AsyncQueryable<TSource>;
join<TInner, TKey, TResult>(inner: AsyncQuerySource<TInner>, outerKeySelector: (to: TSource) => TKey | Promise<TKey>, innerKeySelector: (ti: TInner) => TKey | Promise<TKey>, resultSelector: (to: TSource, ti: TInner) => TResult | Promise<TResult>): AsyncQueryable<TResult>;
groupJoin<TInner, TKey, TResult>(inner: AsyncQuerySource<TInner>, outerKeySelector: (to: TSource) => TKey | Promise<TKey>, innerKeySelector: (ti: TInner) => TKey | Promise<TKey>, resultSelector: (to: TSource, ti: AsyncQuerySource<TInner>) => TResult | Promise<TResult>): AsyncQueryable<TResult>;
concat(iter: AsyncQuerySource<TSource>): AsyncQueryable<TSource>;
/**
* Concatenates two sequences.
* @param second Sequence to concatenate to `this` sequence.
*/
concat(second: AsyncQuerySource<TSource>): AsyncQueryable<TSource>;
/**
* Enumerates the elements of a sequence in reverse order.
*/
reverse(): AsyncQueryable<TSource>;
/**
* Sorts the elements of a sequence in ascending order.
*
* Unlike JavaScript's `Array#sort`, which coerces all objects to string and sorts them
* lexically, this method requires `keySelector` to perform any conversions explicitly. Among
* other things, this means that numbers are sorted numerically rather than lexically.
* @param keySelector Maps an element of the sequence to the key used for sorting.
*/
orderBy(keySelector: (t: TSource) => OrderKey | Promise<OrderKey>): AsyncQueryable<TSource>;
/**
* Sorts the elements of a sequence in descending order.
*
* Unlike JavaScript's `Array#sort`, which coerces all objects to string and sorts them
* lexically, this method requires `keySelector` to perform any conversions explicitly. Among
* other things, this means that numbers are sorted numerically rather than lexically.
* @param keySelector Maps an element of the sequence to the key used for sorting.
*/
orderByDescending(keySelector: (t: TSource) => OrderKey | Promise<OrderKey>): AsyncQueryable<TSource>;
groupBy<TKey, TResult = TSource>(keySelector: (t: TSource) => TKey | Promise<TKey>, elementSelector?: (t: TSource) => TResult | Promise<TResult>): AsyncQueryable<Grouping<TKey, TResult>>;
/**
* Collect elements in a sequence into groups whose keys match.
* @param keySelector Maps an element of the sequence into the key used for grouping.
* @param elementSelector Optionally transforms each element of the sequence from `TSource` to
* `TResult`.
* @example
* await from([1, 2, 1]).groupBy(x => x).map(g => g.toArray()).toArray(); // [[1, 1], [2]]
*/
groupBy<TKey, TResult = TSource>(keySelector: (t: TSource) => TKey | Promise<TKey>, elementSelector?: (t: TSource) => TResult | Promise<TResult>): AsyncQueryable<AsyncQueryableGrouping<TKey, TResult>>;
/**
* Suppresses duplicate elements in a sequence.
*/
distinct(): AsyncQueryable<TSource>;
/**
* Produces the set union of two sequences.
* @param second Sequence to union with `this` sequence.
* @example
* await from([1, 2, 3]).union([1, 1, 1, 1, 1]).toArray(); // == [1, 2, 3]
*/
union(second: AsyncQuerySource<TSource>): AsyncQueryable<TSource>;
/**
* Produces the set intersection of two sequences.
* @param second Sequence to intersect with `this` sequence.
* @example
* await from([1, 2, 3]).intersection([1, 1, 1, 1, 1]).toArray(); // == [1]
*/
intersect(second: AsyncQuerySource<TSource>): AsyncQueryable<TSource>;
/**
* Produces the set difference of two sequences.
* @param second Sequence to diff with `this` sequence.
* @example
* await from([1, 2]).except([1, 1, 1, 2, 3, 1, 1]).toArray(); // == [3]
*/
except(second: AsyncQuerySource<TSource>): AsyncQueryable<TSource>;
/**
* Find first element in sequence, or first element in sequence that satisfies `predicate`. If
* sequence is empty or no elements satisfy this condition, throw an exception.
* @param predicate Optional test for elements in the sequence.
*/
first(predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<TSource>;
/**
* Find first element in sequence, or first element in sequence that satisfies `predicate`, or
* return provided default value.
* @param defaultValue Default value to return if element cannot be found.
* @param predicate Optional test for elements in the sequence.
*/
firstOrDefault(defaultValue: TSource, predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<TSource>;
/**
* Find last element in sequence, or last element in sequence that satisfies `predicate`. If
* sequence is empty or no elements satisfy this condition, throw an exception.
* @param predicate Optional test for elements in the sequence.
*/
last(predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<TSource>;
/**
* Find last element in sequence, or last element in sequence that satisfies `predicate`, or
* return provided default value.
* @param defaultValue Default value to return if element cannot be found.
* @param predicate Optional test for elements in the sequence.
*/
lastOrDefault(defaultValue: TSource, predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<TSource>;
/**
* Return single element in sequence, or single element in sequence that satisfies `predicate`.
* If sequence is empty or no elements satisfy this condition, throw an exception.
* @param predicate Optional test for elements in the sequence.
*/
single(predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<TSource>;
/**
* Find single element in sequence, or single element in sequence that satisfies `predicate`, or
* return provided default value.
* @param defaultValue Default value to return if element cannot be found.
* @param predicate Optional test for elements in the sequence.
*/
singleOrDefault(defaultValue: TSource, predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<TSource>;
/**
* Return element at `index` in sequence. If `index` is out of range, throw an exception.
* @param index Zero-based index of the element to return.
*/
elementAt(index: number): Promise<TSource>;
/**
* Return element at `index` in sequence, or the provided default value if the index does not exist.
* @param defaultValue Default value to return if element cannot be found.
* @param index Zero-based index of the element to return.
*/
elementAtOrDefault(defaultValue: TSource, index: number | Promise<number>): Promise<TSource>;
/**
* Return `this` sequence, or a sequence containing only `defaultValue` if the sequence is
* empty.
* @param defaultValue Default value to return if sequence is empty.
*/
defaultIfEmpty(defaultValue: TSource): AsyncQueryable<TSource>;
/**
* Retruns `true` if any element of a sequence exists or satisfies `predicate`.
* @param predicate Boolean function to check against elements of the sequence.
*/
any(predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<boolean>;
/**
* Returns `true` if all elements of a sequence satisfy `predicate`.
* @param predicate Boolean function to check against elements of the sequence.
*/
all(predicate: (t: TSource) => boolean | Promise<boolean>): Promise<boolean>;
/**
* Returns `true` of sequence contains element equal to `value`.
* @param value Element to check the sequence contains.
*/
contains(value: TSource): Promise<boolean>;
/**
* Counts the number of elements in a sequence, or the number of elements that satisfy
* `predicate`.
* @param predicate Function to check against elements of the sequence.
*/
count(predicate?: (t: TSource) => boolean | Promise<boolean>): Promise<number>;
/**
* Sums all the numbers in a sequence.
*/
sum(): TSource extends number ? Promise<number> : never;
/**
* Applies `selector` to each element in a sequence, and then sums the resulting numbers.
* @param selector Function mapping elements of a sequence to numbers.
*/
sum(selector?: (t: TSource) => number | Promise<number>): Promise<number>;
/**
* Finds the minimum number in a sequence.
*/
min(): TSource extends number ? Promise<number> : never;
/**
* Applies `selector` to each element in a sequence, and then finds the minimum of the resulting
* numbers.
* @param selector Function mapping elements of a sequence to numbers.
*/
min(selector?: (t: TSource) => number | Promise<number>): Promise<number>;
/**
* Finds the maximum number in a sequence.
*/
max(): TSource extends number ? Promise<number> : never;
/**
* Applies `selector` to each element in a sequence, and then finds the maximum of the resulting
* numbers.
* @param selector Function mapping elements of a sequence to numbers.
*/
max(selector?: (t: TSource) => number | Promise<number>): Promise<number>;
/**
* Averages the numbers of a sequence.
*/
average(): TSource extends number ? Promise<number> : never;
/**
* Applies `selector` to each element in a sequence, and then averages the resulting numbers.
* @param selector Function mapping elements of a sequence to numbers.
*/
average(selector?: (t: TSource) => number | Promise<number>): Promise<number>;
/**
* Accumulates a value over a sequence. `func` is applied to each element in the sequence, an
* the result of `func` becomes the `acc` argument in the next application. The first `acc`
* takes the value `seed`.
* @param seed Value of `acc` in the first call to `func`.
* @param func Accumulates a result.
*/
aggregate<TAccumulate>(seed: TAccumulate, func: (acc: TAccumulate, t: TSource) => TAccumulate | Promise<TAccumulate>): Promise<TAccumulate>;
/**
* Transforms a sequence of `TSource` to a `Promise<TSource[]>`.
*/
toArray(): Promise<TSource[]>;
/**
* Transforms a sequence into a `Map`.
* @param keySelector Maps elements in the sequence to keys that will be used in the resulting
* `Map`.
* @param elementSelector Optionally maps elements in the sequence into the values used in teh
* resulting `Map`.
*/
toMap<TKey, TResult = TSource>(keySelector: (t: TSource) => TKey | Promise<TKey>, elementSelector?: (t: TSource) => TResult | Promise<TResult>): Promise<Map<TKey, TResult>>;
/**
* Filter out everything in the sequence that is not of type `TResult`, returning a sequence of
* type `TResult`.
* @param typeGuard Checks whether element is of type `TResult`.
*/
ofType<TResult>(typeGuard: (o: any) => o is TResult): AsyncQueryable<TResult>;
/**
* Evaluate a function `f` on each element of a sequence.
* @param f Function to run on each element of the sequence.
*/
forEach(f: (t: TSource) => void | Promise<void>): void;

@@ -67,3 +297,3 @@ pipe(): AsyncQueryable<TSource>;

}
export interface Grouping<TKey, TSource> extends GroupedAsyncIterableIterator<TKey, TSource>, AsyncQueryable<TSource> {
export interface AsyncQueryableGrouping<TKey, TSource> extends GroupedAsyncIterableIterator<TKey, TSource>, AsyncQueryable<TSource> {
}
{
"name": "@pulumi/query",
"version": "v0.0.1-dev.1557895217+g6fbaeb5",
"version": "v0.0.1-dev.1558545876+g0c03dd1",
"description": "An simple, relational SDK for querying TypeScript and JavaScript data structures",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -58,2 +58,5 @@ "use strict";

describe("range", () => {
//
// TODO: Throw error when range overlaps.
//
it("produces an empty array for overlapping ranges", () => __awaiter(this, void 0, void 0, function* () {

@@ -60,0 +63,0 @@ let xs = yield __1.range(0, 0).toArray();

Sorry, the diff of this file is not supported yet