@dra2020/dra-types 1.0.6 → 1.0.9

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.
@@ -23,6 +23,7 @@ export interface UserLikes {
23
23
  }
24
24
  export interface SplitBlock {
25
25
  id?: string;
26
+ chunk?: string;
26
27
  state: string;
27
28
  datasource: string;
28
29
  geoid: string;
@@ -31,3 +32,9 @@ export interface SplitBlock {
31
32
  export declare type DistrictToSplitBlock = {
32
33
  [nDistrict: number]: SplitBlock[];
33
34
  };
35
+ export declare function vgeoidToGeoid(vgeoid: string): string;
36
+ export declare function vgeoidToChunk(vgeoid: string): string;
37
+ export declare function isVfeature(geoid: string): boolean;
38
+ export declare function splitToCacheKey(s: SplitBlock): string;
39
+ export declare function splitToChunkKey(s: SplitBlock): string;
40
+ export declare function splitToPrefix(s: SplitBlock): string;
package/dist/dra-types.js CHANGED
@@ -105,9 +105,557 @@ return /******/ (function(modules) { // webpackBootstrap
105
105
 
106
106
  "use strict";
107
107
 
108
+ function __export(m) {
109
+ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
110
+ }
108
111
  Object.defineProperty(exports, "__esModule", { value: true });
112
+ __export(__webpack_require__(/*! ./dra-types */ "./lib/dra-types.ts"));
109
113
 
110
114
 
115
+ /***/ }),
116
+
117
+ /***/ "./lib/dra-types.ts":
118
+ /*!**************************!*\
119
+ !*** ./lib/dra-types.ts ***!
120
+ \**************************/
121
+ /*! no static exports found */
122
+ /***/ (function(module, exports, __webpack_require__) {
123
+
124
+ "use strict";
125
+
126
+ Object.defineProperty(exports, "__esModule", { value: true });
127
+ // Public libraries
128
+ const Hash = __webpack_require__(/*! object-hash */ "./node_modules/object-hash/index.js");
129
+ // Canonical hashing of splitblock data
130
+ function hash(o) {
131
+ return Hash(o, { respectType: false,
132
+ unorderedArrays: true,
133
+ unorderedObjects: true,
134
+ excludeKeys: (k) => (k === 'id' || k === 'chunk')
135
+ });
136
+ }
137
+ function vgeoidToGeoid(vgeoid) {
138
+ let re = /vfeature_([^_]*)_.*/;
139
+ let a = re.exec(vgeoid);
140
+ if (a == null || a.length != 2)
141
+ return '';
142
+ else
143
+ return a[1];
144
+ }
145
+ exports.vgeoidToGeoid = vgeoidToGeoid;
146
+ function vgeoidToChunk(vgeoid) {
147
+ // vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
148
+ // the contents are chunked into a file of form "vfeature_chunk_[chunkid]"
149
+ // So extract the chunk ID and download that.
150
+ let re = /vfeature_([^_]*)_([^_*])_(.*)/;
151
+ let a = re.exec(vgeoid);
152
+ if (a && a.length == 4)
153
+ vgeoid = `vfeature_chunk_${a[2]}`;
154
+ else
155
+ vgeoid = null;
156
+ return vgeoid;
157
+ }
158
+ exports.vgeoidToChunk = vgeoidToChunk;
159
+ function isVfeature(geoid) {
160
+ return geoid.indexOf('vfeature') === 0;
161
+ }
162
+ exports.isVfeature = isVfeature;
163
+ function splitToCacheKey(s) {
164
+ if (s.id === undefined)
165
+ s.id = hash(s);
166
+ if (s.chunk === undefined)
167
+ s.chunk = "0";
168
+ return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;
169
+ }
170
+ exports.splitToCacheKey = splitToCacheKey;
171
+ function splitToChunkKey(s) {
172
+ if (s.chunk === undefined)
173
+ s.chunk = "0";
174
+ return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;
175
+ }
176
+ exports.splitToChunkKey = splitToChunkKey;
177
+ function splitToPrefix(s) {
178
+ if (s.blocks === undefined) {
179
+ let re = /_([^_]*)_(.*)_vfeature.*\.geojson$/;
180
+ let a = re.exec(s.id);
181
+ if (a && a.length == 3)
182
+ return `_${a[1]}_${a[2]}`;
183
+ return s.id;
184
+ }
185
+ return `_${s.state}_${s.datasource}`;
186
+ }
187
+ exports.splitToPrefix = splitToPrefix;
188
+
189
+
190
+ /***/ }),
191
+
192
+ /***/ "./node_modules/object-hash/index.js":
193
+ /*!*******************************************!*\
194
+ !*** ./node_modules/object-hash/index.js ***!
195
+ \*******************************************/
196
+ /*! no static exports found */
197
+ /***/ (function(module, exports, __webpack_require__) {
198
+
199
+ "use strict";
200
+
201
+
202
+ var crypto = __webpack_require__(/*! crypto */ "crypto");
203
+
204
+ /**
205
+ * Exported function
206
+ *
207
+ * Options:
208
+ *
209
+ * - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'
210
+ * - `excludeValues` {true|*false} hash object keys, values ignored
211
+ * - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'
212
+ * - `ignoreUnknown` {true|*false} ignore unknown object types
213
+ * - `replacer` optional function that replaces values before hashing
214
+ * - `respectFunctionProperties` {*true|false} consider function properties when hashing
215
+ * - `respectFunctionNames` {*true|false} consider 'name' property of functions for hashing
216
+ * - `respectType` {*true|false} Respect special properties (prototype, constructor)
217
+ * when hashing to distinguish between types
218
+ * - `unorderedArrays` {true|*false} Sort all arrays before hashing
219
+ * - `unorderedSets` {*true|false} Sort `Set` and `Map` instances before hashing
220
+ * * = default
221
+ *
222
+ * @param {object} object value to hash
223
+ * @param {object} options hashing options
224
+ * @return {string} hash value
225
+ * @api public
226
+ */
227
+ exports = module.exports = objectHash;
228
+
229
+ function objectHash(object, options){
230
+ options = applyDefaults(object, options);
231
+
232
+ return hash(object, options);
233
+ }
234
+
235
+ /**
236
+ * Exported sugar methods
237
+ *
238
+ * @param {object} object value to hash
239
+ * @return {string} hash value
240
+ * @api public
241
+ */
242
+ exports.sha1 = function(object){
243
+ return objectHash(object);
244
+ };
245
+ exports.keys = function(object){
246
+ return objectHash(object, {excludeValues: true, algorithm: 'sha1', encoding: 'hex'});
247
+ };
248
+ exports.MD5 = function(object){
249
+ return objectHash(object, {algorithm: 'md5', encoding: 'hex'});
250
+ };
251
+ exports.keysMD5 = function(object){
252
+ return objectHash(object, {algorithm: 'md5', encoding: 'hex', excludeValues: true});
253
+ };
254
+
255
+ // Internals
256
+ var hashes = crypto.getHashes ? crypto.getHashes().slice() : ['sha1', 'md5'];
257
+ hashes.push('passthrough');
258
+ var encodings = ['buffer', 'hex', 'binary', 'base64'];
259
+
260
+ function applyDefaults(object, sourceOptions){
261
+ sourceOptions = sourceOptions || {};
262
+
263
+ // create a copy rather than mutating
264
+ var options = {};
265
+ options.algorithm = sourceOptions.algorithm || 'sha1';
266
+ options.encoding = sourceOptions.encoding || 'hex';
267
+ options.excludeValues = sourceOptions.excludeValues ? true : false;
268
+ options.algorithm = options.algorithm.toLowerCase();
269
+ options.encoding = options.encoding.toLowerCase();
270
+ options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true; // default to false
271
+ options.respectType = sourceOptions.respectType === false ? false : true; // default to true
272
+ options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
273
+ options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
274
+ options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true; // default to false
275
+ options.unorderedSets = sourceOptions.unorderedSets === false ? false : true; // default to false
276
+ options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true; // default to true
277
+ options.replacer = sourceOptions.replacer || undefined;
278
+ options.excludeKeys = sourceOptions.excludeKeys || undefined;
279
+
280
+ if(typeof object === 'undefined') {
281
+ throw new Error('Object argument required.');
282
+ }
283
+
284
+ // if there is a case-insensitive match in the hashes list, accept it
285
+ // (i.e. SHA256 for sha256)
286
+ for (var i = 0; i < hashes.length; ++i) {
287
+ if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
288
+ options.algorithm = hashes[i];
289
+ }
290
+ }
291
+
292
+ if(hashes.indexOf(options.algorithm) === -1){
293
+ throw new Error('Algorithm "' + options.algorithm + '" not supported. ' +
294
+ 'supported values: ' + hashes.join(', '));
295
+ }
296
+
297
+ if(encodings.indexOf(options.encoding) === -1 &&
298
+ options.algorithm !== 'passthrough'){
299
+ throw new Error('Encoding "' + options.encoding + '" not supported. ' +
300
+ 'supported values: ' + encodings.join(', '));
301
+ }
302
+
303
+ return options;
304
+ }
305
+
306
+ /** Check if the given function is a native function */
307
+ function isNativeFunction(f) {
308
+ if ((typeof f) !== 'function') {
309
+ return false;
310
+ }
311
+ var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
312
+ return exp.exec(Function.prototype.toString.call(f)) != null;
313
+ }
314
+
315
+ function hash(object, options) {
316
+ var hashingStream;
317
+
318
+ if (options.algorithm !== 'passthrough') {
319
+ hashingStream = crypto.createHash(options.algorithm);
320
+ } else {
321
+ hashingStream = new PassThrough();
322
+ }
323
+
324
+ if (typeof hashingStream.write === 'undefined') {
325
+ hashingStream.write = hashingStream.update;
326
+ hashingStream.end = hashingStream.update;
327
+ }
328
+
329
+ var hasher = typeHasher(options, hashingStream);
330
+ hasher.dispatch(object);
331
+ if (!hashingStream.update) {
332
+ hashingStream.end('');
333
+ }
334
+
335
+ if (hashingStream.digest) {
336
+ return hashingStream.digest(options.encoding === 'buffer' ? undefined : options.encoding);
337
+ }
338
+
339
+ var buf = hashingStream.read();
340
+ if (options.encoding === 'buffer') {
341
+ return buf;
342
+ }
343
+
344
+ return buf.toString(options.encoding);
345
+ }
346
+
347
+ /**
348
+ * Expose streaming API
349
+ *
350
+ * @param {object} object Value to serialize
351
+ * @param {object} options Options, as for hash()
352
+ * @param {object} stream A stream to write the serializiation to
353
+ * @api public
354
+ */
355
+ exports.writeToStream = function(object, options, stream) {
356
+ if (typeof stream === 'undefined') {
357
+ stream = options;
358
+ options = {};
359
+ }
360
+
361
+ options = applyDefaults(object, options);
362
+
363
+ return typeHasher(options, stream).dispatch(object);
364
+ };
365
+
366
+ function typeHasher(options, writeTo, context){
367
+ context = context || [];
368
+ var write = function(str) {
369
+ if (writeTo.update) {
370
+ return writeTo.update(str, 'utf8');
371
+ } else {
372
+ return writeTo.write(str, 'utf8');
373
+ }
374
+ };
375
+
376
+ return {
377
+ dispatch: function(value){
378
+ if (options.replacer) {
379
+ value = options.replacer(value);
380
+ }
381
+
382
+ var type = typeof value;
383
+ if (value === null) {
384
+ type = 'null';
385
+ }
386
+
387
+ //console.log("[DEBUG] Dispatch: ", value, "->", type, " -> ", "_" + type);
388
+
389
+ return this['_' + type](value);
390
+ },
391
+ _object: function(object) {
392
+ var pattern = (/\[object (.*)\]/i);
393
+ var objString = Object.prototype.toString.call(object);
394
+ var objType = pattern.exec(objString);
395
+ if (!objType) { // object type did not match [object ...]
396
+ objType = 'unknown:[' + objString + ']';
397
+ } else {
398
+ objType = objType[1]; // take only the class name
399
+ }
400
+
401
+ objType = objType.toLowerCase();
402
+
403
+ var objectNumber = null;
404
+
405
+ if ((objectNumber = context.indexOf(object)) >= 0) {
406
+ return this.dispatch('[CIRCULAR:' + objectNumber + ']');
407
+ } else {
408
+ context.push(object);
409
+ }
410
+
411
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(object)) {
412
+ write('buffer:');
413
+ return write(object);
414
+ }
415
+
416
+ if(objType !== 'object' && objType !== 'function') {
417
+ if(this['_' + objType]) {
418
+ this['_' + objType](object);
419
+ } else if (options.ignoreUnknown) {
420
+ return write('[' + objType + ']');
421
+ } else {
422
+ throw new Error('Unknown object type "' + objType + '"');
423
+ }
424
+ }else{
425
+ var keys = Object.keys(object);
426
+ if (options.unorderedObjects) {
427
+ keys = keys.sort();
428
+ }
429
+ // Make sure to incorporate special properties, so
430
+ // Types with different prototypes will produce
431
+ // a different hash and objects derived from
432
+ // different functions (`new Foo`, `new Bar`) will
433
+ // produce different hashes.
434
+ // We never do this for native functions since some
435
+ // seem to break because of that.
436
+ if (options.respectType !== false && !isNativeFunction(object)) {
437
+ keys.splice(0, 0, 'prototype', '__proto__', 'constructor');
438
+ }
439
+
440
+ if (options.excludeKeys) {
441
+ keys = keys.filter(function(key) { return !options.excludeKeys(key); });
442
+ }
443
+
444
+ write('object:' + keys.length + ':');
445
+ var self = this;
446
+ return keys.forEach(function(key){
447
+ self.dispatch(key);
448
+ write(':');
449
+ if(!options.excludeValues) {
450
+ self.dispatch(object[key]);
451
+ }
452
+ write(',');
453
+ });
454
+ }
455
+ },
456
+ _array: function(arr, unordered){
457
+ unordered = typeof unordered !== 'undefined' ? unordered :
458
+ options.unorderedArrays !== false; // default to options.unorderedArrays
459
+
460
+ var self = this;
461
+ write('array:' + arr.length + ':');
462
+ if (!unordered || arr.length <= 1) {
463
+ return arr.forEach(function(entry) {
464
+ return self.dispatch(entry);
465
+ });
466
+ }
467
+
468
+ // the unordered case is a little more complicated:
469
+ // since there is no canonical ordering on objects,
470
+ // i.e. {a:1} < {a:2} and {a:1} > {a:2} are both false,
471
+ // we first serialize each entry using a PassThrough stream
472
+ // before sorting.
473
+ // also: we can’t use the same context array for all entries
474
+ // since the order of hashing should *not* matter. instead,
475
+ // we keep track of the additions to a copy of the context array
476
+ // and add all of them to the global context array when we’re done
477
+ var contextAdditions = [];
478
+ var entries = arr.map(function(entry) {
479
+ var strm = new PassThrough();
480
+ var localContext = context.slice(); // make copy
481
+ var hasher = typeHasher(options, strm, localContext);
482
+ hasher.dispatch(entry);
483
+ // take only what was added to localContext and append it to contextAdditions
484
+ contextAdditions = contextAdditions.concat(localContext.slice(context.length));
485
+ return strm.read().toString();
486
+ });
487
+ context = context.concat(contextAdditions);
488
+ entries.sort();
489
+ return this._array(entries, false);
490
+ },
491
+ _date: function(date){
492
+ return write('date:' + date.toJSON());
493
+ },
494
+ _symbol: function(sym){
495
+ return write('symbol:' + sym.toString());
496
+ },
497
+ _error: function(err){
498
+ return write('error:' + err.toString());
499
+ },
500
+ _boolean: function(bool){
501
+ return write('bool:' + bool.toString());
502
+ },
503
+ _string: function(string){
504
+ write('string:' + string.length + ':');
505
+ write(string.toString());
506
+ },
507
+ _function: function(fn){
508
+ write('fn:');
509
+ if (isNativeFunction(fn)) {
510
+ this.dispatch('[native]');
511
+ } else {
512
+ this.dispatch(fn.toString());
513
+ }
514
+
515
+ if (options.respectFunctionNames !== false) {
516
+ // Make sure we can still distinguish native functions
517
+ // by their name, otherwise String and Function will
518
+ // have the same hash
519
+ this.dispatch("function-name:" + String(fn.name));
520
+ }
521
+
522
+ if (options.respectFunctionProperties) {
523
+ this._object(fn);
524
+ }
525
+ },
526
+ _number: function(number){
527
+ return write('number:' + number.toString());
528
+ },
529
+ _xml: function(xml){
530
+ return write('xml:' + xml.toString());
531
+ },
532
+ _null: function() {
533
+ return write('Null');
534
+ },
535
+ _undefined: function() {
536
+ return write('Undefined');
537
+ },
538
+ _regexp: function(regex){
539
+ return write('regex:' + regex.toString());
540
+ },
541
+ _uint8array: function(arr){
542
+ write('uint8array:');
543
+ return this.dispatch(Array.prototype.slice.call(arr));
544
+ },
545
+ _uint8clampedarray: function(arr){
546
+ write('uint8clampedarray:');
547
+ return this.dispatch(Array.prototype.slice.call(arr));
548
+ },
549
+ _int8array: function(arr){
550
+ write('uint8array:');
551
+ return this.dispatch(Array.prototype.slice.call(arr));
552
+ },
553
+ _uint16array: function(arr){
554
+ write('uint16array:');
555
+ return this.dispatch(Array.prototype.slice.call(arr));
556
+ },
557
+ _int16array: function(arr){
558
+ write('uint16array:');
559
+ return this.dispatch(Array.prototype.slice.call(arr));
560
+ },
561
+ _uint32array: function(arr){
562
+ write('uint32array:');
563
+ return this.dispatch(Array.prototype.slice.call(arr));
564
+ },
565
+ _int32array: function(arr){
566
+ write('uint32array:');
567
+ return this.dispatch(Array.prototype.slice.call(arr));
568
+ },
569
+ _float32array: function(arr){
570
+ write('float32array:');
571
+ return this.dispatch(Array.prototype.slice.call(arr));
572
+ },
573
+ _float64array: function(arr){
574
+ write('float64array:');
575
+ return this.dispatch(Array.prototype.slice.call(arr));
576
+ },
577
+ _arraybuffer: function(arr){
578
+ write('arraybuffer:');
579
+ return this.dispatch(new Uint8Array(arr));
580
+ },
581
+ _url: function(url) {
582
+ return write('url:' + url.toString(), 'utf8');
583
+ },
584
+ _map: function(map) {
585
+ write('map:');
586
+ var arr = Array.from(map);
587
+ return this._array(arr, options.unorderedSets !== false);
588
+ },
589
+ _set: function(set) {
590
+ write('set:');
591
+ var arr = Array.from(set);
592
+ return this._array(arr, options.unorderedSets !== false);
593
+ },
594
+ _blob: function() {
595
+ if (options.ignoreUnknown) {
596
+ return write('[blob]');
597
+ }
598
+
599
+ throw Error('Hashing Blob objects is currently not supported\n' +
600
+ '(see https://github.com/puleos/object-hash/issues/26)\n' +
601
+ 'Use "options.replacer" or "options.ignoreUnknown"\n');
602
+ },
603
+ _domwindow: function() { return write('domwindow'); },
604
+ /* Node.js standard native objects */
605
+ _process: function() { return write('process'); },
606
+ _timer: function() { return write('timer'); },
607
+ _pipe: function() { return write('pipe'); },
608
+ _tcp: function() { return write('tcp'); },
609
+ _udp: function() { return write('udp'); },
610
+ _tty: function() { return write('tty'); },
611
+ _statwatcher: function() { return write('statwatcher'); },
612
+ _securecontext: function() { return write('securecontext'); },
613
+ _connection: function() { return write('connection'); },
614
+ _zlib: function() { return write('zlib'); },
615
+ _context: function() { return write('context'); },
616
+ _nodescript: function() { return write('nodescript'); },
617
+ _httpparser: function() { return write('httpparser'); },
618
+ _dataview: function() { return write('dataview'); },
619
+ _signal: function() { return write('signal'); },
620
+ _fsevent: function() { return write('fsevent'); },
621
+ _tlswrap: function() { return write('tlswrap'); }
622
+ };
623
+ }
624
+
625
+ // Mini-implementation of stream.PassThrough
626
+ // We are far from having need for the full implementation, and we can
627
+ // make assumptions like "many writes, then only one final read"
628
+ // and we can ignore encoding specifics
629
+ function PassThrough() {
630
+ return {
631
+ buf: '',
632
+
633
+ write: function(b) {
634
+ this.buf += b;
635
+ },
636
+
637
+ end: function(b) {
638
+ this.buf += b;
639
+ },
640
+
641
+ read: function() {
642
+ return this.buf;
643
+ }
644
+ };
645
+ }
646
+
647
+
648
+ /***/ }),
649
+
650
+ /***/ "crypto":
651
+ /*!*************************!*\
652
+ !*** external "crypto" ***!
653
+ \*************************/
654
+ /*! no static exports found */
655
+ /***/ (function(module, exports) {
656
+
657
+ module.exports = require("crypto");
658
+
111
659
  /***/ })
