@dra2020/baseclient 1.0.123 → 1.0.125

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.
@@ -1,4 +1,4 @@
1
- export declare type DataTable = {
1
+ export type DataTable = {
2
2
  [key: string]: {
3
3
  interpolate: boolean;
4
4
  colors: any[];
@@ -1,4 +1,4 @@
1
- export declare type ContextValues = {
1
+ export type ContextValues = {
2
2
  [key: string]: any;
3
3
  };
4
4
  export interface IContext {
package/dist/fsm/fsm.d.ts CHANGED
@@ -14,9 +14,7 @@ export declare const FSM_CUSTOM6: number;
14
14
  export declare const FSM_CUSTOM7: number;
15
15
  export declare const FSM_CUSTOM8: number;
16
16
  export declare const FSM_CUSTOM9: number;
17
- export declare type FsmIndex = {
18
- [key: number]: Fsm;
19
- };
17
+ export type FsmIndex = Set<Fsm>;
20
18
  export declare class FsmManager {
21
19
  theId: number;
22
20
  theEpoch: number;
@@ -54,7 +52,8 @@ export declare class Fsm {
54
52
  waitOn(fsm: Fsm | Fsm[]): Fsm;
55
53
  setState(state: number): void;
56
54
  end(state?: number): void;
57
- preTick(): void;
55
+ waitOnCompleted(f: Fsm): void;
56
+ _completed(f: Fsm): void;
58
57
  tick(): void;
59
58
  }
60
59
  export declare class FsmOnDone extends Fsm {
@@ -69,7 +68,7 @@ export declare class FsmSleep extends Fsm {
69
68
  constructor(env: FsmEnvironment, delay: number);
70
69
  tick(): void;
71
70
  }
72
- export declare type SerializerIndex = {
71
+ export type SerializerIndex = {
73
72
  [key: string]: Fsm;
74
73
  };
75
74
  export declare class FsmSerializer extends Fsm {
@@ -78,7 +77,7 @@ export declare class FsmSerializer extends Fsm {
78
77
  serialize(id: string, fsm?: Fsm): Fsm;
79
78
  tick(): void;
80
79
  }
81
- declare type FsmArrayMap = {
80
+ type FsmArrayMap = {
82
81
  [key: string]: Fsm[];
83
82
  };
84
83
  export declare class FsmTracker {
package/dist/geo/geo.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import * as geojson from 'geojson';
2
2
  import * as Poly from '../poly/all';
3
- export declare type GeoProperties = geojson.GeoJsonProperties;
4
- export declare type GeoFeature = geojson.Feature;
5
- export declare type GeoFeatureArray = GeoFeature[];
6
- export declare type GeoFeatureCollection = geojson.FeatureCollection;
7
- export declare type GeoCentroidMap = {
3
+ export type GeoProperties = geojson.GeoJsonProperties;
4
+ export type GeoFeature = geojson.Feature;
5
+ export type GeoFeatureArray = GeoFeature[];
6
+ export type GeoFeatureCollection = geojson.FeatureCollection;
7
+ export type GeoCentroidMap = {
8
8
  [geoid: string]: {
9
9
  x: number;
10
10
  y: number;
11
11
  };
12
12
  };
13
- export declare type HideMap = {
13
+ export type HideMap = {
14
14
  [id: string]: boolean;
15
15
  };
16
16
  export declare function dumpMetrics(): void;
@@ -33,14 +33,14 @@ export declare function geoTopoToCollectionNonNull(topo: Poly.Topo): GeoFeatureC
33
33
  export interface GeoFeatureMap {
34
34
  [id: string]: GeoFeature;
35
35
  }
36
- export declare type FeatureFunc = (f: GeoFeature) => void;
36
+ export type FeatureFunc = (f: GeoFeature) => void;
37
37
  interface GeoEntry {
38
38
  tag: string;
39
39
  col?: GeoFeatureCollection;
40
40
  map?: GeoFeatureMap;
41
41
  topo?: Poly.Topo;
42
42
  }
43
- declare type GeoEntryMap = {
43
+ type GeoEntryMap = {
44
44
  [tag: string]: GeoEntry;
45
45
  };
46
46
  export declare function geoEqual(m1: GeoMultiCollection, m2: GeoMultiCollection): boolean;
@@ -1,7 +1,7 @@
1
- export declare type BlockMapping = {
1
+ export type BlockMapping = {
2
2
  [blockid: string]: string;
3
3
  };
4
- export declare type ReverseBlockMapping = {
4
+ export type ReverseBlockMapping = {
5
5
  [geoid: string]: string[];
6
6
  };
7
7
  interface Entry {
@@ -5,8 +5,8 @@ export declare const OpRetain: number;
5
5
  export declare const OpCursor: number;
6
6
  export declare const OpSet: number;
7
7
  export declare const OpTmpRetain: number;
8
- export declare type OTSingleArrayEdit = [number, number, any];
9
- export declare type OTEdits = OTSingleArrayEdit[];
8
+ export type OTSingleArrayEdit = [number, number, any];
9
+ export type OTEdits = OTSingleArrayEdit[];
10
10
  declare enum OTalignEdgesType {
11
11
  AlignForCompose = 0,
12
12
  AlignForTransform = 1
@@ -1,7 +1,7 @@
1
1
  import * as OT from "./ottypes";
2
2
  export declare const OpCounterAdd = 1;
3
3
  export declare const OpCounterDel = 2;
4
- export declare type CounterEdit = [number, string, any];
4
+ export type CounterEdit = [number, string, any];
5
5
  export declare class OTCounterResource extends OT.OTResourceBase {
6
6
  constructor(rid: string);
7
7
  static factory(rid: string): OTCounterResource;
@@ -1,7 +1,7 @@
1
1
  import * as OT from './ottypes';
2
2
  export declare const OpMapSet = 1;
3
3
  export declare const OpMapDel = 2;
4
- export declare type MapEdit = [number, string, any];
4
+ export type MapEdit = [number, string, any];
5
5
  export declare class OTMapResource extends OT.OTResourceBase {
6
6
  constructor(rid: string);
7
7
  static factory(rid: string): OTMapResource;
@@ -23,7 +23,7 @@ export declare const FilterOfficial: number;
23
23
  export declare const FilterCOI: number;
24
24
  export declare const FilterMyGroups: number;
25
25
  export declare const FilterCount: number;
26
- export declare type Filter = number;
26
+ export type Filter = number;
27
27
  export declare const PermNone: number;
28
28
  export declare const PermRead: number;
29
29
  export declare const PermWrite: number;
@@ -32,10 +32,10 @@ export declare const PermAdmin: number;
32
32
  export declare const PermVersion: number;
33
33
  export declare const PermEdit: number;
34
34
  export declare const PermAll: number;
35
- export declare type Permission = number;
35
+ export type Permission = number;
36
36
  export declare const ServerStateRunning: number;
37
37
  export declare const ServerStateMaintenance: number;
38
- export declare type ServerState = number;
38
+ export type ServerState = number;
39
39
  export interface AccessSessionMap {
40
40
  [key: string]: string;
41
41
  }
@@ -52,7 +52,7 @@ export interface Revision {
52
52
  label?: string;
53
53
  editcache?: string;
54
54
  }
55
- export declare type RevisionList = Revision[];
55
+ export type RevisionList = Revision[];
56
56
  export interface SessionUser {
57
57
  id: string;
58
58
  name: string;
@@ -101,7 +101,7 @@ export interface SessionProps {
101
101
  xid?: string;
102
102
  colors?: string;
103
103
  }
104
- export declare type LabelUpdate = {
104
+ export type LabelUpdate = {
105
105
  [name: string]: boolean | null;
106
106
  };
107
107
  export interface SessionUpdateProps {
@@ -1,8 +1,8 @@
1
- export declare type Matrix = number[][];
2
- export declare type Vector = number[];
3
- export declare type Range = number[];
4
- export declare type Index = number[][];
5
- export declare type applyCB = (v: Vector) => number;
1
+ export type Matrix = number[][];
2
+ export type Vector = number[];
3
+ export type Range = number[];
4
+ export type Index = number[][];
5
+ export type applyCB = (v: Vector) => number;
6
6
  export declare const enum Dim {
7
7
  Rows = 0,
8
8
  Columns = 1
@@ -4,8 +4,8 @@ export interface PolyPack {
4
4
  buffer: any;
5
5
  }
6
6
  export declare function polyPackSize(coords: any): number;
7
- declare type EachRingCB = (buffer: Float64Array, iPoly: number, iRing: number, iOffset: number, nPoints: number) => void;
8
- declare type EachPointCB = (buffer: Float64Array, iPoly: number, iRing: number, iOffset: number) => void;
7
+ type EachRingCB = (buffer: Float64Array, iPoly: number, iRing: number, iOffset: number, nPoints: number) => void;
8
+ type EachPointCB = (buffer: Float64Array, iPoly: number, iRing: number, iOffset: number) => void;
9
9
  export declare function polyPackEachRing(pack: PolyPack, cb: EachRingCB): void;
10
10
  export declare function polyPackEachPoint(pack: PolyPack, cb: EachPointCB): void;
11
11
  export declare function polyPackCountPoints(pack: PolyPack): number;
@@ -22,7 +22,7 @@ export declare function polyUnpack(prepack: any): any;
22
22
  export declare function featurePackSize(f: any): number;
23
23
  export declare function featurePack(f: any, prepack?: PolyPack): any;
24
24
  export declare function featureUnpack(f: any): any;
25
- export declare type SavePack = WeakMap<any, any>;
25
+ export type SavePack = WeakMap<any, any>;
26
26
  export declare function featureUnpackTemporarily(f: any, save?: SavePack): SavePack;
27
27
  export declare function featureRepack(f: any, save: SavePack): any;
28
28
  export declare function featurePackString(f: any): string;
@@ -1,2 +1,2 @@
1
- export declare type Point = [number, number];
1
+ export type Point = [number, number];
2
2
  export declare function simplify(points: Point[], tolerance?: number, highestQuality?: boolean): Point[];
@@ -2,11 +2,11 @@ import * as FSM from '../fsm/all';
2
2
  import * as G from '../geo/all';
3
3
  import * as P from './poly';
4
4
  import * as Q from './quad';
5
- export declare type Topo = any;
5
+ export type Topo = any;
6
6
  export declare function topoFromCollection(col: any): Topo;
7
7
  export declare function topoContiguity(topo: Topo): any;
8
8
  export declare function topoToFeature(topo: Topo, geoid: string): any;
9
- export declare type TopoSpliceEntry = {
9
+ export type TopoSpliceEntry = {
10
10
  topology: Topo;
11
11
  filterout?: any;
12
12
  };
@@ -15,10 +15,10 @@ interface Fragment {
15
15
  s: string;
16
16
  u8?: Uint8Array;
17
17
  }
18
- declare type FragmentTable = {
18
+ type FragmentTable = {
19
19
  [frag: string]: Fragment;
20
20
  };
21
- declare type FragmentPair = {
21
+ type FragmentPair = {
22
22
  f1: Fragment;
23
23
  f2: Fragment;
24
24
  offset?: number;
@@ -51,7 +51,7 @@ declare class ValueTableBuilder {
51
51
  toOffset(s: string): number;
52
52
  toBinary(): void;
53
53
  }
54
- export declare type StringMap = {
54
+ export type StringMap = {
55
55
  [key: string]: string;
56
56
  };
57
57
  interface UnpackedNode {
@@ -8,7 +8,7 @@ export interface Stop {
8
8
  stop: number;
9
9
  rgb?: RGB;
10
10
  }
11
- export declare type GradientStops = Stop[];
11
+ export type GradientStops = Stop[];
12
12
  export declare function execGradient(stops: GradientStops, value: number): string;
13
13
  export declare function parseGradient(sStops: string): GradientStops;
14
14
  export declare function asCSSGradient(stops: GradientStops): string;
@@ -1,4 +1,4 @@
1
- export declare type DateString = string;
1
+ export type DateString = string;
2
2
  export declare function Now(): DateString;
3
3
  export declare class Elapsed {
4
4
  tStart: any;
package/lib/fsm/fsm.ts CHANGED
@@ -51,7 +51,7 @@ function FsmStateToString(state: number): string
51
51
  }
52
52
  }
53
53
 
54
- export type FsmIndex = { [key: number]: Fsm };
54
+ export type FsmIndex = Set<Fsm>;
55
55
 
56
56
  export class FsmManager
57
57
  {
@@ -66,14 +66,14 @@ export class FsmManager
66
66
  this.theId = 0;
67
67
  this.theEpoch = 0;
68
68
  this.bTickSet = false;
69
- this.theTickList = {};
69
+ this.theTickList = new Set<Fsm>();
70
70
  this.theBusyLoopCount = 0;
71
71
  this.doTick = this.doTick.bind(this);
72
72
  }
73
73
 
74
74
  forceTick(fsm: Fsm): void
75
75
  {
76
- this.theTickList[fsm.id] = fsm;
76
+ this.theTickList.add(fsm);
77
77
  if (! this.bTickSet)
78
78
  {
79
79
  this.bTickSet = true;
@@ -82,32 +82,26 @@ export class FsmManager
82
82
  }
83
83
 
84
84
  doTick(): void
85
- {
86
- this.bTickSet = false;
87
- let nLoops: number = 0;
88
-
89
- while (nLoops < 1 && !Util.isEmpty(this.theTickList))
90
- {
91
- nLoops++;
92
- let thisTickList = this.theTickList;
93
- this.theTickList = {};
94
-
95
- for (let id in thisTickList) if (thisTickList.hasOwnProperty(id))
96
- {
97
- let f = thisTickList[id];
98
- f.preTick();
99
- f.tick();
100
- }
101
- }
85
+ {
86
+ this.bTickSet = false;
87
+ let nLoops = 0;
102
88
 
103
- if (Util.isEmpty(this.theTickList))
104
- this.theBusyLoopCount = 0;
105
- else
106
- this.theBusyLoopCount++;
89
+ while (nLoops < 1 && this.theTickList.size > 0)
90
+ {
91
+ nLoops++;
92
+ let thisTickList = this.theTickList;
93
+ this.theTickList = new Set<Fsm>();
107
94
 
108
- this.theEpoch++;
95
+ thisTickList.forEach((f: Fsm) => f.tick());
109
96
  }
110
97
 
98
+ if (this.theTickList.size == 0)
99
+ this.theBusyLoopCount = 0;
100
+ else
101
+ this.theBusyLoopCount++;
102
+
103
+ this.theEpoch++;
104
+ }
111
105
  }
112
106
 
113
107
  export interface FsmEnvironment
@@ -132,143 +126,105 @@ export class Fsm
132
126
  this.state = FSM_STARTING;
133
127
  this.dependentError = false;
134
128
  this.epochDone = -1;
135
- this._waitOn = null;
136
- this._waitedOn = null;
129
+ this._waitOn = new Set<Fsm>();
130
+ this._waitedOn = new Set<Fsm>();
137
131
  this.manager.forceTick(this);
138
132
  }
139
133
 
140
134
  get env(): FsmEnvironment { return this._env; }
141
135
  get manager(): FsmManager { return this.env.fsmManager; }
142
136
 
143
- get done(): boolean
144
- {
145
- return FsmDone(this.state);
146
- }
137
+ get done(): boolean { return FsmDone(this.state) }
147
138
 
148
- get ready(): boolean
149
- {
150
- return !this.done && this._waitOn == null;
151
- }
139
+ get ready(): boolean { return !this.done && this.nWaitOn == 0 }
152
140
 
153
- get iserror(): boolean
154
- {
155
- return (this.state === FSM_ERROR || this.state === FSM_CANCEL);
156
- }
141
+ get iserror(): boolean { return this.state === FSM_ERROR || this.state === FSM_CANCEL }
157
142
 
158
- get isDependentError(): boolean
159
- {
160
- return this.dependentError;
161
- }
143
+ get isDependentError(): boolean { return this.dependentError }
162
144
 
163
- cancel(): void
164
- {
165
- // Override if you need to do more than marking complete
166
- this.setState(FSM_CANCEL);
167
- }
145
+ // Override if you need to do more than marking complete
146
+ cancel(): void { this.setState(FSM_CANCEL) }
168
147
 
169
- setDependentError(): void
170
- {
171
- this.dependentError = true;
172
- }
148
+ setDependentError(): void { this.dependentError = true }
173
149
 
174
- clearDependentError(): void
175
- {
176
- this.dependentError = false;
177
- }
150
+ clearDependentError(): void { this.dependentError = false }
178
151
 
179
- get ticked(): boolean
180
- {
181
- return this.done && this.manager.theEpoch > this.epochDone;
182
- }
152
+ get ticked(): boolean { return this.done && this.manager.theEpoch > this.epochDone }
183
153
 
184
- get nWaitOn(): number
185
- {
186
- return Util.countKeys(this._waitOn);
187
- }
154
+ get nWaitOn(): number { return this._waitOn.size }
188
155
 
189
- get nWaitedOn(): number
190
- {
191
- return Util.countKeys(this._waitedOn);
192
- }
156
+ get nWaitedOn(): number { return this._waitedOn.size }
193
157
 
194
158
  waitOn(fsm: Fsm | Fsm[]): Fsm
159
+ {
160
+ if (fsm == null)
161
+ return this;
162
+ else if (Array.isArray(fsm))
195
163
  {
196
- if (fsm == null)
197
- return this;
198
- else if (Array.isArray(fsm))
164
+ fsm.forEach((f: Fsm) => this.waitOn(f));
165
+ }
166
+ else
167
+ {
168
+ if (fsm.done)
199
169
  {
200
- for (let i: number = 0; i < fsm.length; i++)
201
- this.waitOn(fsm[i]);
170
+ // If dependency is already done, don't add to waitOn list but ensure that
171
+ // this Fsm gets ticked during next epoch. This is because the dependent tick
172
+ // only happens when the dependency state is changed.
173
+ this.manager.forceTick(this);
174
+ if (fsm.iserror)
175
+ this.setDependentError();
202
176
  }
203
177
  else
204
178
  {
205
- if (fsm.done)
206
- {
207
- // If dependency is already done, don't add to waitOn list but ensure that
208
- // this Fsm gets ticked during next epoch. This is because the dependent tick
209
- // only happens when the dependency state is changed.
210
- this.manager.forceTick(this);
211
- if (fsm.iserror)
212
- this.setDependentError();
213
- }
214
- else
215
- {
216
- if (this._waitOn == null) this._waitOn = {};
217
- this._waitOn[fsm.id] = fsm;
218
- if (fsm._waitedOn == null) fsm._waitedOn = {};
219
- fsm._waitedOn[this.id] = this;
220
- }
179
+ this._waitOn.add(fsm);
180
+ fsm._waitedOn.add(this);
221
181
  }
222
- return this;
223
182
  }
183
+ return this;
184
+ }
224
185
 
225
186
  setState(state: number): void
187
+ {
188
+ this.state = state;
189
+ if (this.done)
226
190
  {
227
- this.state = state;
228
- if (this.done)
191
+ // Loop because completion might add more to wait list
192
+ while (this.nWaitedOn)
229
193
  {
230
- while (this._waitedOn)
231
- {
232
- let on = this._waitedOn;
233
- this._waitedOn = null;
234
- for (let id in on) if (on.hasOwnProperty(id))
235
- {
236
- let f = on[id];
237
- if (this.iserror) f.setDependentError();
238
- this.manager.forceTick(f);
239
- }
240
- }
241
-
242
- this.epochDone = this.manager.theEpoch;
194
+ let waitedOn = this._waitedOn;
195
+ this._waitedOn = new Set<Fsm>();
196
+ waitedOn.forEach((f: Fsm) => { f._completed(this); this.manager.forceTick(f) });
243
197
  }
244
- this.manager.forceTick(this);
198
+
199
+ this.epochDone = this.manager.theEpoch;
245
200
  }
201
+ this.manager.forceTick(this);
202
+ }
246
203
 
247
204
  // Can override if need to do more here
248
205
  end(state: number = FSM_DONE): void
249
- {
250
- this.setState(state);
251
- }
206
+ {
207
+ this.setState(state);
208
+ }
252
209
 
253
- // Cleans up _waitOn
254
- preTick(): void
210
+ // Override if subclass needs to respond to individual items completing rather than waiting
211
+ // in tick. Useful to avoid O(n^2) if waiting on lots of items and not wanting to do a linear
212
+ // scan for completed FSMs. Or to not require separate bookkeeping for list of dependents.
213
+ waitOnCompleted(f: Fsm): void { }
214
+
215
+ _completed(f: Fsm): void
216
+ {
217
+ if (f.iserror) this.setDependentError();
218
+ if (f.done && this._waitOn.has(f))
255
219
  {
256
- if (this._waitOn == null) return;
257
- let bMore: boolean = false;
258
- for (let id in this._waitOn) if (this._waitOn.hasOwnProperty(id))
259
- {
260
- let fsm = this._waitOn[id];
261
- if (fsm.done)
262
- delete this._waitOn[id];
263
- else
264
- bMore = true;
265
- }
266
- if (!bMore) this._waitOn = null;
220
+ this._waitOn.delete(f);
221
+ this.waitOnCompleted(f);
267
222
  }
223
+ }
268
224
 
269
225
  tick(): void
270
- {
271
- }
226
+ {
227
+ }
272
228
  }
273
229
 
274
230
  // Launches callback provided when the associated Fsm (or Fsm array) completes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.123",
3
+ "version": "1.0.125",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",
@@ -30,14 +30,14 @@
30
30
  "devDependencies": {
31
31
  "@types/diff-match-patch": "^1.0.32",
32
32
  "@types/geojson": "^7946.0.8",
33
- "@types/node": "12.7.2",
34
- "@types/object-hash": "^2.2.1",
35
- "source-map-loader": "^3.0.0",
36
- "ts-loader": "^9.2.6",
33
+ "@types/node": "20.11.30",
34
+ "@types/object-hash": "^3.0.6",
35
+ "source-map-loader": "^5.0.0",
36
+ "ts-loader": "^9.5.1",
37
37
  "tsify": "^5.0.4",
38
- "typescript": "^4.5.2",
39
- "webpack": "^5.65.0",
40
- "webpack-cli": "^4.9.1"
38
+ "typescript": "^5.4.3",
39
+ "webpack": "^5.91.0",
40
+ "webpack-cli": "^5.1.4"
41
41
  },
42
42
  "dependencies": {
43
43
  "@dra2020/topojson-client": "^3.2.12",
@@ -45,7 +45,7 @@
45
45
  "@dra2020/topojson-simplify": "^3.0.102",
46
46
  "diff-match-patch": "^1.0.5",
47
47
  "geojson": "^0.5.0",
48
- "object-hash": "^2.2.0",
48
+ "object-hash": "^3.0.0",
49
49
  "polygon-clipping": "^0.15.3",
50
50
  "tinyqueue": "^2.0.3"
51
51
  }