@dra2020/baseclient 1.0.13 → 1.0.14

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 (185) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/dist/all/all.d.ts +36 -0
  4. package/dist/all/allclient.d.ts +18 -0
  5. package/dist/base.js +33010 -0
  6. package/dist/base.js.map +1 -0
  7. package/dist/baseclient.js +8991 -0
  8. package/dist/baseclient.js.map +1 -0
  9. package/dist/context/all.d.ts +1 -0
  10. package/dist/context/context.d.ts +13 -0
  11. package/dist/dbabstract/all.d.ts +1 -0
  12. package/dist/dbabstract/db.d.ts +83 -0
  13. package/dist/dbdynamo/all.d.ts +1 -0
  14. package/dist/dbdynamo/dbdynamo.d.ts +190 -0
  15. package/dist/filterexpr/all.d.ts +1 -0
  16. package/dist/filterexpr/filterexpr.d.ts +64 -0
  17. package/dist/fsm/all.d.ts +1 -0
  18. package/dist/fsm/fsm.d.ts +118 -0
  19. package/dist/fsmfile/all.d.ts +1 -0
  20. package/dist/fsmfile/fsmfile.d.ts +47 -0
  21. package/dist/jsonstream/all.d.ts +1 -0
  22. package/dist/jsonstream/jsonstream.d.ts +130 -0
  23. package/dist/lambda/all.d.ts +1 -0
  24. package/dist/lambda/env.d.ts +10 -0
  25. package/dist/lambda/lambda.d.ts +18 -0
  26. package/dist/logabstract/all.d.ts +1 -0
  27. package/dist/logabstract/log.d.ts +26 -0
  28. package/dist/logclient/all.d.ts +1 -0
  29. package/dist/logclient/log.d.ts +6 -0
  30. package/dist/logserver/all.d.ts +5 -0
  31. package/dist/logserver/log.d.ts +11 -0
  32. package/dist/logserver/logaccum.d.ts +154 -0
  33. package/dist/logserver/logblob.d.ts +24 -0
  34. package/dist/logserver/logconcat.d.ts +55 -0
  35. package/dist/logserver/logkey.d.ts +28 -0
  36. package/dist/memsqs/all.d.ts +4 -0
  37. package/dist/memsqs/client.d.ts +13 -0
  38. package/dist/memsqs/loopback.d.ts +11 -0
  39. package/dist/memsqs/orderedlist.d.ts +19 -0
  40. package/dist/memsqs/queue.d.ts +84 -0
  41. package/dist/memsqs/server.d.ts +37 -0
  42. package/dist/ot-editutil/all.d.ts +2 -0
  43. package/dist/ot-editutil/oteditutil.d.ts +14 -0
  44. package/dist/ot-editutil/otmaputil.d.ts +21 -0
  45. package/dist/ot-js/all.d.ts +9 -0
  46. package/dist/ot-js/otarray.d.ts +111 -0
  47. package/dist/ot-js/otclientengine.d.ts +38 -0
  48. package/dist/ot-js/otcomposite.d.ts +37 -0
  49. package/dist/ot-js/otcounter.d.ts +17 -0
  50. package/dist/ot-js/otengine.d.ts +22 -0
  51. package/dist/ot-js/otmap.d.ts +19 -0
  52. package/dist/ot-js/otserverengine.d.ts +38 -0
  53. package/dist/ot-js/otsession.d.ts +111 -0
  54. package/dist/ot-js/ottypes.d.ts +29 -0
  55. package/dist/poly/all.d.ts +15 -0
  56. package/dist/poly/blend.d.ts +1 -0
  57. package/dist/poly/boundbox.d.ts +16 -0
  58. package/dist/poly/cartesian.d.ts +5 -0
  59. package/dist/poly/graham-scan.d.ts +8 -0
  60. package/dist/poly/hash.d.ts +1 -0
  61. package/dist/poly/matrix.d.ts +24 -0
  62. package/dist/poly/minbound.d.ts +1 -0
  63. package/dist/poly/poly.d.ts +52 -0
  64. package/dist/poly/polybin.d.ts +5 -0
  65. package/dist/poly/polylabel.d.ts +7 -0
  66. package/dist/poly/polypack.d.ts +30 -0
  67. package/dist/poly/polyround.d.ts +1 -0
  68. package/dist/poly/polysimplify.d.ts +1 -0
  69. package/dist/poly/quad.d.ts +48 -0
  70. package/dist/poly/selfintersect.d.ts +1 -0
  71. package/dist/poly/shamos.d.ts +1 -0
  72. package/dist/poly/simplify.d.ts +2 -0
  73. package/dist/poly/topo.d.ts +46 -0
  74. package/dist/poly/union.d.ts +48 -0
  75. package/dist/storage/all.d.ts +4 -0
  76. package/dist/storage/datablob.d.ts +9 -0
  77. package/dist/storage/env.d.ts +10 -0
  78. package/dist/storage/splitsblob.d.ts +13 -0
  79. package/dist/storage/storage.d.ts +166 -0
  80. package/dist/storages3/all.d.ts +1 -0
  81. package/dist/storages3/s3.d.ts +62 -0
  82. package/dist/util/all.d.ts +5 -0
  83. package/dist/util/bintrie.d.ts +93 -0
  84. package/dist/util/countedhash.d.ts +19 -0
  85. package/dist/util/gradient.d.ts +15 -0
  86. package/dist/util/indexedarray.d.ts +15 -0
  87. package/dist/util/util.d.ts +68 -0
  88. package/docs/context.md +2 -0
  89. package/docs/dbabstract.md +2 -0
  90. package/docs/dbdynamo.md +2 -0
  91. package/docs/fsm.md +243 -0
  92. package/docs/fsmfile.md +2 -0
  93. package/docs/jsonstream.md +44 -0
  94. package/docs/lambda.md +2 -0
  95. package/docs/logabstract.md +2 -0
  96. package/docs/logclient.md +2 -0
  97. package/docs/logserver.md +2 -0
  98. package/docs/ot-editutil.md +2 -0
  99. package/docs/ot-js.md +95 -0
  100. package/docs/poly.md +103 -0
  101. package/docs/storage.md +2 -0
  102. package/docs/storages3.md +2 -0
  103. package/docs/util.md +2 -0
  104. package/lib/all/all.ts +41 -0
  105. package/lib/all/allclient.ts +19 -0
  106. package/lib/context/all.ts +1 -0
  107. package/lib/context/context.ts +82 -0
  108. package/lib/dbabstract/all.ts +1 -0
  109. package/lib/dbabstract/db.ts +246 -0
  110. package/lib/dbdynamo/all.ts +1 -0
  111. package/lib/dbdynamo/dbdynamo.ts +1551 -0
  112. package/lib/filterexpr/all.ts +1 -0
  113. package/lib/filterexpr/filterexpr.ts +625 -0
  114. package/lib/fsm/all.ts +1 -0
  115. package/lib/fsm/fsm.ts +549 -0
  116. package/lib/fsmfile/all.ts +1 -0
  117. package/lib/fsmfile/fsmfile.ts +236 -0
  118. package/lib/jsonstream/all.ts +1 -0
  119. package/lib/jsonstream/jsonstream.ts +940 -0
  120. package/lib/lambda/all.ts +1 -0
  121. package/lib/lambda/env.ts +13 -0
  122. package/lib/lambda/lambda.ts +120 -0
  123. package/lib/logabstract/all.ts +1 -0
  124. package/lib/logabstract/log.ts +55 -0
  125. package/lib/logclient/all.ts +1 -0
  126. package/lib/logclient/log.ts +105 -0
  127. package/lib/logserver/all.ts +5 -0
  128. package/lib/logserver/log.ts +565 -0
  129. package/lib/logserver/logaccum.ts +1445 -0
  130. package/lib/logserver/logblob.ts +84 -0
  131. package/lib/logserver/logconcat.ts +313 -0
  132. package/lib/logserver/logkey.ts +125 -0
  133. package/lib/memsqs/all.ts +4 -0
  134. package/lib/memsqs/client.ts +268 -0
  135. package/lib/memsqs/loopback.ts +64 -0
  136. package/lib/memsqs/orderedlist.ts +74 -0
  137. package/lib/memsqs/queue.ts +395 -0
  138. package/lib/memsqs/server.ts +262 -0
  139. package/lib/ot-editutil/all.ts +2 -0
  140. package/lib/ot-editutil/oteditutil.ts +180 -0
  141. package/lib/ot-editutil/otmaputil.ts +209 -0
  142. package/lib/ot-js/all.ts +9 -0
  143. package/lib/ot-js/otarray.ts +1168 -0
  144. package/lib/ot-js/otclientengine.ts +327 -0
  145. package/lib/ot-js/otcomposite.ts +247 -0
  146. package/lib/ot-js/otcounter.ts +145 -0
  147. package/lib/ot-js/otengine.ts +71 -0
  148. package/lib/ot-js/otmap.ts +144 -0
  149. package/lib/ot-js/otserverengine.ts +329 -0
  150. package/lib/ot-js/otsession.ts +199 -0
  151. package/lib/ot-js/ottypes.ts +98 -0
  152. package/lib/poly/all.ts +15 -0
  153. package/lib/poly/blend.ts +27 -0
  154. package/lib/poly/boundbox.ts +102 -0
  155. package/lib/poly/cartesian.ts +130 -0
  156. package/lib/poly/graham-scan.ts +401 -0
  157. package/lib/poly/hash.ts +15 -0
  158. package/lib/poly/matrix.ts +309 -0
  159. package/lib/poly/minbound.ts +211 -0
  160. package/lib/poly/poly.ts +767 -0
  161. package/lib/poly/polybin.ts +218 -0
  162. package/lib/poly/polylabel.ts +204 -0
  163. package/lib/poly/polypack.ts +458 -0
  164. package/lib/poly/polyround.ts +30 -0
  165. package/lib/poly/polysimplify.ts +24 -0
  166. package/lib/poly/quad.ts +272 -0
  167. package/lib/poly/selfintersect.ts +87 -0
  168. package/lib/poly/shamos.ts +297 -0
  169. package/lib/poly/simplify.ts +119 -0
  170. package/lib/poly/topo.ts +525 -0
  171. package/lib/poly/union.ts +371 -0
  172. package/lib/storage/all.ts +4 -0
  173. package/lib/storage/datablob.ts +36 -0
  174. package/lib/storage/env.ts +14 -0
  175. package/lib/storage/splitsblob.ts +63 -0
  176. package/lib/storage/storage.ts +604 -0
  177. package/lib/storages3/all.ts +1 -0
  178. package/lib/storages3/s3.ts +576 -0
  179. package/lib/util/all.ts +5 -0
  180. package/lib/util/bintrie.ts +603 -0
  181. package/lib/util/countedhash.ts +83 -0
  182. package/lib/util/gradient.ts +108 -0
  183. package/lib/util/indexedarray.ts +80 -0
  184. package/lib/util/util.ts +695 -0
  185. package/package.json +8 -8