112
660
 
113
661
  /******/ });
@@ -1 +1 @@
1
- {"version":3,"sources":["webpack://dra-types/webpack/universalModuleDefinition","webpack://dra-types/webpack/bootstrap"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA","file":"dra-types.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"dra-types\"] = factory();\n\telse\n\t\troot[\"dra-types\"] = factory();\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/all.ts\");\n"],"sourceRoot":""}
1
+ {"version":3,"sources":["webpack://dra-types/webpack/universalModuleDefinition","webpack://dra-types/webpack/bootstrap","webpack://dra-types/./lib/all.ts","webpack://dra-types/./lib/dra-types.ts","webpack://dra-types/./node_modules/object-hash/index.js","webpack://dra-types/external \"crypto\""],"names":[],"mappings":"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AC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;AACvC,CAAC;AAXD,sCAWC;;;;;;;;;;;;;AC7HY;;AAEb,aAAa,mBAAO,CAAC,sBAAQ;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,YAAY;AACnC;AACA,uBAAuB,YAAY;AACnC;AACA,mCAAmC,YAAY;AAC/C,8BAA8B,YAAY;AAC1C,qBAAqB,YAAY;AACjC;AACA,yBAAyB,YAAY;AACrC,uBAAuB,YAAY;AACnC;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,YAAY,OAAO;AACnB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,WAAW,OAAO;AAClB,YAAY,OAAO;AACnB;AACA;AACA;AACA;AACA;AACA;AACA,6BAA6B,wDAAwD;AACrF;AACA;AACA,6BAA6B,kCAAkC;AAC/D;AACA;AACA,6BAA6B,uDAAuD;AACpF;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8EAA8E;AAC9E,2EAA2E;AAC3E;AACA;AACA,kFAAkF;AAClF,+EAA+E;AAC/E,qFAAqF;AACrF;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,mBAAmB;AACpC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,0CAA0C,sBAAsB;AAChE;AACA;;AAEA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA,OAAO;AACP,6BAA6B;AAC7B;;AAEA;;AAEA;;AAEA;AACA;AACA,OAAO;AACP;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAAS;AACT;AACA,SAAS;AACT;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,4CAA4C,kCAAkC,EAAE;AAChF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA,KAAK;AACL;AACA;AACA,0CAA0C;;AAE1C;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;;AAEA;AACA;AACA,eAAe,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2CAA2C;AAC3C;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL,4BAA4B,2BAA2B,EAAE;AACzD;AACA,0BAA0B,yBAAyB,EAAE;AACrD,wBAAwB,uBAAuB,EAAE;AACjD,uBAAuB,sBAAsB,EAAE;AAC/C,sBAAsB,qBAAqB,EAAE;AAC7C,sBAAsB,qBAAqB,EAAE;AAC7C,sBAAsB,qBAAqB,EAAE;AAC7C,8BAA8B,6BAA6B,EAAE;AAC7D,gCAAgC,+BAA+B,EAAE;AACjE,6BAA6B,4BAA4B,EAAE;AAC3D,uBAAuB,sBAAsB,EAAE;AAC/C,0BAA0B,yBAAyB,EAAE;AACrD,6BAA6B,4BAA4B,EAAE;AAC3D,6BAA6B,4BAA4B,EAAE;AAC3D,2BAA2B,0BAA0B,EAAE;AACvD,yBAAyB,wBAAwB,EAAE;AACnD,0BAA0B,yBAAyB,EAAE;AACrD,0BAA0B,yBAAyB;AACnD;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,KAAK;;AAEL;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC7bA,mC","file":"dra-types.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"dra-types\"] = factory();\n\telse\n\t\troot[\"dra-types\"] = factory();\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/all.ts\");\n","export * from './dra-types';\n","// Public libraries\nimport * as Hash from 'object-hash';\n\n// Type for single comment\nexport interface Comment\n{\n userid: string;\n text: string;\n date: string;\n recommend: number;\n}\n\n// Comment record associated with a map\nexport interface CommentList\n{\n id?: string;\n [commentid: string]: Comment | string; // Really just Comment but make TypeScript happy\n}\n\n// Supported like kinds\nexport type LikeKind = 'like' | 'love' | 'wow' | 'angry' | 'funny';\n\n// Like record for an individual like\nexport interface Like\n{\n date: string;\n kind: LikeKind;\n}\n\n// Record for likes associated with a map\nexport interface LikeList\n{\n id?: string;\n [userid: string]: Like | string; // Really just Like but make TypeScript happy\n}\n\n// Record for likes an individual user has performed\nexport interface UserLikes\n{\n id?: string;\n [aid: string]: Like | string; // Really just Like but make TypeScript happy\n}\n\nexport interface SplitBlock\n{\n id?: string;\n chunk?: string;\n state: string;\n datasource: string;\n geoid: string;\n blocks: string[];\n}\n\nexport type DistrictToSplitBlock = { [nDistrict: number]: SplitBlock[] };\n\n// Canonical hashing of splitblock data\nfunction hash(o: any): string\n{\n return Hash(o,\n { respectType: false,\n unorderedArrays: true,\n unorderedObjects: true,\n excludeKeys: (k: string) => (k === 'id' || k === 'chunk')\n });\n}\n\nexport function vgeoidToGeoid(vgeoid: string): string\n{\n let re = /vfeature_([^_]*)_.*/;\n let a = re.exec(vgeoid);\n if (a == null || a.length != 2)\n return '';\n else\n return a[1];\n}\n\nexport function vgeoidToChunk(vgeoid: string): string\n{\n // vgeoid is string of form: \"vfeature_[geoid]_[chunkid]_[hash]\"\n // the contents are chunked into a file of form \"vfeature_chunk_[chunkid]\"\n // So extract the chunk ID and download that.\n let re = /vfeature_([^_]*)_([^_*])_(.*)/;\n let a = re.exec(vgeoid);\n if (a && a.length == 4)\n vgeoid = `vfeature_chunk_${a[2]}`;\n else\n vgeoid = null;\n\n return vgeoid;\n}\n\nexport function isVfeature(geoid: string): boolean\n{\n return geoid.indexOf('vfeature') === 0;\n}\n\nexport function splitToCacheKey(s: SplitBlock): string\n{\n if (s.id === undefined)\n s.id = hash(s);\n if (s.chunk === undefined)\n s.chunk = \"0\";\n\n return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;\n}\n\nexport function splitToChunkKey(s: SplitBlock): string\n{\n if (s.chunk === undefined)\n s.chunk = \"0\";\n\n return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;\n}\n\nexport function splitToPrefix(s: SplitBlock): string\n{\n if (s.blocks === undefined)\n {\n let re = /_([^_]*)_(.*)_vfeature.*\\.geojson$/;\n let a = re.exec(s.id);\n if (a && a.length == 3)\n return `_${a[1]}_${a[2]}`;\n return s.id;\n }\n return `_${s.state}_${s.datasource}`;\n}\n","'use strict';\n\nvar crypto = require('crypto');\n\n/**\n * Exported function\n *\n * Options:\n *\n * - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'\n * - `excludeValues` {true|*false} hash object keys, values ignored\n * - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'\n * - `ignoreUnknown` {true|*false} ignore unknown object types\n * - `replacer` optional function that replaces values before hashing\n * - `respectFunctionProperties` {*true|false} consider function properties when hashing\n * - `respectFunctionNames` {*true|false} consider 'name' property of functions for hashing\n * - `respectType` {*true|false} Respect special properties (prototype, constructor)\n * when hashing to distinguish between types\n * - `unorderedArrays` {true|*false} Sort all arrays before hashing\n * - `unorderedSets` {*true|false} Sort `Set` and `Map` instances before hashing\n * * = default\n *\n * @param {object} object value to hash\n * @param {object} options hashing options\n * @return {string} hash value\n * @api public\n */\nexports = module.exports = objectHash;\n\nfunction objectHash(object, options){\n options = applyDefaults(object, options);\n\n return hash(object, options);\n}\n\n/**\n * Exported sugar methods\n *\n * @param {object} object value to hash\n * @return {string} hash value\n * @api public\n */\nexports.sha1 = function(object){\n return objectHash(object);\n};\nexports.keys = function(object){\n return objectHash(object, {excludeValues: true, algorithm: 'sha1', encoding: 'hex'});\n};\nexports.MD5 = function(object){\n return objectHash(object, {algorithm: 'md5', encoding: 'hex'});\n};\nexports.keysMD5 = function(object){\n return objectHash(object, {algorithm: 'md5', encoding: 'hex', excludeValues: true});\n};\n\n// Internals\nvar hashes = crypto.getHashes ? crypto.getHashes().slice() : ['sha1', 'md5'];\nhashes.push('passthrough');\nvar encodings = ['buffer', 'hex', 'binary', 'base64'];\n\nfunction applyDefaults(object, sourceOptions){\n sourceOptions = sourceOptions || {};\n\n // create a copy rather than mutating\n var options = {};\n options.algorithm = sourceOptions.algorithm || 'sha1';\n options.encoding = sourceOptions.encoding || 'hex';\n options.excludeValues = sourceOptions.excludeValues ? true : false;\n options.algorithm = options.algorithm.toLowerCase();\n options.encoding = options.encoding.toLowerCase();\n options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true; // default to false\n options.respectType = sourceOptions.respectType === false ? false : true; // default to true\n options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;\n options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;\n options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true; // default to false\n options.unorderedSets = sourceOptions.unorderedSets === false ? false : true; // default to false\n options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true; // default to true\n options.replacer = sourceOptions.replacer || undefined;\n options.excludeKeys = sourceOptions.excludeKeys || undefined;\n\n if(typeof object === 'undefined') {\n throw new Error('Object argument required.');\n }\n\n // if there is a case-insensitive match in the hashes list, accept it\n // (i.e. SHA256 for sha256)\n for (var i = 0; i < hashes.length; ++i) {\n if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {\n options.algorithm = hashes[i];\n }\n }\n\n if(hashes.indexOf(options.algorithm) === -1){\n throw new Error('Algorithm \"' + options.algorithm + '\" not supported. ' +\n 'supported values: ' + hashes.join(', '));\n }\n\n if(encodings.indexOf(options.encoding) === -1 &&\n options.algorithm !== 'passthrough'){\n throw new Error('Encoding \"' + options.encoding + '\" not supported. ' +\n 'supported values: ' + encodings.join(', '));\n }\n\n return options;\n}\n\n/** Check if the given function is a native function */\nfunction isNativeFunction(f) {\n if ((typeof f) !== 'function') {\n return false;\n }\n var exp = /^function\\s+\\w*\\s*\\(\\s*\\)\\s*{\\s+\\[native code\\]\\s+}$/i;\n return exp.exec(Function.prototype.toString.call(f)) != null;\n}\n\nfunction hash(object, options) {\n var hashingStream;\n\n if (options.algorithm !== 'passthrough') {\n hashingStream = crypto.createHash(options.algorithm);\n } else {\n hashingStream = new PassThrough();\n }\n\n if (typeof hashingStream.write === 'undefined') {\n hashingStream.write = hashingStream.update;\n hashingStream.end = hashingStream.update;\n }\n\n var hasher = typeHasher(options, hashingStream);\n hasher.dispatch(object);\n if (!hashingStream.update) {\n hashingStream.end('');\n }\n\n if (hashingStream.digest) {\n return hashingStream.digest(options.encoding === 'buffer' ? undefined : options.encoding);\n }\n\n var buf = hashingStream.read();\n if (options.encoding === 'buffer') {\n return buf;\n }\n\n return buf.toString(options.encoding);\n}\n\n/**\n * Expose streaming API\n *\n * @param {object} object Value to serialize\n * @param {object} options Options, as for hash()\n * @param {object} stream A stream to write the serializiation to\n * @api public\n */\nexports.writeToStream = function(object, options, stream) {\n if (typeof stream === 'undefined') {\n stream = options;\n options = {};\n }\n\n options = applyDefaults(object, options);\n\n return typeHasher(options, stream).dispatch(object);\n};\n\nfunction typeHasher(options, writeTo, context){\n context = context || [];\n var write = function(str) {\n if (writeTo.update) {\n return writeTo.update(str, 'utf8');\n } else {\n return writeTo.write(str, 'utf8');\n }\n };\n\n return {\n dispatch: function(value){\n if (options.replacer) {\n value = options.replacer(value);\n }\n\n var type = typeof value;\n if (value === null) {\n type = 'null';\n }\n\n //console.log(\"[DEBUG] Dispatch: \", value, \"->\", type, \" -> \", \"_\" + type);\n\n return this['_' + type](value);\n },\n _object: function(object) {\n var pattern = (/\\[object (.*)\\]/i);\n var objString = Object.prototype.toString.call(object);\n var objType = pattern.exec(objString);\n if (!objType) { // object type did not match [object ...]\n objType = 'unknown:[' + objString + ']';\n } else {\n objType = objType[1]; // take only the class name\n }\n\n objType = objType.toLowerCase();\n\n var objectNumber = null;\n\n if ((objectNumber = context.indexOf(object)) >= 0) {\n return this.dispatch('[CIRCULAR:' + objectNumber + ']');\n } else {\n context.push(object);\n }\n\n if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(object)) {\n write('buffer:');\n return write(object);\n }\n\n if(objType !== 'object' && objType !== 'function') {\n if(this['_' + objType]) {\n this['_' + objType](object);\n } else if (options.ignoreUnknown) {\n return write('[' + objType + ']');\n } else {\n throw new Error('Unknown object type \"' + objType + '\"');\n }\n }else{\n var keys = Object.keys(object);\n if (options.unorderedObjects) {\n keys = keys.sort();\n }\n // Make sure to incorporate special properties, so\n // Types with different prototypes will produce\n // a different hash and objects derived from\n // different functions (`new Foo`, `new Bar`) will\n // produce different hashes.\n // We never do this for native functions since some\n // seem to break because of that.\n if (options.respectType !== false && !isNativeFunction(object)) {\n keys.splice(0, 0, 'prototype', '__proto__', 'constructor');\n }\n\n if (options.excludeKeys) {\n keys = keys.filter(function(key) { return !options.excludeKeys(key); });\n }\n\n write('object:' + keys.length + ':');\n var self = this;\n return keys.forEach(function(key){\n self.dispatch(key);\n write(':');\n if(!options.excludeValues) {\n self.dispatch(object[key]);\n }\n write(',');\n });\n }\n },\n _array: function(arr, unordered){\n unordered = typeof unordered !== 'undefined' ? unordered :\n options.unorderedArrays !== false; // default to options.unorderedArrays\n\n var self = this;\n write('array:' + arr.length + ':');\n if (!unordered || arr.length <= 1) {\n return arr.forEach(function(entry) {\n return self.dispatch(entry);\n });\n }\n\n // the unordered case is a little more complicated:\n // since there is no canonical ordering on objects,\n // i.e. {a:1} < {a:2} and {a:1} > {a:2} are both false,\n // we first serialize each entry using a PassThrough stream\n // before sorting.\n // also: we can’t use the same context array for all entries\n // since the order of hashing should *not* matter. instead,\n // we keep track of the additions to a copy of the context array\n // and add all of them to the global context array when we’re done\n var contextAdditions = [];\n var entries = arr.map(function(entry) {\n var strm = new PassThrough();\n var localContext = context.slice(); // make copy\n var hasher = typeHasher(options, strm, localContext);\n hasher.dispatch(entry);\n // take only what was added to localContext and append it to contextAdditions\n contextAdditions = contextAdditions.concat(localContext.slice(context.length));\n return strm.read().toString();\n });\n context = context.concat(contextAdditions);\n entries.sort();\n return this._array(entries, false);\n },\n _date: function(date){\n return write('date:' + date.toJSON());\n },\n _symbol: function(sym){\n return write('symbol:' + sym.toString());\n },\n _error: function(err){\n return write('error:' + err.toString());\n },\n _boolean: function(bool){\n return write('bool:' + bool.toString());\n },\n _string: function(string){\n write('string:' + string.length + ':');\n write(string.toString());\n },\n _function: function(fn){\n write('fn:');\n if (isNativeFunction(fn)) {\n this.dispatch('[native]');\n } else {\n this.dispatch(fn.toString());\n }\n\n if (options.respectFunctionNames !== false) {\n // Make sure we can still distinguish native functions\n // by their name, otherwise String and Function will\n // have the same hash\n this.dispatch(\"function-name:\" + String(fn.name));\n }\n\n if (options.respectFunctionProperties) {\n this._object(fn);\n }\n },\n _number: function(number){\n return write('number:' + number.toString());\n },\n _xml: function(xml){\n return write('xml:' + xml.toString());\n },\n _null: function() {\n return write('Null');\n },\n _undefined: function() {\n return write('Undefined');\n },\n _regexp: function(regex){\n return write('regex:' + regex.toString());\n },\n _uint8array: function(arr){\n write('uint8array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _uint8clampedarray: function(arr){\n write('uint8clampedarray:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _int8array: function(arr){\n write('uint8array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _uint16array: function(arr){\n write('uint16array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _int16array: function(arr){\n write('uint16array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _uint32array: function(arr){\n write('uint32array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _int32array: function(arr){\n write('uint32array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _float32array: function(arr){\n write('float32array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _float64array: function(arr){\n write('float64array:');\n return this.dispatch(Array.prototype.slice.call(arr));\n },\n _arraybuffer: function(arr){\n write('arraybuffer:');\n return this.dispatch(new Uint8Array(arr));\n },\n _url: function(url) {\n return write('url:' + url.toString(), 'utf8');\n },\n _map: function(map) {\n write('map:');\n var arr = Array.from(map);\n return this._array(arr, options.unorderedSets !== false);\n },\n _set: function(set) {\n write('set:');\n var arr = Array.from(set);\n return this._array(arr, options.unorderedSets !== false);\n },\n _blob: function() {\n if (options.ignoreUnknown) {\n return write('[blob]');\n }\n\n throw Error('Hashing Blob objects is currently not supported\\n' +\n '(see https://github.com/puleos/object-hash/issues/26)\\n' +\n 'Use \"options.replacer\" or \"options.ignoreUnknown\"\\n');\n },\n _domwindow: function() { return write('domwindow'); },\n /* Node.js standard native objects */\n _process: function() { return write('process'); },\n _timer: function() { return write('timer'); },\n _pipe: function() { return write('pipe'); },\n _tcp: function() { return write('tcp'); },\n _udp: function() { return write('udp'); },\n _tty: function() { return write('tty'); },\n _statwatcher: function() { return write('statwatcher'); },\n _securecontext: function() { return write('securecontext'); },\n _connection: function() { return write('connection'); },\n _zlib: function() { return write('zlib'); },\n _context: function() { return write('context'); },\n _nodescript: function() { return write('nodescript'); },\n _httpparser: function() { return write('httpparser'); },\n _dataview: function() { return write('dataview'); },\n _signal: function() { return write('signal'); },\n _fsevent: function() { return write('fsevent'); },\n _tlswrap: function() { return write('tlswrap'); }\n };\n}\n\n// Mini-implementation of stream.PassThrough\n// We are far from having need for the full implementation, and we can\n// make assumptions like \"many writes, then only one final read\"\n// and we can ignore encoding specifics\nfunction PassThrough() {\n return {\n buf: '',\n\n write: function(b) {\n this.buf += b;\n },\n\n end: function(b) {\n this.buf += b;\n },\n\n read: function() {\n return this.buf;\n }\n };\n}\n","module.exports = require(\"crypto\");"],"sourceRoot":""}
package/lib/dra-types.ts CHANGED
@@ -1,3 +1,6 @@
1
+ // Public libraries
2
+ import * as Hash from 'object-hash';
3
+
1
4
  // Type for single comment
