@dra2020/baseclient 1.0.84 → 1.0.85
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/baseclient.js +42 -3
- package/dist/baseclient.js.map +1 -1
- package/dist/csv/csv.d.ts +10 -0
- package/docs/fsm.md +10 -6
- package/lib/csv/csv.ts +58 -2
- package/package.json +1 -1
package/dist/csv/csv.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import * as Util from '../util/all';
|
|
2
|
+
export declare class ParseMany {
|
|
3
|
+
buf: Uint8Array;
|
|
4
|
+
n: number;
|
|
5
|
+
one: ParseOne;
|
|
6
|
+
constructor(coder: Util.Coder, buf: Uint8Array);
|
|
7
|
+
get length(): number;
|
|
8
|
+
get fields(): string[];
|
|
9
|
+
next(): boolean;
|
|
10
|
+
}
|
|
2
11
|
export declare class ParseOne {
|
|
3
12
|
coder: Util.Coder;
|
|
4
13
|
fields: string[];
|
|
@@ -12,6 +21,7 @@ export declare class ParseOne {
|
|
|
12
21
|
force: boolean;
|
|
13
22
|
constructor(coder: Util.Coder, line?: string);
|
|
14
23
|
set(line: string): void;
|
|
24
|
+
setBuf(buf: Uint8Array): void;
|
|
15
25
|
get length(): number;
|
|
16
26
|
pushtok(): void;
|
|
17
27
|
parse(): void;
|
package/docs/fsm.md
CHANGED
|
@@ -191,14 +191,18 @@ An `Fsm` can be reused and transition from `ready` to not `ready` or `done` to n
|
|
|
191
191
|
|
|
192
192
|
### Cancellation
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
The standard member function `cancel` will set the state to `FSM_CANCEL` which is considered a done state as
|
|
195
|
+
well as an error state (and will set the dependentError flag on any waiting state machines).
|
|
195
196
|
|
|
196
|
-
By convention, a sub-class should override the `
|
|
197
|
-
|
|
198
|
-
to indicate error.
|
|
197
|
+
By convention, a sub-class should override the `cancel` member function to allow external cancellation
|
|
198
|
+
if it needs to do more internal cleanup than set the state to `FSM_CANCEL`.
|
|
199
199
|
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
Additionally, it can use the `end` member function (by convention) to complete the state machine if that
|
|
201
|
+
makes sense and does not wanted to be treated as an error.
|
|
202
|
+
The class should override the `end` member function if it needs to do cleanup and finalization internally.
|
|
203
|
+
|
|
204
|
+
If a class internally is implemented with callbacks or promises, by convention it should check `if this.done`
|
|
205
|
+
when the callback or promise completes to check whether it may have been externally canceled while awaiting.
|
|
202
206
|
|
|
203
207
|
### FsmOnDone
|
|
204
208
|
|
package/lib/csv/csv.ts
CHANGED
|
@@ -23,6 +23,56 @@ function isWhite(c: number): boolean
|
|
|
23
23
|
return c === Space || c === Newline || c === Tab || c == CR;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Keep calling next() to retrieve next parsed line. Returns false when done. Empty lines are ignored.
|
|
27
|
+
|
|
28
|
+
export class ParseMany
|
|
29
|
+
{
|
|
30
|
+
buf: Uint8Array;
|
|
31
|
+
n: number;
|
|
32
|
+
one: ParseOne;
|
|
33
|
+
|
|
34
|
+
constructor(coder: Util.Coder, buf: Uint8Array)
|
|
35
|
+
{
|
|
36
|
+
this.buf = buf;
|
|
37
|
+
this.n = 0;
|
|
38
|
+
this.one = new ParseOne(coder);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get length(): number { return this.one.length }
|
|
42
|
+
get fields(): string[] { return this.one.fields }
|
|
43
|
+
|
|
44
|
+
next(): boolean
|
|
45
|
+
{
|
|
46
|
+
// Move past any leading CRLF
|
|
47
|
+
while (this.n < this.buf.length)
|
|
48
|
+
{
|
|
49
|
+
let c = this.buf[this.n];
|
|
50
|
+
if (c == CR || c == Newline)
|
|
51
|
+
this.n++;
|
|
52
|
+
else
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let s = this.n;
|
|
57
|
+
while (this.n < this.buf.length)
|
|
58
|
+
{
|
|
59
|
+
let c = this.buf[this.n];
|
|
60
|
+
if (c == CR || c == Newline)
|
|
61
|
+
break;
|
|
62
|
+
else
|
|
63
|
+
this.n++;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (s != this.n)
|
|
67
|
+
{
|
|
68
|
+
this.one.setBuf(this.buf.subarray(s, this.n));
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
26
76
|
export class ParseOne
|
|
27
77
|
{
|
|
28
78
|
coder: Util.Coder;
|
|
@@ -47,9 +97,15 @@ export class ParseOne
|
|
|
47
97
|
|
|
48
98
|
set(line: string): void
|
|
49
99
|
{
|
|
100
|
+
this.setBuf(Util.s2u8(this.coder, line));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
setBuf(buf: Uint8Array): void
|
|
104
|
+
{
|
|
105
|
+
this.buf = buf;
|
|
50
106
|
this.fields = [];
|
|
51
|
-
this.
|
|
52
|
-
|
|
107
|
+
if (!this.tok || this.tok.length < this.buf.length)
|
|
108
|
+
this.tok = new Uint8Array(new ArrayBuffer(this.buf.length));
|
|
53
109
|
this.n = 0;
|
|
54
110
|
this.toklen = 0;
|
|
55
111
|
this.infield = false;
|