@dra2020/baseclient 1.0.0

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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/dist/all/all.d.ts +18 -0
  4. package/dist/baseclient.js +9567 -0
  5. package/dist/baseclient.js.map +1 -0
  6. package/dist/context/all.d.ts +1 -0
  7. package/dist/context/context.d.ts +13 -0
  8. package/dist/filterexpr/all.d.ts +1 -0
  9. package/dist/filterexpr/filterexpr.d.ts +64 -0
  10. package/dist/fsm/all.d.ts +1 -0
  11. package/dist/fsm/fsm.d.ts +118 -0
  12. package/dist/logabstract/all.d.ts +1 -0
  13. package/dist/logabstract/log.d.ts +26 -0
  14. package/dist/logclient/all.d.ts +1 -0
  15. package/dist/logclient/log.d.ts +6 -0
  16. package/dist/ot-editutil/all.d.ts +2 -0
  17. package/dist/ot-editutil/oteditutil.d.ts +14 -0
  18. package/dist/ot-editutil/otmaputil.d.ts +21 -0
  19. package/dist/ot-js/all.d.ts +9 -0
  20. package/dist/ot-js/otarray.d.ts +111 -0
  21. package/dist/ot-js/otclientengine.d.ts +38 -0
  22. package/dist/ot-js/otcomposite.d.ts +37 -0
  23. package/dist/ot-js/otcounter.d.ts +17 -0
  24. package/dist/ot-js/otengine.d.ts +22 -0
  25. package/dist/ot-js/otmap.d.ts +19 -0
  26. package/dist/ot-js/otserverengine.d.ts +38 -0
  27. package/dist/ot-js/otsession.d.ts +111 -0
  28. package/dist/ot-js/ottypes.d.ts +29 -0
  29. package/dist/poly/all.d.ts +15 -0
  30. package/dist/poly/blend.d.ts +1 -0
  31. package/dist/poly/boundbox.d.ts +16 -0
  32. package/dist/poly/cartesian.d.ts +5 -0
  33. package/dist/poly/graham-scan.d.ts +8 -0
  34. package/dist/poly/hash.d.ts +1 -0
  35. package/dist/poly/matrix.d.ts +24 -0
  36. package/dist/poly/minbound.d.ts +1 -0
  37. package/dist/poly/poly.d.ts +52 -0
  38. package/dist/poly/polybin.d.ts +5 -0
  39. package/dist/poly/polylabel.d.ts +7 -0
  40. package/dist/poly/polypack.d.ts +30 -0
  41. package/dist/poly/polyround.d.ts +1 -0
  42. package/dist/poly/polysimplify.d.ts +1 -0
  43. package/dist/poly/quad.d.ts +48 -0
  44. package/dist/poly/selfintersect.d.ts +1 -0
  45. package/dist/poly/shamos.d.ts +1 -0
  46. package/dist/poly/simplify.d.ts +2 -0
  47. package/dist/poly/topo.d.ts +46 -0
  48. package/dist/poly/union.d.ts +48 -0
  49. package/dist/util/all.d.ts +5 -0
  50. package/dist/util/bintrie.d.ts +93 -0
  51. package/dist/util/countedhash.d.ts +19 -0
  52. package/dist/util/gradient.d.ts +15 -0
  53. package/dist/util/indexedarray.d.ts +15 -0
  54. package/dist/util/util.d.ts +68 -0
  55. package/docs/context.md +2 -0
  56. package/docs/fsm.md +243 -0
  57. package/docs/logabstract.md +2 -0
  58. package/docs/logclient.md +2 -0
  59. package/docs/ot-editutil.md +2 -0
  60. package/docs/ot-js.md +95 -0
  61. package/docs/poly.md +103 -0
  62. package/docs/util.md +2 -0
  63. package/lib/all/all.ts +19 -0
  64. package/lib/context/all.ts +1 -0
  65. package/lib/context/context.ts +82 -0
  66. package/lib/filterexpr/all.ts +1 -0
  67. package/lib/filterexpr/filterexpr.ts +625 -0
  68. package/lib/fsm/all.ts +1 -0
  69. package/lib/fsm/fsm.ts +549 -0
  70. package/lib/logabstract/all.ts +1 -0
  71. package/lib/logabstract/log.ts +55 -0
  72. package/lib/logclient/all.ts +1 -0
  73. package/lib/logclient/log.ts +105 -0
  74. package/lib/ot-editutil/all.ts +2 -0
  75. package/lib/ot-editutil/oteditutil.ts +180 -0
  76. package/lib/ot-editutil/otmaputil.ts +209 -0
  77. package/lib/ot-js/all.ts +9 -0
  78. package/lib/ot-js/otarray.ts +1168 -0
  79. package/lib/ot-js/otclientengine.ts +327 -0
  80. package/lib/ot-js/otcomposite.ts +247 -0
  81. package/lib/ot-js/otcounter.ts +145 -0
  82. package/lib/ot-js/otengine.ts +71 -0
  83. package/lib/ot-js/otmap.ts +144 -0
  84. package/lib/ot-js/otserverengine.ts +329 -0
  85. package/lib/ot-js/otsession.ts +199 -0
  86. package/lib/ot-js/ottypes.ts +98 -0
  87. package/lib/poly/all.ts +15 -0
  88. package/lib/poly/blend.ts +27 -0
  89. package/lib/poly/boundbox.ts +102 -0
  90. package/lib/poly/cartesian.ts +130 -0
  91. package/lib/poly/graham-scan.ts +401 -0
  92. package/lib/poly/hash.ts +15 -0
  93. package/lib/poly/matrix.ts +309 -0
  94. package/lib/poly/minbound.ts +211 -0
  95. package/lib/poly/poly.ts +767 -0
  96. package/lib/poly/polybin.ts +218 -0
  97. package/lib/poly/polylabel.ts +204 -0
  98. package/lib/poly/polypack.ts +458 -0
  99. package/lib/poly/polyround.ts +30 -0
  100. package/lib/poly/polysimplify.ts +24 -0
  101. package/lib/poly/quad.ts +272 -0
  102. package/lib/poly/selfintersect.ts +87 -0
  103. package/lib/poly/shamos.ts +297 -0
  104. package/lib/poly/simplify.ts +119 -0
  105. package/lib/poly/topo.ts +525 -0
  106. package/lib/poly/union.ts +371 -0
  107. package/lib/util/all.ts +5 -0
  108. package/lib/util/bintrie.ts +603 -0
  109. package/lib/util/countedhash.ts +83 -0
  110. package/lib/util/gradient.ts +108 -0
  111. package/lib/util/indexedarray.ts +80 -0
  112. package/lib/util/util.ts +695 -0
  113. package/package.json +52 -0