2
5
  export interface Comment
3
6
  {
@@ -41,6 +44,7 @@ export interface UserLikes
41
44
  export interface SplitBlock
42
45
  {
43
46
  id?: string;
47
+ chunk?: string;
44
48
  state: string;
45
49
  datasource: string;
46
50
  geoid: string;
@@ -48,3 +52,75 @@ export interface SplitBlock
48
52
  }
49
53
 
50
54
  export type DistrictToSplitBlock = { [nDistrict: number]: SplitBlock[] };
55
+
56
+ // Canonical hashing of splitblock data
57
+ function hash(o: any): string
58
+ {
59
+ return Hash(o,
60
+ { respectType: false,
61
+ unorderedArrays: true,
62
+ unorderedObjects: true,
63
+ excludeKeys: (k: string) => (k === 'id' || k === 'chunk')
64
+ });
65
+ }
66
+
67
+ export function vgeoidToGeoid(vgeoid: string): string
68
+ {
69
+ let re = /vfeature_([^_]*)_.*/;
70
+ let a = re.exec(vgeoid);
71
+ if (a == null || a.length != 2)
72
+ return '';
73
+ else
74
+ return a[1];
75
+ }
76
+
77
+ export function vgeoidToChunk(vgeoid: string): string
78
+ {
79
+ // vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
80
+ // the contents are chunked into a file of form "vfeature_chunk_[chunkid]"
81
+ // So extract the chunk ID and download that.
82
+ let re = /vfeature_([^_]*)_([^_*])_(.*)/;
83
+ let a = re.exec(vgeoid);
84
+ if (a && a.length == 4)
85
+ vgeoid = `vfeature_chunk_${a[2]}`;
86
+ else
87
+ vgeoid = null;
88
+
89
+ return vgeoid;
90
+ }
91
+
92
+ export function isVfeature(geoid: string): boolean
93
+ {
94
+ return geoid.indexOf('vfeature') === 0;
95
+ }
96
+
97
+ export function splitToCacheKey(s: SplitBlock): string
98
+ {
99
+ if (s.id === undefined)
100
+ s.id = hash(s);
101
+ if (s.chunk === undefined)
102
+ s.chunk = "0";
103
+
104
+ return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;
105
+ }
106
+
107
+ export function splitToChunkKey(s: SplitBlock): string
108
+ {
109
+ if (s.chunk === undefined)
110
+ s.chunk = "0";
111
+
112
+ return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;
113
+ }
114
+
115
+ export function splitToPrefix(s: SplitBlock): string
116
+ {
117
+ if (s.blocks === undefined)
118
+ {
119
+ let re = /_([^_]*)_(.*)_vfeature.*\.geojson$/;
120
+ let a = re.exec(s.id);
121
+ if (a && a.length == 3)
122
+ return `_${a[1]}_${a[2]}`;
123
+ return s.id;
124
+ }
125
+ return `_${s.state}_${s.datasource}`;
126
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/dra-types",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
4
4
  "description": "Shared types used between client and server.",
5
5
  "main": "dist/dra-types.js",
6
6
  "types": "./dist/all.d.ts",
@@ -24,6 +24,7 @@
24
24
  "homepage": "https://github.com/dra2020/dra-types#readme",
25
25
  "devDependencies": {
26
26
  "@types/node": "12.7.2",
27
+ "@types/object-hash": "^1.3.0",
27
28
  "source-map-loader": "^0.2.4",
28
29
  "ts-loader": "^6.1.2",
29
30
  "tsify": "^4.0.1",
@@ -31,5 +32,7 @@
31
32
  "webpack": "^4.40.2",
32
33
  "webpack-cli": "^3.3.9"
33
34
  },
34
- "dependencies": {}
35
+ "dependencies": {
36
+ "object-hash": "^2.0.0"
37
+ }
35
38
  }