@dra2020/baseclient 1.0.84 → 1.0.86

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/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/dist/geo/all.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './geo';
2
2
  export * from './vfeature';
3
3
  export * from './flexname';
4
+ export * from './multiblockmapping';
@@ -0,0 +1,21 @@
1
+ export declare type BlockMapping = {
2
+ [blockid: string]: string;
3
+ };
4
+ export declare type ReverseBlockMapping = {
5
+ [geoid: string]: string[];
6
+ };
7
+ interface Entry {
8
+ tag: string;
9
+ bm: BlockMapping;
10
+ rbm?: ReverseBlockMapping;
11
+ }
12
+ export declare function reverseBlockMapping(bm: BlockMapping): ReverseBlockMapping;
13
+ export declare class MultiBlockMapping {
14
+ entries: Entry[];
15
+ constructor(tag?: string, bm?: BlockMapping);
16
+ add(tag: string, bm: BlockMapping): void;
17
+ remove(tag: string): void;
18
+ map(blockid: string): string;
19
+ rev(geoid: string): string[];
20
+ }
21
+ export {};
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
- There is no explicit cancellation mechanism.
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 `end` member function to allow external cancellation or completion.
197
- By default this function sets the `Fsm` to `FSM_DONE` but can optionally take the `FSM_ERROR` state
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
- Whether calling `end` or setting the state explicitly to `FSM_DONE` or `FSM_ERROR` from external to
201
- the state machine makes semantic sense depends on the specific properties and semantics of the computation.
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.buf = Util.s2u8(this.coder, line);
52
- this.tok = new Uint8Array(new ArrayBuffer(this.buf.length));
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;
package/lib/geo/all.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './geo';
2
2
  export * from './vfeature';
3
3
  export * from './flexname';
4
+ export * from './multiblockmapping';
@@ -0,0 +1,72 @@
1
+ export type BlockMapping = { [blockid: string]: string };
2
+ export type ReverseBlockMapping = { [geoid: string]: string[] };
3
+
4
+ interface Entry
5
+ {
6
+ tag: string,
7
+ bm: BlockMapping,
8
+ rbm?: ReverseBlockMapping,
9
+ }
10
+
11
+ export function reverseBlockMapping(bm: BlockMapping): ReverseBlockMapping
12
+ {
13
+ let rev: ReverseBlockMapping = {};
14
+
15
+ if (bm) Object.keys(bm).forEach(blockid => {
16
+ let geoid = bm[blockid];
17
+ if (! rev[geoid]) rev[geoid] = [];
18
+ rev[geoid].push(blockid);
19
+ });
20
+ Object.values(rev).forEach((a: string[]) => a.sort());
21
+ return rev;
22
+ }
23
+
24
+ export class MultiBlockMapping
25
+ {
26
+ entries: Entry[];
27
+
28
+ constructor(tag?: string, bm?: BlockMapping)
29
+ {
30
+ this.entries = [];
31
+ if (tag && bm)
32
+ this.entries.push({ tag, bm });
33
+ }
34
+
35
+ add(tag: string, bm: BlockMapping): void
36
+ {
37
+ this.entries.forEach(e => { if (e.tag === tag) { e.bm = bm; delete e.rbm; bm = null } });
38
+ if (bm)
39
+ this.entries.push({ tag, bm });
40
+ }
41
+
42
+ remove(tag: string): void
43
+ {
44
+ for (let i = this.entries.length-1; i >= 0; i--)
45
+ if (this.entries[i].tag === tag)
46
+ this.entries.splice(i, 1);
47
+ }
48
+
49
+ map(blockid: string): string
50
+ {
51
+ for (let i = 0; i < this.entries.length; i++)
52
+ {
53
+ let e = this.entries[i];
54
+ if (e.bm[blockid])
55
+ return e.bm[blockid];
56
+ }
57
+ return undefined;
58
+ }
59
+
60
+ rev(geoid: string): string[]
61
+ {
62
+ for (let i = 0; i < this.entries.length; i++)
63
+ {
64
+ let e = this.entries[i];
65
+ if (! e.rbm)
66
+ e.rbm = reverseBlockMapping(e.bm);
67
+ if (e.rbm[geoid])
68
+ return e.rbm[geoid];
69
+ }
70
+ return undefined;
71
+ }
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",