xdriver 2.0.12 → 2.0.13
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/lib/table.d.ts +13 -1
- package/lib/table.js +39 -4
- package/package.json +1 -1
- package/src/table.ts +51 -5
package/lib/table.d.ts
CHANGED
|
@@ -15,8 +15,20 @@ export type Rows = Array<Row>;
|
|
|
15
15
|
export type TableMeta = ITable & {
|
|
16
16
|
rows?: Rows;
|
|
17
17
|
};
|
|
18
|
-
export declare class RowPacket<T extends Row>
|
|
18
|
+
export declare class RowPacket<T extends Row> {
|
|
19
|
+
private readonly rows;
|
|
19
20
|
constructor(rows?: Array<T>);
|
|
21
|
+
[Symbol.iterator](): Generator<T, void, unknown>;
|
|
22
|
+
forEach(callback: (value: T, index: number, array: Array<T>) => void): void;
|
|
23
|
+
filter(callback: (value: T, index: number, array: Array<T>) => boolean): Array<T>;
|
|
24
|
+
reduce<U>(callback: (previousValue: U, currentValue: T, currentIndex: number, array: Array<T>) => U, initialValue: U): U;
|
|
25
|
+
map<U>(callback: (value: T, index: number, array: Array<T>) => U): Array<U>;
|
|
26
|
+
some(callback: (value: T, index: number, array: Array<T>) => boolean): boolean;
|
|
27
|
+
find(callback: (value: T, index: number, array: Array<T>) => boolean): T | undefined;
|
|
28
|
+
push(...items: Array<T>): void;
|
|
29
|
+
slice(start?: number, end?: number): Array<T>;
|
|
30
|
+
join(separator?: string): string;
|
|
31
|
+
get length(): number;
|
|
20
32
|
distinct(column?: string | ((row: T) => any)): Array<T>;
|
|
21
33
|
mapping<K, T>(keyFn: (row: T, index: number, array: Array<T>) => K): Map<K, T>;
|
|
22
34
|
mapping<K, V>(keyFn: (row: T, index: number, array: Array<T>) => K, valFn: (row: T, index: number, array: Array<T>) => V): Map<K, V>;
|
package/lib/table.js
CHANGED
|
@@ -33,13 +33,48 @@ const _request = (request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
-
export class RowPacket
|
|
36
|
+
export class RowPacket {
|
|
37
37
|
constructor(rows = []) {
|
|
38
|
-
|
|
38
|
+
this.rows = rows;
|
|
39
|
+
}
|
|
40
|
+
*[Symbol.iterator]() {
|
|
41
|
+
for (const item of this.rows) {
|
|
42
|
+
yield item;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
forEach(callback) {
|
|
46
|
+
this.rows.forEach(callback);
|
|
47
|
+
}
|
|
48
|
+
filter(callback) {
|
|
49
|
+
return this.rows.filter(callback);
|
|
50
|
+
}
|
|
51
|
+
reduce(callback, initialValue) {
|
|
52
|
+
return this.rows.reduce(callback, initialValue);
|
|
53
|
+
}
|
|
54
|
+
map(callback) {
|
|
55
|
+
return this.rows.map(callback);
|
|
56
|
+
}
|
|
57
|
+
some(callback) {
|
|
58
|
+
return this.rows.some(callback);
|
|
59
|
+
}
|
|
60
|
+
find(callback) {
|
|
61
|
+
return this.rows.find(callback);
|
|
62
|
+
}
|
|
63
|
+
push(...items) {
|
|
64
|
+
this.rows.push(...items);
|
|
65
|
+
}
|
|
66
|
+
slice(start, end) {
|
|
67
|
+
return this.rows.slice(start, end);
|
|
68
|
+
}
|
|
69
|
+
join(separator) {
|
|
70
|
+
return this.rows.join(separator);
|
|
71
|
+
}
|
|
72
|
+
get length() {
|
|
73
|
+
return this.rows.length;
|
|
39
74
|
}
|
|
40
75
|
distinct(column) {
|
|
41
76
|
if (!column) {
|
|
42
|
-
return this;
|
|
77
|
+
return this.rows;
|
|
43
78
|
}
|
|
44
79
|
let set = new Set();
|
|
45
80
|
return this.filter(row => {
|
|
@@ -77,7 +112,7 @@ export class RowPacket extends Array {
|
|
|
77
112
|
this.forEach((item, index, array) => {
|
|
78
113
|
var _a;
|
|
79
114
|
let unionKey = typeof key === 'function' ? key.call(this, item, index, array) : item[key];
|
|
80
|
-
let value = valFn ? valFn(item, index, this) : item;
|
|
115
|
+
let value = valFn ? valFn(item, index, this.rows) : item;
|
|
81
116
|
if (!group.has(unionKey)) {
|
|
82
117
|
group.set(unionKey, [value]);
|
|
83
118
|
}
|
package/package.json
CHANGED
package/src/table.ts
CHANGED
|
@@ -49,10 +49,56 @@ export type Rows = Array<Row>;
|
|
|
49
49
|
|
|
50
50
|
export type TableMeta = ITable & { rows?: Rows };
|
|
51
51
|
|
|
52
|
-
export class RowPacket<T extends Row>
|
|
52
|
+
export class RowPacket<T extends Row> {
|
|
53
|
+
|
|
54
|
+
private readonly rows: Array<T>;
|
|
53
55
|
|
|
54
56
|
constructor(rows: Array<T> = []) {
|
|
55
|
-
|
|
57
|
+
this.rows = rows;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
*[Symbol.iterator]() {
|
|
61
|
+
// 使用 generator 函数最简单!
|
|
62
|
+
for (const item of this.rows) {
|
|
63
|
+
yield item;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
forEach(callback: (value: T, index: number, array: Array<T>) => void) {
|
|
68
|
+
this.rows.forEach(callback);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
filter(callback: (value: T, index: number, array: Array<T>) => boolean): Array<T> {
|
|
72
|
+
return this.rows.filter(callback);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
reduce<U>(callback: (previousValue: U, currentValue: T, currentIndex: number, array: Array<T>) => U,
|
|
76
|
+
initialValue: U): U {
|
|
77
|
+
return this.rows.reduce(callback, initialValue);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
map<U>(callback: (value: T, index: number, array: Array<T>) => U): Array<U> {
|
|
81
|
+
return this.rows.map(callback);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
some(callback: (value: T, index: number, array: Array<T>) => boolean): boolean {
|
|
85
|
+
return this.rows.some(callback);
|
|
86
|
+
}
|
|
87
|
+
find(callback: (value: T, index: number, array: Array<T>) => boolean): T | undefined {
|
|
88
|
+
return this.rows.find(callback);
|
|
89
|
+
}
|
|
90
|
+
push(...items: Array<T>) {
|
|
91
|
+
this.rows.push(...items);
|
|
92
|
+
}
|
|
93
|
+
slice(start?: number, end?: number): Array<T> {
|
|
94
|
+
return this.rows.slice(start, end);
|
|
95
|
+
}
|
|
96
|
+
join(separator?: string): string {
|
|
97
|
+
return this.rows.join(separator);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get length(): number {
|
|
101
|
+
return this.rows.length;
|
|
56
102
|
}
|
|
57
103
|
|
|
58
104
|
/**
|
|
@@ -61,7 +107,7 @@ export class RowPacket<T extends Row> extends Array<T> {
|
|
|
61
107
|
*/
|
|
62
108
|
distinct(column?: string | ((row: T) => any)): Array<T> {
|
|
63
109
|
if (!column) {
|
|
64
|
-
return this;
|
|
110
|
+
return this.rows;
|
|
65
111
|
}
|
|
66
112
|
let set = new Set<any>();
|
|
67
113
|
return this.filter(row => {
|
|
@@ -111,7 +157,7 @@ export class RowPacket<T extends Row> extends Array<T> {
|
|
|
111
157
|
let group = new Map<K, Array<V | T>>();
|
|
112
158
|
this.forEach((item, index, array) => {
|
|
113
159
|
let unionKey: K = typeof key === 'function' ? key.call(this, item, index, array) : item[key];
|
|
114
|
-
let value = valFn ? valFn(item, index, this) : item;
|
|
160
|
+
let value = valFn ? valFn(item, index, this.rows) : item;
|
|
115
161
|
if (!group.has(unionKey)) {
|
|
116
162
|
group.set(unionKey, [value]);
|
|
117
163
|
} else {
|
|
@@ -473,7 +519,7 @@ export default class Table implements ITable{
|
|
|
473
519
|
* @param direction
|
|
474
520
|
* @param indexName
|
|
475
521
|
*/
|
|
476
|
-
async scan<R extends Row>(key?:
|
|
522
|
+
async scan<R extends Row>(key?: IDBValidKey | IDBKeyRange, direction: IDBCursorDirection = 'next', indexName?: string): Promise<RowPacket<R>> {
|
|
477
523
|
const store = _getObjectStore(this)
|
|
478
524
|
let request: IDBRequest<IDBCursorWithValue | null>
|
|
479
525
|
if (!indexName) {
|