-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathstreams.ts
51 lines (46 loc) · 1.44 KB
/
streams.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// See https://github.com/microsoft/TouchDevelop-backend/blob/master/docs/streams.md
namespace pxt.streams {
export interface JsonStreamField {
name: string;
sum: number;
min: number;
max: number;
count: number;
}
export interface JsonStreamMeta {
fields: JsonStreamField[];
size: number;
rows: number;
batches: number;
}
export interface JsonStream {
kind: string;
id: string;
time: number;
name?: string;
meta: JsonStreamMeta;
privatekey?: string;
}
export interface JsonStreamPayload {
fields: string[];
values: number[][];
}
export interface JsonStreamPayloadResponse {
meta: JsonStreamMeta;
quotaUsedHere: number;
quotaLeft: number;
}
export interface JsonStreamData {
fields: JsonStreamField[];
values: number[][];
continuation?: string;
continuationUrl?: string;
}
export function createStreamAsync(target: string, name?: string): Promise<JsonStream> {
return Cloud.privatePostAsync("streams", { target: target, name: name || 'data' }).then(j => <JsonStream>j);
}
export function postPayloadAsync(stream: JsonStream, data: JsonStreamPayload): Promise<void> {
Util.assert(!!stream.privatekey);
return Cloud.privatePostAsync(`${stream.id}/data?privatekey=${stream.privatekey}`, data);
}
}