documentdb-typescript
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "documentdb-typescript", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "TypeScript API for Microsoft Azure DocumentDB", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -22,2 +22,6 @@ # Azure DocumentDB TypeScript API | ||
**v1.0.3:** | ||
* _New:_ Added support for Typescript 2.3's `for await (... of ...)` syntax (without breaking support for ES < 6 and TS < 2.3). See example below. | ||
**v1.0.0:** | ||
@@ -272,2 +276,6 @@ | ||
The `DocumentStream` class exposes a number of methods (e.g. `forEach` and `mapAsync`) | ||
If you do not wish to use the Typescript/ES6 `await` keyword, you can use the `Promise` object returned by `next`, `read`, `forEach`, or `mapAsync` instead. | ||
```typescript | ||
@@ -282,3 +290,3 @@ // Example: iterate over query results | ||
// read all results in a loop (with type hint) | ||
// the hard way: read all results in a loop (with type hint) | ||
type FooResult = { foo: string }; | ||
@@ -292,2 +300,10 @@ var stream = coll.queryDocuments<FooResult>("select c.foo from c"); | ||
// explicitly reset the stream to the beginning if needed: | ||
await stream.resetAsync(); | ||
// the **new** way (Typescript 2.3): for await ... of | ||
for await (const doc of stream) { | ||
console.log(doc.foo); | ||
} | ||
// ... or use the forEach method | ||
@@ -302,4 +318,4 @@ // (can be awaited, too) | ||
console.log(ids); | ||
// get only the newest time stamp | ||
// use `top 1` to get only the newest time stamp | ||
var newest = await coll.queryDocuments( | ||
@@ -314,3 +330,12 @@ "select top 1 c._ts from c order by c._ts desc") | ||
"s ago"); | ||
// ... or without `await`: | ||
coll.queryDocuments( | ||
"select top 1 c._ts from c order by c._ts desc") | ||
.read() | ||
.then(newest => { | ||
if (!newest) console.log("No documents"); | ||
else console.log("Last change" /* + ... */); | ||
}); | ||
} | ||
``` |
@@ -15,9 +15,3 @@ /** Represents asynchronously loaded query result sets as a stream; the type parameter represents the query result type, i.e. a full document resource type for `SELECT * FROM` queries, an object with only projected properties for `SELECT x, y, ... FROM` queries, or even a scalar value for `SELECT VALUE ... FROM` queries */ | ||
/** Get the next result (asynchronously), if any; promise resolves to a `{ value, done }` pair, or is rejected if an error occurred; subsequent calls to this function will return promises for results after the current result (i.e. requests are queued) */ | ||
next(): Promise<{ | ||
value: T; | ||
done: false; | ||
} | { | ||
value: any; | ||
done: true; | ||
}>; | ||
next(): Promise<IteratorResult<T>>; | ||
/** Call a function for each result, until all results have been processed or the callback returns `false` or throws an error; returned promise resolves to true if all results have been processed, or false otherwise, or is rejected if an error occurred */ | ||
@@ -24,0 +18,0 @@ forEach(f: (doc: T) => any): PromiseLike<boolean>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84397
336
1299