package/lib/fsm/fsm.ts ADDED
@@ -0,0 +1,549 @@
1
+ // Shared libraries
2
+ import * as Util from '../util/all';
3
+
4
+ // States
5
+ export const FSM_STARTING: number = 0;
6
+ export const FSM_PENDING: number = 1<<0;
7
+ export const FSM_DONE: number = 1<<1;
8
+ export const FSM_ERROR: number = 1<<2;
9
+ export const FSM_RELEASED: number = 1<<3;
10
+ export const FSM_CUSTOM1: number = 1<<4;
11
+ export const FSM_CUSTOM2: number = 1<<5;
12
+ export const FSM_CUSTOM3: number = 1<<6;
13
+ export const FSM_CUSTOM4: number = 1<<7;
14
+ export const FSM_CUSTOM5: number = 1<<8;
15
+ export const FSM_CUSTOM6: number = 1<<9;
16
+ export const FSM_CUSTOM7: number = 1<<10;
17
+ export const FSM_CUSTOM8: number = 1<<11;
18
+ export const FSM_CUSTOM9: number = 1<<12;
19
+
20
+ // polyfill
21
+ let doLater: any = global && global.setImmediate ? setImmediate : (cb: any) => { setTimeout(cb, 0) };
22
+
23
+ function FsmDone(s: number): boolean
24
+ {
25
+ return (s === FSM_DONE || s === FSM_ERROR || s === FSM_RELEASED);
26
+ }
27
+
28
+ function FsmStateToString(state: number): string
29
+ {
30
+ let a: string[] = [];
31
+
32
+ if (state === FSM_STARTING)
33
+ return 'starting';
34
+ else
35
+ {
36
+ if (state === FSM_PENDING) a.push('pending');
37
+ if (state === FSM_DONE) a.push('done');
38
+ if (state === FSM_ERROR) a.push('error');
39
+ if (state === FSM_RELEASED) a.push('released');
40
+ if (state === FSM_CUSTOM1) a.push('custom1');
41
+ if (state === FSM_CUSTOM2) a.push('custom2');
42
+ if (state === FSM_CUSTOM3) a.push('custom3');
43
+ if (state === FSM_CUSTOM4) a.push('custom4');
44
+ if (state === FSM_CUSTOM5) a.push('custom5');
45
+ if (state === FSM_CUSTOM6) a.push('custom6');
46
+ if (state === FSM_CUSTOM7) a.push('custom7');
47
+ if (state === FSM_CUSTOM8) a.push('custom8');
48
+ if (state === FSM_CUSTOM9) a.push('custom9');
49
+ return a.join('|');
50
+ }
51
+ }
52
+
53
+ export type FsmIndex = { [key: number]: Fsm };
54
+
55
+ export class FsmManager
56
+ {
57
+ theId: number;
58
+ theEpoch: number;
59
+ bTickSet: boolean;
60
+ theTickList: FsmIndex;
61
+ theBusyLoopCount: number;
62
+
63
+ constructor()
64
+ {
65
+ this.theId = 0;
66
+ this.theEpoch = 0;
67
+ this.bTickSet = false;
68
+ this.theTickList = {};
69
+ this.theBusyLoopCount = 0;
70
+ this.doTick = this.doTick.bind(this);
71
+ }
72
+
73
+ forceTick(fsm: Fsm): void
74
+ {
75
+ this.theTickList[fsm.id] = fsm;
76
+ if (! this.bTickSet)
77
+ {
78
+ this.bTickSet = true;
79
+ doLater(this.doTick);
80
+ }
81
+ }
82
+
83
+ doTick(): void
84
+ {
85
+ this.bTickSet = false;
86
+ let nLoops: number = 0;
87
+
88
+ while (nLoops < 1 && !Util.isEmpty(this.theTickList))
89
+ {
90
+ nLoops++;
91
+ let thisTickList = this.theTickList;
92
+ this.theTickList = {};
93
+
94
+ for (let id in thisTickList) if (thisTickList.hasOwnProperty(id))
95
+ {
96
+ let f = thisTickList[id];
97
+ f.preTick();
98
+ f.tick();
99
+ }
100
+ }
101
+
102
+ if (Util.isEmpty(this.theTickList))
103
+ this.theBusyLoopCount = 0;
104
+ else
105
+ this.theBusyLoopCount++;
106
+
107
+ this.theEpoch++;
108
+ }
109
+
110
+ }
111
+
112
+ export interface FsmEnvironment
113
+ {
114
+ fsmManager: FsmManager;
115
+ }
116
+
117
+ export class Fsm
118
+ {
119
+ id: number;
120
+ state: number;
121
+ dependentError: boolean;
122
+ epochDone: number;
123
+ _env: FsmEnvironment;
124
+ _waitOn: FsmIndex;
125
+ _waitedOn: FsmIndex;
126
+
127
+ constructor(env: FsmEnvironment)
128
+ {
129
+ this._env = env;
130
+ this.id = this.manager.theId++;
131
+ this.state = FSM_STARTING;
132
+ this.dependentError = false;
133
+ this.epochDone = -1;
134
+ this._waitOn = null;
135
+ this._waitedOn = null;
136
+ this.manager.forceTick(this);
137
+ }
138
+
139
+ get env(): FsmEnvironment { return this._env; }
140
+ get manager(): FsmManager { return this.env.fsmManager; }
141
+
142
+ get done(): boolean
143
+ {
144
+ return FsmDone(this.state);
145
+ }
146
+
147
+ get ready(): boolean
148
+ {
149
+ return !this.done && this._waitOn == null;
150
+ }
151
+
152
+ get iserror(): boolean
153
+ {
154
+ return (this.state === FSM_ERROR);
155
+ }
156
+
157
+ get isDependentError(): boolean
158
+ {
159
+ return this.dependentError;
160
+ }
161
+
162
+ setDependentError(): void
163
+ {
164
+ this.dependentError = true;
165
+ }
166
+
167
+ clearDependentError(): void
168
+ {
169
+ this.dependentError = false;
170
+ }
171
+
172
+ get ticked(): boolean
173
+ {
174
+ return this.done && this.manager.theEpoch > this.epochDone;
175
+ }
176
+
177
+ get nWaitOn(): number
178
+ {
179
+ return Util.countKeys(this._waitOn);
180
+ }
181
+
182
+ get nWaitedOn(): number
183
+ {
184
+ return Util.countKeys(this._waitedOn);
185
+ }
186
+
187
+ waitOn(fsm: Fsm | Fsm[]): Fsm
188
+ {
189
+ if (fsm == null)
190
+ return this;
191
+ else if (Array.isArray(fsm))
192
+ {
193
+ for (let i: number = 0; i < fsm.length; i++)
194
+ this.waitOn(fsm[i]);
195
+ }
196
+ else
197
+ {
198
+ if (fsm.done)
199
+ {
200
+ // If dependency is already done, don't add to waitOn list but ensure that
201
+ // this Fsm gets ticked during next epoch. This is because the dependent tick
202
+ // only happens when the dependency state is changed.
203
+ this.manager.forceTick(this);
204
+ if (fsm.iserror)
205
+ this.setDependentError();
206
+ }
207
+ else
208
+ {
209
+ if (this._waitOn == null) this._waitOn = {};
210
+ this._waitOn[fsm.id] = fsm;
211
+ if (fsm._waitedOn == null) fsm._waitedOn = {};
212
+ fsm._waitedOn[this.id] = this;
213
+ }
214
+ }
215
+ return this;
216
+ }
217
+
218
+ setState(state: number): void
219
+ {
220
+ this.state = state;
221
+ if (this.done)
222
+ {
223
+ while (this._waitedOn)
224
+ {
225
+ let on = this._waitedOn;
226
+ this._waitedOn = null;
227
+ for (let id in on) if (on.hasOwnProperty(id))
228
+ {
229
+ let f = on[id];
230
+ if (this.iserror) f.setDependentError();
231
+ this.manager.forceTick(f);
232
+ }
233
+ }
234
+
235
+ this.epochDone = this.manager.theEpoch;
236
+ }
237
+ this.manager.forceTick(this);
238
+ }
239
+
240
+ // Can override if need to do more here
241
+ end(state: number = FSM_DONE): void
242
+ {
243
+ this.setState(state);
244
+ }
245
+
246
+ // Cleans up _waitOn
247
+ preTick(): void
248
+ {
249
+ if (this._waitOn == null) return;
250
+ let bMore: boolean = false;
251
+ for (let id in this._waitOn) if (this._waitOn.hasOwnProperty(id))
252
+ {
253
+ let fsm = this._waitOn[id];
254
+ if (fsm.done)
255
+ delete this._waitOn[id];
256
+ else
257
+ bMore = true;
258
+ }
259
+ if (!bMore) this._waitOn = null;
260
+ }
261
+
262
+ tick(): void
263
+ {
264
+ }
265
+ }
266
+
267
+ // Launches callback provided when the associated Fsm (or Fsm array) completes.
268
+ export class FsmOnDone extends Fsm
269
+ {
270
+ cb: any;
271
+ fsm: Fsm | Fsm[];
272
+
273
+ constructor(env: FsmEnvironment, fsm: Fsm | Fsm[], cb: any)
274
+ {
275
+ super(env);
276
+ this.waitOn(fsm);
277
+ this.fsm = fsm;
278
+ this.cb = cb;
279
+ }
280
+
281
+ tick(): void
282
+ {
283
+ if (this.ready && this.state == FSM_STARTING)
284
+ {
285
+ this.setState(this.isDependentError ? FSM_ERROR : FSM_DONE);
286
+ this.cb(this.fsm);
287
+ }
288
+ }
289
+ }
290
+
291
+ export class FsmSleep extends Fsm
292
+ {
293
+ delay: number;
294
+
295
+ constructor(env: FsmEnvironment, delay: number)
296
+ {
297
+ super(env);
298
+ this.delay = delay;
299
+ }
300
+
301
+ tick(): void
302
+ {
303
+ if (this.ready && this.state === FSM_STARTING)
304
+ {
305
+ this.setState(FSM_PENDING);
306
+ setTimeout(() => { this.setState(FSM_DONE); }, this.delay);
307
+ }
308
+ }
309
+ }
310
+
311
+ export type SerializerIndex = { [key: string]: Fsm };
312
+
313
+ export class FsmSerializer extends Fsm
314
+ {
315
+ index: SerializerIndex;
316
+
317
+ constructor(env: FsmEnvironment)
318
+ {
319
+ super(env);
320
+ this.index = {};
321
+ }
322
+
323
+ serialize(id: string, fsm?: Fsm): Fsm
324
+ {
325
+ let prev = this.index[id];
326
+ if (prev && !fsm) return prev;
327
+ if (prev !== undefined)
328
+ fsm.waitOn(prev);
329
+ this.index[id] = fsm;
330
+ if (this.done)
331
+ this.setState(FSM_STARTING);
332
+ this.waitOn(fsm);
333
+ return prev;
334
+ }
335
+
336
+ tick(): void
337
+ {
338
+ // If fully quiescent, take advantage to clear the waiting cache.
339
+ if (this.ready && this.state == FSM_STARTING)
340
+ {
341
+ this.index = {};
342
+ this.setState(FSM_DONE);
343
+ }
344
+ }
345
+ }
346
+
347
+ // The FsmTracker class provides a mechanism for serializing a set of finite state
348
+ // machines identified by a consistent unique identifier. A finite state machine is
349
+ // "tracked" until completion. If any other finite state machine calls "maybeWait"
350
+ // while any other are tracked and pending, that FSM will wait for the others to
351
+ // complete.
352
+ //
353
+
354
+ class FsmTrackerWrap extends Fsm
355
+ {
356
+ index: FsmTracker;
357
+ uid: string;
358
+ fsm: Fsm;
359
+
360
+ constructor(env: FsmEnvironment, index: FsmTracker, uid: string, fsm: Fsm)
361
+ {
362
+ super(env);
363
+ this.index = index;
364
+ this.uid = uid;
365
+ this.fsm = fsm;
366
+ index._track(uid, fsm);
367
+ this.waitOn(fsm);
368
+ }
369
+
370
+ tick(): void
371
+ {
372
+ if (this.ready && this.state == FSM_STARTING)
373
+ {
374
+ this.index._untrack(this.uid, this.fsm);
375
+ this.setState(FSM_DONE);
376
+ }
377
+ }
378
+ }
379
+
380
+ type FsmArrayMap = { [key: string]: Fsm[] };
381
+
382
+ export class FsmTracker
383
+ {
384
+ env: FsmEnvironment;
385
+ map: FsmArrayMap;
386
+
387
+ constructor(env: FsmEnvironment)
388
+ {
389
+ this.env = env;
390
+ this.map = {};
391
+ }
392
+
393
+ _track(uid: string, fsm: Fsm): void
394
+ {
395
+ let a = this.map[uid];
396
+ if (a === undefined)
397
+ {
398
+ a = [];
399
+ this.map[uid] = a;
400
+ }
401
+ a.push(fsm);
402
+ }
403
+
404
+ _untrack(uid: string, fsm: Fsm): void
405
+ {
406
+ let a = this.map[uid];
407
+ if (a)
408
+ {
409
+ for (let i: number = 0; i < a.length; i++)
410
+ if (a[i] === fsm)
411
+ {
412
+ if (a.length == 1)
413
+ delete this.map[uid];
414
+ else
415
+ a.splice(i, 1);
416
+ break;
417
+ }
418
+ }
419
+ }
420
+
421
+ track(uid: string, fsm: Fsm): Fsm
422
+ {
423
+ return new FsmTrackerWrap(this.env, this, uid, fsm);
424
+ }
425
+
426
+ maybeWait(uid: string, fsm: Fsm): void
427
+ {
428
+ fsm.waitOn(this.map[uid]);
429
+ }
430
+ }
431
+
432
+
433
+ // FsmLoop: repeat the Fsm passed in (resetting to STARTING state after finished) at some minimum interval.
434
+ // Assumes that the Fsm can be correctly reset and restarted by setting the state.
435
+ //
436
+
437
+ export interface LoopOptions
438
+ {
439
+ minRepeatInterval?: number;
440
+ exitOnError?: boolean;
441
+ }
442
+
443
+ export const DefaultLoopOptions = { minRepeatInterval: 0, exitOnError: true };
444
+
445
+ const FSM_DELAYING = FSM_CUSTOM1;
446
+
447
+ export class FsmLoop extends Fsm
448
+ {
449
+ fsm: Fsm;
450
+ options: LoopOptions;
451
+ elapsed: Util.Elapsed;
452
+
453
+ constructor(env: FsmEnvironment, fsm: Fsm, options?: LoopOptions)
454
+ {
455
+ super(env);
456
+ this.fsm = fsm;
457
+ this.elapsed = new Util.Elapsed();
458
+ this.options = Util.shallowAssignImmutable(DefaultLoopOptions, options);
459
+ this.waitOn(fsm);
460
+ }
461
+
462
+ tick(): void
463
+ {
464
+ if (this.ready && this.isDependentError)
465
+ {
466
+ if (this.options.exitOnError)
467
+ this.setState(FSM_ERROR);
468
+ else
469
+ this.clearDependentError();
470
+ // Fall through
471
+ }
472
+
473
+ if (this.ready)
474
+ {
475
+ switch (this.state)
476
+ {
477
+ case FSM_STARTING:
478
+ let msLeft = this.options.minRepeatInterval - this.elapsed.ms();
479
+ if (msLeft > 0)
480
+ this.waitOn(new FsmSleep(this.env, msLeft));
481
+ this.setState(FSM_DELAYING);
482
+ break;
483
+
484
+ case FSM_DELAYING:
485
+ this.elapsed.start();
486
+ this.fsm.setState(FSM_STARTING);
487
+ this.waitOn(this.fsm);
488
+ this.setState(FSM_STARTING);
489
+ break;
490
+ }
491
+ }
492
+ }
493
+ }
494
+
495
+ export interface ISet
496
+ {
497
+ test: (o: any) => boolean;
498
+ reset: () => void;
499
+ }
500
+
501
+ export class FsmArray extends Fsm
502
+ {
503
+ a: any[];
504
+ iset: ISet;
505
+
506
+ constructor(env: FsmEnvironment, iset?: ISet)
507
+ {
508
+ super(env);
509
+ this.iset = iset;
510
+ this.a = [];
511
+ }
512
+
513
+ push(o: any): void
514
+ {
515
+ if (this.iset == null || !this.iset.test(o))
516
+ {
517
+ if (! this.done) this.setState(FSM_DONE);
518
+ this.a.push(o);
519
+ }
520
+ }
521
+
522
+ concat(a: any[]): void
523
+ {
524
+ if (a)
525
+ {
526
+ for (let i: number = 0; i < a.length; i++)
527
+ this.push(a[i]);
528
+ }
529
+ }
530
+
531
+ splice(i?: number, n?: number): void
532
+ {
533
+ if (i === undefined)
534
+ this.reset();
535
+ else
536
+ {
537
+ this.a.splice(i, n);
538
+ if (this.a.length == 0)
539
+ this.reset();
540
+ }
541
+ }
542
+
543
+ reset(): void
544
+ {
545
+ this.a = [];
546
+ if (this.iset) this.iset.reset();
547
+ this.setState(FSM_STARTING);
548
+ }
549
+ }
@@ -0,0 +1 @@
1
+ export * from './log';
@@ -0,0 +1,55 @@
1
+ import * as Util from '../util/all';
2
+ import * as FSM from '../fsm/all';
3
+
4
+ export interface ILog
5
+ {
6
+ dump: () => FSM.Fsm;
7
+ stamp: (o: any) => void;
8
+ log: (o: any, verbosity?: number) => void;
9
+ event: (o: any, verbosity?: number) => void;
10
+ error: (o: any) => void;
11
+ value: (o: any, verbosity?: number) => void;
12
+ chatter: (s: string) => void;
13
+ chatters: () => string[];
14
+ }
15
+
16
+ export class Timer
17
+ {
18
+ ilog: ILog;
19
+ o: any;
20
+ verbosity: number;
21
+ elapsed: Util.Elapsed;
22
+
23
+ constructor(ilog: ILog, kind: string, o: any, verbosity: number = 0)
24
+ {
25
+ this.ilog = ilog;
26
+ if (typeof o === 'string') o = { event: o };
27
+ this.o = o;
28
+ this.o.kind = kind;
29
+ this.verbosity = verbosity;
30
+ this.elapsed = new Util.Elapsed();
31
+ }
32
+
33
+ log(): void
34
+ {
35
+ this.elapsed.end();
36
+ this.o.ms = this.elapsed.ms();
37
+ this.ilog.log(this.o, this.verbosity);
38
+ }
39
+ }
40
+
41
+ export class AsyncTimer extends Timer
42
+ {
43
+ constructor(ilog: ILog, o: any, verbosity: number = 0)
44
+ {
45
+ super(ilog, 'async', o, verbosity);
46
+ }
47
+ }
48
+
49
+ export class SyncTimer extends Timer
50
+ {
51
+ constructor(ilog: ILog, o: any, verbosity: number = 0)
52
+ {
53
+ super(ilog, 'sync', o, verbosity);
54
+ }
55
+ }
@@ -0,0 +1 @@
1
+ export * from './log';
@@ -0,0 +1,105 @@
1
+ import * as Context from '../context/all';
2
+ import * as LogAbstract from '../logabstract/all';
3
+ import * as Util from '../util/all';
4
+ import * as FSM from '../fsm/all';
5
+
6
+ export interface LogEnvironment
7
+ {
8
+ context: Context.IContext;
9
+ }
10
+
11
+ class LogManager implements LogAbstract.ILog
12
+ {
13
+ env: LogEnvironment;
14
+ count: number;
15
+
16
+ constructor(env: LogEnvironment)
17
+ {
18
+ this.env = env;
19
+ this.count = 0;
20
+ }
21
+
22
+ dump(): FSM.Fsm { return null; }
23
+
24
+ print(o: any): void
25
+ {
26
+ let sa: string[] = [];
27
+
28
+ if (o._count !== undefined)
29
+ sa.push(String(o._count));
30
+ if (o.kind === 'error')
31
+ {
32
+ sa.push('error');
33
+ sa.push(o.event);
34
+ }
35
+ else if (o.kind !== 'value')
36
+ {
37
+ sa.push('info');
38
+ sa.push(o.event);
39
+ }
40
+ else
41
+ {
42
+ sa.push('value');
43
+ sa.push(o.event);
44
+ sa.push(String(o.value));
45
+ }
46
+ if (o.detail !== undefined)
47
+ sa.push(o.detail);
48
+ console.log(sa.join(': '));
49
+ }
50
+
51
+ stamp(o: any): void
52
+ {
53
+ this.log(o);
54
+ }
55
+
56
+ log(o: any, verbosity: number = 0): void
57
+ {
58
+ // Show some restraint
59
+ if (verbosity > this.env.context.xnumber('verbosity'))
60
+ return;
61
+
62
+ // Inject some standard properties
63
+ o._time = Util.Now();
64
+ o._count = this.count++;
65
+ if (o.kind === undefined)
66
+ o.kind = 'misc';
67
+ this.print(o);
68
+ }
69
+
70
+
71
+ event(o: any, verbosity: number = 0): void
72
+ {
73
+ if (typeof o === 'string') o = { event: o };
74
+ o.kind = 'event';
75
+ this.log(o, verbosity);
76
+ }
77
+
78
+ error(o: any): void
79
+ {
80
+ if (typeof o === 'string') o = { event: o };
81
+ o.kind = 'error';
82
+ this.log(o);
83
+ }
84
+
85
+ value(o: any, verbosity: number = 0): void
86
+ {
87
+ o.kind = 'value';
88
+ this.log(o, verbosity);
89
+ }
90
+
91
+ chatter(s: string): void
92
+ {
93
+ console.log(s);
94
+ }
95
+
96
+ chatters(): string[]
97
+ {
98
+ return null;
99
+ }
100
+ }
101
+
102
+ export function create(env: LogEnvironment): LogAbstract.ILog
103
+ {
104
+ return new LogManager(env);
105
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./oteditutil";
2
+ export * from "./otmaputil";