@antelopejs/interface-database 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antelope.test.js +1 -1
- package/dist/atomic.d.ts +3 -37
- package/dist/atomic.js +39 -121
- package/dist/atomic.js.map +1 -1
- package/dist/common.d.ts +1 -58
- package/dist/common.js +15 -41
- package/dist/common.js.map +1 -1
- package/dist/datum.d.ts +1 -55
- package/dist/datum.js +2 -66
- package/dist/datum.js.map +1 -1
- package/dist/query.d.ts +11 -12
- package/dist/query.js +24 -22
- package/dist/query.js.map +1 -1
- package/dist/schema.d.ts +3 -120
- package/dist/schema.js +7 -88
- package/dist/schema.js.map +1 -1
- package/dist/selection.d.ts +1 -104
- package/dist/selection.js +5 -123
- package/dist/selection.js.map +1 -1
- package/dist/staged-query/atomic.d.ts +34 -0
- package/dist/staged-query/atomic.js +108 -0
- package/dist/staged-query/atomic.js.map +1 -0
- package/dist/staged-query/common.d.ts +58 -0
- package/dist/staged-query/common.js +45 -0
- package/dist/staged-query/common.js.map +1 -0
- package/dist/staged-query/datum.d.ts +55 -0
- package/dist/staged-query/datum.js +70 -0
- package/dist/staged-query/datum.js.map +1 -0
- package/dist/staged-query/index.d.ts +8 -0
- package/dist/staged-query/index.js +36 -0
- package/dist/staged-query/index.js.map +1 -0
- package/dist/staged-query/query.d.ts +3 -0
- package/dist/staged-query/query.js +9 -0
- package/dist/staged-query/query.js.map +1 -0
- package/dist/staged-query/schema.d.ts +122 -0
- package/dist/staged-query/schema.js +95 -0
- package/dist/staged-query/schema.js.map +1 -0
- package/dist/staged-query/selection.d.ts +104 -0
- package/dist/staged-query/selection.js +126 -0
- package/dist/staged-query/selection.js.map +1 -0
- package/dist/staged-query/stream.d.ts +185 -0
- package/dist/staged-query/stream.js +221 -0
- package/dist/staged-query/stream.js.map +1 -0
- package/dist/staged-query/valueproxy.d.ts +415 -0
- package/dist/staged-query/valueproxy.js +562 -0
- package/dist/staged-query/valueproxy.js.map +1 -0
- package/dist/stream.d.ts +1 -185
- package/dist/stream.js +2 -217
- package/dist/stream.js.map +1 -1
- package/dist/tests/atomic_mutation_operations.test.d.ts +1 -0
- package/dist/tests/atomic_mutation_operations.test.js +278 -0
- package/dist/tests/atomic_mutation_operations.test.js.map +1 -0
- package/dist/valueproxy.d.ts +1 -415
- package/dist/valueproxy.js +15 -559
- package/dist/valueproxy.js.map +1 -1
- package/package.json +9 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Table = exports.Selection = exports.SingleSelection = void 0;
|
|
4
|
+
const datum_1 = require("./datum");
|
|
5
|
+
const query_1 = require("./query");
|
|
6
|
+
const stream_1 = require("./stream");
|
|
7
|
+
const valueproxy_1 = require("./valueproxy");
|
|
8
|
+
const atomic_1 = require("./atomic");
|
|
9
|
+
/**
|
|
10
|
+
* Selection containing a single element
|
|
11
|
+
*/
|
|
12
|
+
class SingleSelection extends datum_1.Datum {
|
|
13
|
+
update(document) {
|
|
14
|
+
if (typeof document === "function") {
|
|
15
|
+
return this.stage((query_1.Query), "update", undefined, this.callfunc(document, (valueproxy_1.ValueProxy)));
|
|
16
|
+
}
|
|
17
|
+
return this.stage((query_1.Query), "update", undefined, document);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Replace documents of this selection
|
|
21
|
+
*
|
|
22
|
+
* @param document Partial document to replace with
|
|
23
|
+
* @returns Number of modified documents
|
|
24
|
+
*/
|
|
25
|
+
replace(document) {
|
|
26
|
+
return this.stage((query_1.Query), "replace", undefined, document);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Delete selected documents
|
|
30
|
+
*
|
|
31
|
+
* @returns Number of deleted documents
|
|
32
|
+
*/
|
|
33
|
+
delete() {
|
|
34
|
+
return this.stage((query_1.Query), "delete");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Turns this selection into a change feed
|
|
38
|
+
*
|
|
39
|
+
* @returns Change feed
|
|
40
|
+
*/
|
|
41
|
+
changes() {
|
|
42
|
+
return this.stage((query_1.Query), "changes");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.SingleSelection = SingleSelection;
|
|
46
|
+
/**
|
|
47
|
+
* Selection containing any number of elements
|
|
48
|
+
*/
|
|
49
|
+
class Selection extends stream_1.Stream {
|
|
50
|
+
update(document) {
|
|
51
|
+
if (typeof document === "function") {
|
|
52
|
+
return this.stage((query_1.Query), "update", undefined, this.callfunc(document, (valueproxy_1.ValueProxy)));
|
|
53
|
+
}
|
|
54
|
+
return this.stage((query_1.Query), "update", undefined, document);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Replace documents of this selection
|
|
58
|
+
*
|
|
59
|
+
* @param document Partial document to replace with
|
|
60
|
+
* @returns Number of modified documents
|
|
61
|
+
*/
|
|
62
|
+
replace(document) {
|
|
63
|
+
return this.stage((query_1.Query), "replace", undefined, document);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Delete selected documents
|
|
67
|
+
*
|
|
68
|
+
* @returns Number of deleted documents
|
|
69
|
+
*/
|
|
70
|
+
delete() {
|
|
71
|
+
return this.stage((query_1.Query), "delete");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.Selection = Selection;
|
|
75
|
+
/**
|
|
76
|
+
* Database table
|
|
77
|
+
*/
|
|
78
|
+
class Table extends Selection {
|
|
79
|
+
/** Atomically checks one record's revision and patches or deletes it without upsert. */
|
|
80
|
+
atomicMutation(key, request) {
|
|
81
|
+
(0, atomic_1.ValidateAtomicMutationTable)(this.stages);
|
|
82
|
+
(0, atomic_1.ValidateAtomicMutation)(key, request);
|
|
83
|
+
return this.stage(atomic_1.AtomicMutationQuery, "atomicMutation", undefined, key, request);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Inserts one or more documents into this table
|
|
87
|
+
*
|
|
88
|
+
* @param obj Document(s) to insert
|
|
89
|
+
* @returns Inserted IDs
|
|
90
|
+
*/
|
|
91
|
+
insert(obj, options) {
|
|
92
|
+
return this.stage((query_1.Query), "insert", options, obj);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets a document using its primary key
|
|
96
|
+
*
|
|
97
|
+
* @param key Primary key value
|
|
98
|
+
* @returns Single document selection
|
|
99
|
+
*/
|
|
100
|
+
get(key) {
|
|
101
|
+
return this.stage((SingleSelection), "get", undefined, key);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Gets multiple documents using a secondary index
|
|
105
|
+
*
|
|
106
|
+
* @param keys Key value(s)
|
|
107
|
+
* @param index Secondary index, will use the primary key if undefined
|
|
108
|
+
* @returns Multiple document selection
|
|
109
|
+
*/
|
|
110
|
+
getAll(keys, index) {
|
|
111
|
+
return this.stage((Selection), "getAll", { index }, keys);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Gets multiple documents using a secondary index and bounding values
|
|
115
|
+
*
|
|
116
|
+
* @param index Secondary index
|
|
117
|
+
* @param low Lowest value of the range
|
|
118
|
+
* @param high Highest value of the range (excluded)
|
|
119
|
+
* @returns Multiple document selection
|
|
120
|
+
*/
|
|
121
|
+
between(index, low, high) {
|
|
122
|
+
return this.stage((Selection), "between", { index }, low, high);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.Table = Table;
|
|
126
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/staged-query/selection.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,mCAAgC;AAChC,qCAAkC;AAClC,6CAAkE;AAOlE,qCAMkB;AAIlB;;GAEG;AACH,MAAa,eAAmB,SAAQ,aAAQ;IAWvC,MAAM,CAAC,QAA4D;QACxE,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAA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@@
|
|
|
1
|
+
import { Datum } from "./datum";
|
|
2
|
+
import { Query } from "./query";
|
|
3
|
+
import type { Selection } from "./selection";
|
|
4
|
+
import type { Changes, ExtractType, Value } from "./common";
|
|
5
|
+
import { ValueProxy, type ValueProxyOrValue } from "./valueproxy";
|
|
6
|
+
export declare class Stream<T> extends Query<T[]> {
|
|
7
|
+
/**
|
|
8
|
+
* Changes the type of the value in this stream.
|
|
9
|
+
* This does not actually perform any conversion, it only changes the typescript type.
|
|
10
|
+
*
|
|
11
|
+
* @returns Same stream with a different type
|
|
12
|
+
*/
|
|
13
|
+
cast<U>(): Stream<U>;
|
|
14
|
+
/**
|
|
15
|
+
* Indexes the stream value.
|
|
16
|
+
*
|
|
17
|
+
* TODO: Better name?
|
|
18
|
+
*
|
|
19
|
+
* @param key Field name
|
|
20
|
+
* @param def Default value
|
|
21
|
+
* @returns New stream
|
|
22
|
+
*/
|
|
23
|
+
key<K extends keyof T, U = undefined>(key: K, def?: U): Stream<U extends undefined ? T[K] : U | Exclude<T[K], null | undefined>>;
|
|
24
|
+
/**
|
|
25
|
+
* Defaults the stream value to a given value if it is null.
|
|
26
|
+
*
|
|
27
|
+
* @param value Default value
|
|
28
|
+
* @returns Stream with non-null value
|
|
29
|
+
*/
|
|
30
|
+
default<U>(val: Value<U>): Stream<U | Exclude<T, null | undefined>>;
|
|
31
|
+
/**
|
|
32
|
+
* Maps the array values using a mapping function.
|
|
33
|
+
*
|
|
34
|
+
* @param mapper Mapping function
|
|
35
|
+
* @returns New stream
|
|
36
|
+
*/
|
|
37
|
+
map<U>(mapper: (val: ValueProxy<T>) => U): Stream<ExtractType<U>>;
|
|
38
|
+
/**
|
|
39
|
+
* Filters the array using a predicate function.
|
|
40
|
+
*
|
|
41
|
+
* @param predicate Predicate function.
|
|
42
|
+
* @returns Filtered stream
|
|
43
|
+
*/
|
|
44
|
+
filter(predicate: (val: ValueProxy<T>) => ValueProxyOrValue<boolean>): this;
|
|
45
|
+
/**
|
|
46
|
+
* Selects specific fields in the documents, discarding the rest.
|
|
47
|
+
*
|
|
48
|
+
* @param fields Selected fields
|
|
49
|
+
* @returns New stream
|
|
50
|
+
*/
|
|
51
|
+
pluck(...fields: string[]): Stream<Partial<T>>;
|
|
52
|
+
/**
|
|
53
|
+
* Excludes specific fields in the documents
|
|
54
|
+
*
|
|
55
|
+
* @param fields Excluded fields
|
|
56
|
+
* @returns New stream
|
|
57
|
+
*/
|
|
58
|
+
without(...fields: string[]): Stream<Partial<T>>;
|
|
59
|
+
/**
|
|
60
|
+
* Concatenates the results of another stream into this stream without deduplication
|
|
61
|
+
*
|
|
62
|
+
* @param other Stream to concatenate
|
|
63
|
+
* @returns New stream containing elements from both streams
|
|
64
|
+
*/
|
|
65
|
+
union<U>(other: Stream<U>): Stream<T | U>;
|
|
66
|
+
/**
|
|
67
|
+
* Perform a left join operation between this stream (left) and another stream (right)
|
|
68
|
+
*
|
|
69
|
+
* @param right Right stream
|
|
70
|
+
* @param predicate Predicate to match elements from the left stream to the right stream
|
|
71
|
+
* @param mapper Mapping function for each pair of documents
|
|
72
|
+
* @returns New stream with results of the mapping function
|
|
73
|
+
*/
|
|
74
|
+
join<U, V>(right: Stream<U>, predicate: (left: ValueProxy<T>, right: ValueProxy<U>) => ValueProxyOrValue<boolean>, mapper: (left: ValueProxy<T>, right: ValueProxy<U | null>) => V): Stream<ExtractType<V>>;
|
|
75
|
+
/**
|
|
76
|
+
* Perform an inner join operation between this stream (left) and another stream (right)
|
|
77
|
+
*
|
|
78
|
+
* @param right Right stream
|
|
79
|
+
* @param predicate Predicate to match elements from the left stream to the right stream
|
|
80
|
+
* @param mapper Mapping function for each pair of documents
|
|
81
|
+
* @returns New stream with results of the mapping function
|
|
82
|
+
*/
|
|
83
|
+
joinInner<U, V>(right: Stream<U>, predicate: (left: ValueProxy<T>, right: ValueProxy<U>) => ValueProxyOrValue<boolean>, mapper: (left: ValueProxy<T>, right: ValueProxy<U>) => V): Stream<ExtractType<V>>;
|
|
84
|
+
/**
|
|
85
|
+
* Transform a foreign key or array of foreign keys into a document from another stream
|
|
86
|
+
*
|
|
87
|
+
* @param right Stream containing the other documents
|
|
88
|
+
* @param localKey Key in the local document to search with and replace
|
|
89
|
+
* @param otherKey Key in the other document to match against
|
|
90
|
+
* @returns New stream
|
|
91
|
+
*/
|
|
92
|
+
lookup<U, TK extends keyof T>(right: Selection<U>, localKey: TK, otherKey: keyof U): Stream<Omit<T, TK> & Record<TK, T[TK] extends any[] ? U[] : U>>;
|
|
93
|
+
/**
|
|
94
|
+
* Group the documents using the given index and maps the result using a mapping function
|
|
95
|
+
*
|
|
96
|
+
* The parameters of this function are:
|
|
97
|
+
* - The stream with all the documents inside the group
|
|
98
|
+
* - The index value for this group
|
|
99
|
+
*
|
|
100
|
+
* The result of this function is used as the element in the new stream
|
|
101
|
+
*
|
|
102
|
+
* @param index Index to group on
|
|
103
|
+
* @param mapper Mapping function
|
|
104
|
+
* @returns New stream of grouped data
|
|
105
|
+
*/
|
|
106
|
+
group<U, K extends keyof T | string>(index: K, mapper: (stream: Stream<T>, group: ValueProxy<K extends keyof T ? T[K] : unknown>) => U): Stream<ExtractType<U>>;
|
|
107
|
+
/**
|
|
108
|
+
* Sort the stream using the given index and direction
|
|
109
|
+
*
|
|
110
|
+
* @param index Index to sort
|
|
111
|
+
* @param direction Sort direction
|
|
112
|
+
* @returns New (sorted) stream
|
|
113
|
+
*/
|
|
114
|
+
orderBy(index: string, direction?: "asc" | "desc"): this;
|
|
115
|
+
/**
|
|
116
|
+
* Obtain a slice (subsection) of the stream
|
|
117
|
+
*
|
|
118
|
+
* @param offset Offset into the stream
|
|
119
|
+
* @param count Number of documents to pick
|
|
120
|
+
* @returns New stream
|
|
121
|
+
*/
|
|
122
|
+
slice(offset: Value<number>, count?: Value<number>): this;
|
|
123
|
+
/**
|
|
124
|
+
* Obtain the Nth document of the stream
|
|
125
|
+
*
|
|
126
|
+
* @param n N
|
|
127
|
+
* @returns Single document
|
|
128
|
+
*/
|
|
129
|
+
nth(n: Value<number>): Datum<T | null>;
|
|
130
|
+
/**
|
|
131
|
+
* Gets the count of documents or the count of distinct values of a given field
|
|
132
|
+
*
|
|
133
|
+
* @param field Field to count distinct entries
|
|
134
|
+
* @returns Count
|
|
135
|
+
*/
|
|
136
|
+
count(field?: keyof T): Datum<number>;
|
|
137
|
+
/**
|
|
138
|
+
* Sum of the values on the given field
|
|
139
|
+
*
|
|
140
|
+
* @param field Field to use
|
|
141
|
+
* @returns Sum
|
|
142
|
+
*/
|
|
143
|
+
sum(field?: keyof T): Datum<number>;
|
|
144
|
+
/**
|
|
145
|
+
* Average of the values on the given field
|
|
146
|
+
*
|
|
147
|
+
* @param field Field to use
|
|
148
|
+
* @returns Average
|
|
149
|
+
*/
|
|
150
|
+
avg(field?: keyof T): Datum<number>;
|
|
151
|
+
/**
|
|
152
|
+
* Minimum of the values on the given field
|
|
153
|
+
*
|
|
154
|
+
* @param field Field to use
|
|
155
|
+
* @returns Minimum value
|
|
156
|
+
*/
|
|
157
|
+
min(field?: keyof T): Datum<number>;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum of the values on the given field
|
|
160
|
+
*
|
|
161
|
+
* @param field Field to use
|
|
162
|
+
* @returns Maximum value
|
|
163
|
+
*/
|
|
164
|
+
max(field?: keyof T): Datum<number>;
|
|
165
|
+
/**
|
|
166
|
+
* Gets an array of distinct documents in the stream
|
|
167
|
+
*
|
|
168
|
+
* @returns Array of documents
|
|
169
|
+
*/
|
|
170
|
+
distinct(): Datum<T[]>;
|
|
171
|
+
distinct(field: undefined): Datum<T[]>;
|
|
172
|
+
/**
|
|
173
|
+
* Gets a stream of the distinct values of a field
|
|
174
|
+
*
|
|
175
|
+
* @param index Field to use
|
|
176
|
+
* @returns New stream
|
|
177
|
+
*/
|
|
178
|
+
distinct<TK extends keyof T>(field: TK): Stream<T[TK]>;
|
|
179
|
+
/**
|
|
180
|
+
* Turns this stream into a change feed
|
|
181
|
+
*
|
|
182
|
+
* @returns Change feed
|
|
183
|
+
*/
|
|
184
|
+
changes(): Query<Changes<T>[]>;
|
|
185
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Stream = void 0;
|
|
4
|
+
const datum_1 = require("./datum");
|
|
5
|
+
const query_1 = require("./query");
|
|
6
|
+
const valueproxy_1 = require("./valueproxy");
|
|
7
|
+
class Stream extends query_1.Query {
|
|
8
|
+
/**
|
|
9
|
+
* Changes the type of the value in this stream.
|
|
10
|
+
* This does not actually perform any conversion, it only changes the typescript type.
|
|
11
|
+
*
|
|
12
|
+
* @returns Same stream with a different type
|
|
13
|
+
*/
|
|
14
|
+
cast() {
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Indexes the stream value.
|
|
19
|
+
*
|
|
20
|
+
* TODO: Better name?
|
|
21
|
+
*
|
|
22
|
+
* @param key Field name
|
|
23
|
+
* @param def Default value
|
|
24
|
+
* @returns New stream
|
|
25
|
+
*/
|
|
26
|
+
key(key, def) {
|
|
27
|
+
return this.stage((Stream), "key", undefined, key, def);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Defaults the stream value to a given value if it is null.
|
|
31
|
+
*
|
|
32
|
+
* @param value Default value
|
|
33
|
+
* @returns Stream with non-null value
|
|
34
|
+
*/
|
|
35
|
+
default(val) {
|
|
36
|
+
return this.stage((Stream), "default", undefined, val);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Maps the array values using a mapping function.
|
|
40
|
+
*
|
|
41
|
+
* @param mapper Mapping function
|
|
42
|
+
* @returns New stream
|
|
43
|
+
*/
|
|
44
|
+
map(mapper) {
|
|
45
|
+
return this.stage((Stream), "map", undefined, this.callfunc(mapper, (valueproxy_1.ValueProxy)));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Filters the array using a predicate function.
|
|
49
|
+
*
|
|
50
|
+
* @param predicate Predicate function.
|
|
51
|
+
* @returns Filtered stream
|
|
52
|
+
*/
|
|
53
|
+
filter(predicate) {
|
|
54
|
+
return this.stage(undefined, "filter", undefined, this.callfunc(predicate, (valueproxy_1.ValueProxy)));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Selects specific fields in the documents, discarding the rest.
|
|
58
|
+
*
|
|
59
|
+
* @param fields Selected fields
|
|
60
|
+
* @returns New stream
|
|
61
|
+
*/
|
|
62
|
+
pluck(...fields) {
|
|
63
|
+
return this.stage((Stream), "pluck", undefined, fields);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Excludes specific fields in the documents
|
|
67
|
+
*
|
|
68
|
+
* @param fields Excluded fields
|
|
69
|
+
* @returns New stream
|
|
70
|
+
*/
|
|
71
|
+
without(...fields) {
|
|
72
|
+
return this.stage((Stream), "without", undefined, fields);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Concatenates the results of another stream into this stream without deduplication
|
|
76
|
+
*
|
|
77
|
+
* @param other Stream to concatenate
|
|
78
|
+
* @returns New stream containing elements from both streams
|
|
79
|
+
*/
|
|
80
|
+
union(other) {
|
|
81
|
+
return this.stage((Stream), "union", undefined, other);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Perform a left join operation between this stream (left) and another stream (right)
|
|
85
|
+
*
|
|
86
|
+
* @param right Right stream
|
|
87
|
+
* @param predicate Predicate to match elements from the left stream to the right stream
|
|
88
|
+
* @param mapper Mapping function for each pair of documents
|
|
89
|
+
* @returns New stream with results of the mapping function
|
|
90
|
+
*/
|
|
91
|
+
join(right, predicate, mapper) {
|
|
92
|
+
return this.stage((Stream), "join", { innerOnly: false }, right, this.callfunc(predicate, (valueproxy_1.ValueProxy), (valueproxy_1.ValueProxy)), this.callfunc(mapper, (valueproxy_1.ValueProxy), (valueproxy_1.ValueProxy)));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Perform an inner join operation between this stream (left) and another stream (right)
|
|
96
|
+
*
|
|
97
|
+
* @param right Right stream
|
|
98
|
+
* @param predicate Predicate to match elements from the left stream to the right stream
|
|
99
|
+
* @param mapper Mapping function for each pair of documents
|
|
100
|
+
* @returns New stream with results of the mapping function
|
|
101
|
+
*/
|
|
102
|
+
joinInner(right, predicate, mapper) {
|
|
103
|
+
return this.stage((Stream), "join", { innerOnly: true }, right, this.callfunc(predicate, (valueproxy_1.ValueProxy), (valueproxy_1.ValueProxy)), this.callfunc(mapper, (valueproxy_1.ValueProxy), (valueproxy_1.ValueProxy)));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Transform a foreign key or array of foreign keys into a document from another stream
|
|
107
|
+
*
|
|
108
|
+
* @param right Stream containing the other documents
|
|
109
|
+
* @param localKey Key in the local document to search with and replace
|
|
110
|
+
* @param otherKey Key in the other document to match against
|
|
111
|
+
* @returns New stream
|
|
112
|
+
*/
|
|
113
|
+
lookup(right, localKey, otherKey) {
|
|
114
|
+
return this.stage((Stream), "lookup", { localKey, otherKey }, right);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Group the documents using the given index and maps the result using a mapping function
|
|
118
|
+
*
|
|
119
|
+
* The parameters of this function are:
|
|
120
|
+
* - The stream with all the documents inside the group
|
|
121
|
+
* - The index value for this group
|
|
122
|
+
*
|
|
123
|
+
* The result of this function is used as the element in the new stream
|
|
124
|
+
*
|
|
125
|
+
* @param index Index to group on
|
|
126
|
+
* @param mapper Mapping function
|
|
127
|
+
* @returns New stream of grouped data
|
|
128
|
+
*/
|
|
129
|
+
group(index, mapper) {
|
|
130
|
+
return this.stage((Stream), "group", { index }, this.callfunc(mapper, (Stream), (valueproxy_1.ValueProxy)));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Sort the stream using the given index and direction
|
|
134
|
+
*
|
|
135
|
+
* @param index Index to sort
|
|
136
|
+
* @param direction Sort direction
|
|
137
|
+
* @returns New (sorted) stream
|
|
138
|
+
*/
|
|
139
|
+
orderBy(index, direction) {
|
|
140
|
+
return this.stage(undefined, "orderBy", { index, direction });
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Obtain a slice (subsection) of the stream
|
|
144
|
+
*
|
|
145
|
+
* @param offset Offset into the stream
|
|
146
|
+
* @param count Number of documents to pick
|
|
147
|
+
* @returns New stream
|
|
148
|
+
*/
|
|
149
|
+
slice(offset, count) {
|
|
150
|
+
return this.stage(undefined, "slice", undefined, offset, count);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Obtain the Nth document of the stream
|
|
154
|
+
*
|
|
155
|
+
* @param n N
|
|
156
|
+
* @returns Single document
|
|
157
|
+
*/
|
|
158
|
+
nth(n) {
|
|
159
|
+
return this.stage((datum_1.Datum), "nth", undefined, n);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Gets the count of documents or the count of distinct values of a given field
|
|
163
|
+
*
|
|
164
|
+
* @param field Field to count distinct entries
|
|
165
|
+
* @returns Count
|
|
166
|
+
*/
|
|
167
|
+
count(field) {
|
|
168
|
+
return this.stage((datum_1.Datum), "count", { field });
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Sum of the values on the given field
|
|
172
|
+
*
|
|
173
|
+
* @param field Field to use
|
|
174
|
+
* @returns Sum
|
|
175
|
+
*/
|
|
176
|
+
sum(field) {
|
|
177
|
+
return this.stage((datum_1.Datum), "sum", { field });
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Average of the values on the given field
|
|
181
|
+
*
|
|
182
|
+
* @param field Field to use
|
|
183
|
+
* @returns Average
|
|
184
|
+
*/
|
|
185
|
+
avg(field) {
|
|
186
|
+
return this.stage((datum_1.Datum), "avg", { field });
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Minimum of the values on the given field
|
|
190
|
+
*
|
|
191
|
+
* @param field Field to use
|
|
192
|
+
* @returns Minimum value
|
|
193
|
+
*/
|
|
194
|
+
min(field) {
|
|
195
|
+
return this.stage((datum_1.Datum), "min", { field });
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Maximum of the values on the given field
|
|
199
|
+
*
|
|
200
|
+
* @param field Field to use
|
|
201
|
+
* @returns Maximum value
|
|
202
|
+
*/
|
|
203
|
+
max(field) {
|
|
204
|
+
return this.stage((datum_1.Datum), "max", { field });
|
|
205
|
+
}
|
|
206
|
+
distinct(field) {
|
|
207
|
+
return this.stage(field ? Stream : datum_1.Datum, "distinct", {
|
|
208
|
+
field,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Turns this stream into a change feed
|
|
213
|
+
*
|
|
214
|
+
* @returns Change feed
|
|
215
|
+
*/
|
|
216
|
+
changes() {
|
|
217
|
+
return this.stage((query_1.Query), "changes");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.Stream = Stream;
|
|
221
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/staged-query/stream.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,mCAAgC;AAGhC,6CAAkE;AAElE,MAAa,MAAU,SAAQ,aAAU;IACvC;;;;;OAKG;IACI,IAAI;QACT,OAAO,IAA4B,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACI,GAAG,CAAmC,GAAM,EAAE,GAAO;QAC1D,OAAO,IAAI,CAAC,KAAK,CACf,CAAA,MAAwE,CAAA,EACxE,KAAK,EACL,SAAS,EACT,GAAG,EACH,GAAG,CACJ,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,OAAO,CAAI,GAAa;QAC7B,OAAO,IAAI,CAAC,KAAK,CACf,CAAA,MAAwC,CAAA,EACxC,SAAS,EACT,SAAS,EACT,GAAG,CACJ,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAI,MAAiC;QAC7C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