@@ -0,0 +1,371 @@
1
+ import * as PC from 'polygon-clipping';
2
+
3
+ import * as Util from '../util/all';
4
+ import * as FSM from '../fsm/all';
5
+
6
+ import * as Poly from './poly';
7
+ import * as Q from './quad';
8
+ import * as PP from './polypack';
9
+ import * as PR from './polyround';
10
+
11
+ // Confusion on how polygon-clipping exposes its interface - be flexible
12
+ let _union: any = undefined;
13
+ let _difference: any = undefined;
14
+ let _intersection: any = undefined;
15
+ let anyPC: any = PC;
16
+ if (anyPC.union) _union = anyPC.union;
17
+ else if (anyPC.default && anyPC.default.union) _union = anyPC.default.union;
18
+ if (_union === undefined) throw 'Unable to load union function from polygon-clipping';
19
+ if (anyPC.difference) _difference = anyPC.difference;
20
+ else if (anyPC.default && anyPC.default.difference) _difference = anyPC.default.difference;
21
+ if (_difference === undefined) throw 'Unable to load difference function from polygon-clipping';
22
+ if (anyPC.intersection) _intersection = anyPC.intersection;
23
+ else if (anyPC.default && anyPC.default.intersection) _intersection = anyPC.default.intersection;
24
+ if (_intersection === undefined) throw 'Unable to load intersection function from polygon-clipping';
25
+
26
+ const FSM_COMPUTING = FSM.FSM_CUSTOM1;
27
+
28
+ function unpackCoords(buffer: Float64Array, offset: number, nPoints: number): any
29
+ {
30
+ let c: any[] = [];
31
+
32
+ let end = offset + nPoints*2;
33
+ for (; offset < end; offset += 2)
34
+ c.push([buffer[offset], buffer[offset+1]]);
35
+ return [ c ];
36
+ }
37
+
38
+ export function polyIntersects(p1: any, p2: any): boolean
39
+ {
40
+ let pp1 = Poly.polyNormalize(p1);
41
+ let pp2 = Poly.polyNormalize(p2);
42
+ let bIntersects: boolean = false;
43
+
44
+ PP.polyPackEachRing(pp1, (buffer1: Float64Array, iPoly1: number, iRing1: number, iOffset1: number, nPoints1: number) => {
45
+ if (iRing1 == 0)
46
+ {
47
+ let c1 = unpackCoords(buffer1, iOffset1, nPoints1);
48
+ PP.polyPackEachRing(pp2, (buffer2: Float64Array, iPoly2: number, iRing2: number, iOffset2: number, nPoints2: number) => {
49
+ if (iRing2 == 0)
50
+ {
51
+ let c2 = unpackCoords(buffer2, iOffset2, nPoints2);
52
+ let result = _intersection(c1, c2);
53
+ if (result && result.length > 0)
54
+ bIntersects = true;
55
+ }
56
+ });
57
+ }
58
+ });
59
+ return bIntersects;
60
+ }
61
+
62
+ class FsmDifference extends FSM.Fsm
63
+ {
64
+ accum: any;
65
+ polys: any[];
66
+ work: Q.WorkDone;
67
+
68
+ constructor(env: FSM.FsmEnvironment, accum?: any, polys?: any[])
69
+ {
70
+ super(env);
71
+ this.work = { nUnion: 0, nDifference: 0, ms: 0 };
72
+ this.initialize(accum, polys);
73
+ }
74
+
75
+ initialize(accum: any, polys: any[])
76
+ {
77
+ this.accum = accum;
78
+ this.polys = polys;
79
+ if (polys == null || polys.length == 0)
80
+ this.setState(FSM.FSM_DONE);
81
+ else
82
+ {
83
+ this.work.nDifference = polys.length;
84
+ this.setState(FSM.FSM_STARTING);
85
+ }
86
+ }
87
+
88
+ cancel(): void
89
+ {
90
+ this.accum = null;
91
+ this.polys = null;
92
+ this.setState(FSM.FSM_DONE);
93
+ }
94
+
95
+ get result(): any
96
+ {
97
+ return this.accum;
98
+ }
99
+
100
+ tick(): void
101
+ {
102
+ if (this.ready)
103
+ {
104
+ switch (this.state)
105
+ {
106
+ case FSM.FSM_STARTING:
107
+ if (this.polys == null)
108
+ this.setState(FSM.FSM_DONE);
109
+ else
110
+ this.setState(FSM_COMPUTING);
111
+ break;
112
+
113
+ case FSM_COMPUTING:
114
+ let elapsed = new Util.Elapsed();
115
+ this.accum = PR.polyRound(_difference(this.accum, this.polys));
116
+ this.work.ms = elapsed.ms();
117
+ this.polys = null;
118
+ this.setState(FSM.FSM_DONE);
119
+ break;
120
+ }
121
+ }
122
+ }
123
+ }
124
+
125
+ const FSM_UNION = FSM.FSM_CUSTOM1;
126
+ const FSM_DIFFERENCE = FSM.FSM_CUSTOM2;
127
+
128
+ function coords(f: any): any
129
+ {
130
+ return (f.geometry !== undefined) ? (f.geometry.packed !== undefined ? f.geometry.packed : f.geometry.coordinates) : f;
131
+ }
132
+
133
+ class FsmIncrementalUnion extends FSM.Fsm
134
+ {
135
+ options: Poly.TickOptions;
136
+ key: any;
137
+ map: any; // { [geoid: string]: Feature }
138
+ result: any;
139
+ lastCompleteMap: any;
140
+ lastCompleteResult: any;
141
+ toSub: any[];
142
+ fsmUnion: Q.FsmQuadTree;
143
+ fsmDifference: FsmDifference;
144
+ work: Q.WorkDone;
145
+
146
+ constructor(env: FSM.FsmEnvironment, options: Poly.TickOptions, key: any, map?: any)
147
+ {
148
+ super(env);
149
+ this.options = options;
150
+ this.key = key;
151
+ this.result = null;
152
+ this.map = null;
153
+ this.lastCompleteResult = null;
154
+ this.lastCompleteMap = null;
155
+ this.toSub = null;
156
+ this.fsmUnion = null;
157
+ this.fsmDifference = null;
158
+ if (map) this.recompute(map);
159
+ }
160
+
161
+ matches(key: any): boolean
162
+ {
163
+ return Util.shallowEqual(this.key, key);
164
+ }
165
+
166
+ recompute(map: any): void
167
+ {
168
+ // If a computation is in progress, just cancel and restart
169
+ if (this.fsmUnion)
170
+ {
171
+ this.fsmUnion.cancel();
172
+ this.fsmUnion = null;
173
+ this.result = this.lastCompleteResult;
174
+ this.map = this.lastCompleteMap;
175
+ }
176
+ if (this.fsmDifference)
177
+ {
178
+ this.fsmDifference.cancel();
179
+ this.fsmDifference = null;
180
+ this.result = this.lastCompleteResult;
181
+ this.map = this.lastCompleteMap;
182
+ }
183
+
184
+ let polys: any[] = [];
185
+ if (this.result == null || Util.isEmpty(map))
186
+ {
187
+ // Starting from scratch
188
+ this.toSub = null;
189
+ for (let id in map) if (map.hasOwnProperty(id))
190
+ polys.push(coords(map[id]));
191
+ }
192
+ else
193
+ {
194
+ // We have the result of a previous computation - compute a difference since we assume
195
+ // that is cheaper (often only one or two polygons added or removed).
196
+ let id: string;
197
+
198
+ // To add (polygons in new map did not occur in old map)
199
+ polys.push(this.result);
200
+ this.result = null;
201
+ for (id in map) if (map.hasOwnProperty(id) && this.map[id] === undefined)
202
+ polys.push(coords(map[id]));
203
+
204
+ // To sub
205
+ this.toSub = [];
206
+ for (id in this.map) if (this.map.hasOwnProperty(id) && map[id] === undefined)
207
+ {
208
+ let c = PP.polyUnpack(coords(this.map[id]));
209
+ if (Util.depthof(c) === 5)
210
+ for (let i: number = 0; i < c.length; i++)
211
+ this.toSub.push(c[i]);
212
+ else
213
+ this.toSub.push(c);
214
+ }
215
+ if (this.toSub.length == 0)
216
+ this.toSub = null;
217
+ }
218
+
219
+ // Short-circuit when no work to be done
220
+ if (polys.length == 1 && this.toSub == null && this.lastCompleteResult)
221
+ {
222
+ this.work = { nUnion: 0, nDifference: 0, ms: 0 };
223
+ this.result = this.lastCompleteResult;
224
+ this.map = this.lastCompleteMap;
225
+ this.setState(FSM.FSM_DONE);
226
+ }
227
+ else
228
+ {
229
+ this.work = { nUnion: polys.length - 1, nDifference: this.toSub ? this.toSub.length : 0, ms: 0 };
230
+ this.fsmUnion = new Q.FsmQuadTree(this.env, this.options, polys);
231
+ this.waitOn(this.fsmUnion);
232
+ this.setState(FSM_UNION);
233
+ this.map = map;
234
+ }
235
+ }
236
+
237
+ cancel(): void
238
+ {
239
+ if (this.fsmUnion)
240
+ {
241
+ this.fsmUnion.cancel();
242
+ this.fsmUnion = null;
243
+ }
244
+ if (this.fsmDifference)
245
+ {
246
+ this.fsmDifference.cancel();
247
+ this.fsmDifference = null;
248
+ }
249
+ this.result = null;
250
+ this.map = null;
251
+ this.lastCompleteResult = null;
252
+ this.lastCompleteMap = null;
253
+ this.setState(FSM.FSM_DONE);
254
+ }
255
+
256
+ tick(): void
257
+ {
258
+ if (this.ready)
259
+ {
260
+ switch (this.state)
261
+ {
262
+ case FSM.FSM_STARTING:
263
+ // never initialized to do work (see recompute())
264
+ this.setState(FSM.FSM_DONE);
265
+ break;
266
+
267
+ case FSM_UNION:
268
+ if (this.fsmUnion)
269
+ this.work.ms += this.fsmUnion.work.ms;
270
+ this.fsmDifference = new FsmDifference(this.env, this.fsmUnion.result, this.toSub);
271
+ this.waitOn(this.fsmDifference);
272
+ this.toSub = null;
273
+ this.fsmUnion = null;
274
+ this.setState(FSM_DIFFERENCE);
275
+ break;
276
+
277
+ case FSM_DIFFERENCE:
278
+ this.result = this.fsmDifference.result;
279
+ this.work.ms += this.fsmDifference.work.ms;
280
+ this.lastCompleteResult = this.result;
281
+ this.lastCompleteMap = this.map;
282
+ this.fsmDifference = null;
283
+ this.setState(FSM.FSM_DONE);
284
+ break;
285
+ }
286
+ }
287
+ }
288
+ }
289
+
290
+ export interface UnionResult
291
+ {
292
+ key: any;
293
+ poly: any;
294
+ work: Q.WorkDone;
295
+ }
296
+
297
+ export class FsmUnion extends FSM.Fsm
298
+ {
299
+ options: Poly.TickOptions;
300
+ unions: FsmIncrementalUnion[];
301
+ work: Q.WorkDone;
302
+
303
+ constructor(env: FSM.FsmEnvironment, options?: Poly.TickOptions)
304
+ {
305
+ super(env);
306
+ this.options = Util.shallowAssignImmutable(Poly.DefaultTickOptions, options);
307
+ this.unions = [];
308
+ this.work = { nUnion: 0, nDifference: 0, ms: 0 };
309
+ }
310
+
311
+ get result(): UnionResult[]
312
+ {
313
+ if (this.unions.length > 0 && this.state === FSM.FSM_DONE)
314
+ return this.unions.map((i: FsmIncrementalUnion) => ({ key: i.key, poly: i.result, work: i.work }) );
315
+ else
316
+ return null;
317
+ }
318
+
319
+ cancel(): void
320
+ {
321
+ this.unions.forEach((i: FsmIncrementalUnion) => {
322
+ i.cancel();
323
+ });
324
+ this.unions = [];
325
+ this.setState(FSM.FSM_DONE);
326
+ }
327
+
328
+ cancelOne(key: any): void
329
+ {
330
+ for (let i = 0; i < this.unions.length; i++)
331
+ {
332
+ let u = this.unions[i];
333
+ if (u.matches(key))
334
+ {
335
+ u.cancel();
336
+ return;
337
+ }
338
+ }
339
+ }
340
+
341
+ recompute(key: any, map: any): void
342
+ {
343
+ let fsm: FsmIncrementalUnion = this.unions.find((i: FsmIncrementalUnion) => i.matches(key));
344
+ if (fsm == null)
345
+ {
346
+ fsm = new FsmIncrementalUnion(this.env, this.options, key, map);
347
+ this.unions.push(fsm);
348
+ }
349
+ else
350
+ fsm.recompute(map);
351
+ this.work = { nUnion: 0, nDifference: 0, ms: 0 };
352
+ this.unions.forEach((u) => { this.work.nUnion += u.work.nUnion; this.work.nDifference += u.work.nDifference });
353
+ this.waitOn(fsm);
354
+ this.setState(FSM_COMPUTING);
355
+ }
356
+
357
+ tick(): void
358
+ {
359
+ if (this.ready)
360
+ {
361
+ switch (this.state)
362
+ {
363
+ case FSM.FSM_STARTING:
364
+ case FSM_COMPUTING:
365
+ if (this.unions) this.unions.forEach((u) => { this.work.ms += u.work.ms });
366
+ this.setState(FSM.FSM_DONE);
367
+ break;
368
+ }
369
+ }
370
+ }
371
+ }
@@ -0,0 +1,4 @@
1
+ export * from './env';
2
+ export * from './storage';
3
+ export * from './datablob';
4
+ export * from './splitsblob';
@@ -0,0 +1,36 @@
1
+ // Shared libraries
2
+ import * as Util from '../util/all';
3
+ import * as Context from '../context/all';
4
+ import * as LogAbstract from '../logabstract/all';
5
+ import * as FSM from '../fsm/all';
6
+
7
+ // App libraries
8
+ import { Environment } from './env';
9
+ import * as Storage from './storage';
10
+
11
+ export class DataBlob extends Storage.StorageBlob
12
+ {
13
+ constructor(env: Environment, params: Storage.BlobParams)
14
+ {
15
+ if (params.bucket == null) params.bucket = env.context.xflag('production') ? 'data' : 'data-dev';
16
+ super(env, params);
17
+ }
18
+
19
+ get env(): Environment { return this._env as Environment; }
20
+
21
+ get json(): any { return this.params.loadTo }
22
+
23
+ static createForJSON(env: Environment, id: string): DataBlob
24
+ {
25
+ let blob = new DataBlob(env, { id: id, loadToType: 'object' });
26
+ blob.startLoad(env.storageManager);
27
+ return blob;
28
+ }
29
+
30
+ static createForStream(env: Environment, id: string, bucket?: string): DataBlob
31
+ {
32
+ let blob = new DataBlob(env, { id: id, bucket: bucket, loadToType: 'stream' });
33
+ blob.startLoad(env.storageManager);
34
+ return blob;
35
+ }
36
+ }
@@ -0,0 +1,14 @@
1
+ // Shared libraries
2
+ import * as Context from '../context/all';
3
+ import * as FSM from '../fsm/all';
4
+ import * as LogAbstract from '../logabstract/all';
5
+
6
+ import * as Storage from './storage';
7
+
8
+ export interface Environment
9
+ {
10
+ context: Context.IContext;
11
+ log: LogAbstract.ILog;
12
+ fsmManager: FSM.FsmManager;
13
+ storageManager: Storage.StorageManager;
14
+ }
@@ -0,0 +1,63 @@
1
+ // Node
2
+ import * as zlib from 'zlib';
3
+
4
+ // Shared libraries
5
+ import * as Context from '../context/all';
6
+ import * as LogAbstract from '../logabstract/all';
7
+ import * as FSM from '../fsm/all';
8
+
9
+ // App libraries
10
+ import { Environment } from './env';
11
+ import * as Storage from './storage';
12
+
13
+ export class SplitsBlob extends Storage.StorageBlob
14
+ {
15
+ ls: { [key: string]: Storage.BlobProperties };
16
+
17
+ constructor(env: Environment, params: Storage.BlobParams)
18
+ {
19
+ if (params.bucket === undefined) params.bucket = env.context.xflag('production') ? 'splits' : 'splits-dev';
20
+ super(env, params);
21
+ }
22
+
23
+ get env(): Environment { return this._env as Environment; }
24
+
25
+ get collection(): any { return this.params.loadTo }
26
+
27
+ static createForLs(env: Environment): SplitsBlob
28
+ {
29
+ let blob = new SplitsBlob(env, { id: '' });
30
+ blob.startList(env.storageManager);
31
+ new FSM.FsmOnDone(env, blob.fsmList, (f: FSM.Fsm) => {
32
+ if (! f.iserror)
33
+ {
34
+ blob.ls = {};
35
+ blob.keys.forEach((k: string, i: number) => { blob.ls[k] = blob.props[i] });
36
+ }
37
+ });
38
+ return blob;
39
+ }
40
+
41
+ static createForUpload(env: Environment, id: string, collection: any): SplitsBlob
42
+ {
43
+ let params: Storage.BlobParams = {
44
+ id: id,
45
+ saveFromType: 'object',
46
+ saveFrom: collection,
47
+ ContentEncoding: 'gzip',
48
+ ContentType: 'application/json',
49
+ CacheControl: 'no-cache'
50
+ };
51
+ let blob = new SplitsBlob(env, params);
52
+ blob.setDirty();
53
+ blob.checkSave(env.storageManager);
54
+ return blob;
55
+ }
56
+
57
+ static createForDownload(env: Environment, id: string): SplitsBlob
58
+ {
59
+ let blob = new SplitsBlob(env, { id: id, loadToType: 'object' });
60
+ blob.startLoad(env.storageManager);
61
+ return blob;
62
+ }
63
+ }