@dra2020/dra-types 1.0.7 → 1.0.10

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.
@@ -32,3 +32,10 @@ export interface SplitBlock {
32
32
  export declare type DistrictToSplitBlock = {
33
33
  [nDistrict: number]: SplitBlock[];
34
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;
41
+ export declare function cacheKeysToChunkHash(keys: string[]): string;
package/dist/dra-types.js CHANGED
@@ -105,9 +105,561 @@ 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
+ function cacheKeysToChunkHash(keys) {
189
+ return hash(keys);
190
+ }
191
+ exports.cacheKeysToChunkHash = cacheKeysToChunkHash;
192
+
193
+
194
+ /***/ }),
195
+
196
+ /***/ "./node_modules/object-hash/index.js":
197
+ /*!*******************************************!*\
198
+ !*** ./node_modules/object-hash/index.js ***!
199
+ \*******************************************/
200
+ /*! no static exports found */
201
+ /***/ (function(module, exports, __webpack_require__) {
202
+
203
+ "use strict";
204
+
205
+
206
+ var crypto = __webpack_require__(/*! crypto */ "crypto");
207
+
208
+ /**
209
+ * Exported function
210
+ *
211
+ * Options:
212
+ *
213
+ * - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'
214
+ * - `excludeValues` {true|*false} hash object keys, values ignored
215
+ * - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'
216
+ * - `ignoreUnknown` {true|*false} ignore unknown object types
217
+ * - `replacer` optional function that replaces values before hashing
218
+ * - `respectFunctionProperties` {*true|false} consider function properties when hashing
219
+ * - `respectFunctionNames` {*true|false} consider 'name' property of functions for hashing
220
+ * - `respectType` {*true|false} Respect special properties (prototype, constructor)
221
+ * when hashing to distinguish between types
222
+ * - `unorderedArrays` {true|*false} Sort all arrays before hashing
223
+ * - `unorderedSets` {*true|false} Sort `Set` and `Map` instances before hashing
224
+ * * = default
225
+ *
226
+ * @param {object} object value to hash
227
+ * @param {object} options hashing options
228
+ * @return {string} hash value
229
+ * @api public
230
+ */
231
+ exports = module.exports = objectHash;
232
+
233
+ function objectHash(object, options){
234
+ options = applyDefaults(object, options);
235
+
236
+ return hash(object, options);
237
+ }
238
+
239
+ /**
240
+ * Exported sugar methods
241
+ *
242
+ * @param {object} object value to hash
243
+ * @return {string} hash value
244
+ * @api public
245
+ */
246
+ exports.sha1 = function(object){
247
+ return objectHash(object);
248
+ };
249
+ exports.keys = function(object){
250
+ return objectHash(object, {excludeValues: true, algorithm: 'sha1', encoding: 'hex'});
251
+ };
252
+ exports.MD5 = function(object){
253
+ return objectHash(object, {algorithm: 'md5', encoding: 'hex'});
254
+ };
255
+ exports.keysMD5 = function(object){
256
+ return objectHash(object, {algorithm: 'md5', encoding: 'hex', excludeValues: true});
257
+ };
258
+
259
+ // Internals
260
+ var hashes = crypto.getHashes ? crypto.getHashes().slice() : ['sha1', 'md5'];
261
+ hashes.push('passthrough');
262
+ var encodings = ['buffer', 'hex', 'binary', 'base64'];
263
+
264
+ function applyDefaults(object, sourceOptions){
265
+ sourceOptions = sourceOptions || {};
266
+
267
+ // create a copy rather than mutating
268
+ var options = {};
269
+ options.algorithm = sourceOptions.algorithm || 'sha1';
270
+ options.encoding = sourceOptions.encoding || 'hex';
271
+ options.excludeValues = sourceOptions.excludeValues ? true : false;
272
+ options.algorithm = options.algorithm.toLowerCase();
273
+ options.encoding = options.encoding.toLowerCase();
274
+ options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true; // default to false
275
+ options.respectType = sourceOptions.respectType === false ? false : true; // default to true
276
+ options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
277
+ options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
278
+ options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true; // default to false
279
+ options.unorderedSets = sourceOptions.unorderedSets === false ? false : true; // default to false
280
+ options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true; // default to true
281
+ options.replacer = sourceOptions.replacer || undefined;
282
+ options.excludeKeys = sourceOptions.excludeKeys || undefined;
283
+
284
+ if(typeof object === 'undefined') {
285
+ throw new Error('Object argument required.');
286
+ }
287
+
288
+ // if there is a case-insensitive match in the hashes list, accept it
289
+ // (i.e. SHA256 for sha256)
290
+ for (var i = 0; i < hashes.length; ++i) {
291
+ if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
292
+ options.algorithm = hashes[i];
293
+ }
294
+ }
295
+
296
+ if(hashes.indexOf(options.algorithm) === -1){
297
+ throw new Error('Algorithm "' + options.algorithm + '" not supported. ' +
298
+ 'supported values: ' + hashes.join(', '));
299
+ }
300
+
301
+ if(encodings.indexOf(options.encoding) === -1 &&
302
+ options.algorithm !== 'passthrough'){
303
+ throw new Error('Encoding "' + options.encoding + '" not supported. ' +
304
+ 'supported values: ' + encodings.join(', '));
305
+ }
306
+
307
+ return options;
308
+ }
309
+
310
+ /** Check if the given function is a native function */
311
+ function isNativeFunction(f) {
312
+ if ((typeof f) !== 'function') {
313
+ return false;
314
+ }
315
+ var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
316
+ return exp.exec(Function.prototype.toString.call(f)) != null;
317
+ }
318
+
319
+ function hash(object, options) {
320
+ var hashingStream;
321
+
322
+ if (options.algorithm !== 'passthrough') {
323
+ hashingStream = crypto.createHash(options.algorithm);
324
+ } else {
325
+ hashingStream = new PassThrough();
326
+ }
327
+
328
+ if (typeof hashingStream.write === 'undefined') {
329
+ hashingStream.write = hashingStream.update;
330
+ hashingStream.end = hashingStream.update;
331
+ }
332
+
333
+ var hasher = typeHasher(options, hashingStream);
334
+ hasher.dispatch(object);
335
+ if (!hashingStream.update) {
336
+ hashingStream.end('');
337
+ }
338
+
339
+ if (hashingStream.digest) {
340
+ return hashingStream.digest(options.encoding === 'buffer' ? undefined : options.encoding);
341
+ }
342
+
343
+ var buf = hashingStream.read();
344
+ if (options.encoding === 'buffer') {
345
+ return buf;
346
+ }
347
+
348
+ return buf.toString(options.encoding);
349
+ }
350
+
351
+ /**
352
+ * Expose streaming API
353
+ *
354
+ * @param {object} object Value to serialize
355
+ * @param {object} options Options, as for hash()
356
+ * @param {object} stream A stream to write the serializiation to
357
+ * @api public
358
+ */
359
+ exports.writeToStream = function(object, options, stream) {
360
+ if (typeof stream === 'undefined') {
361
+ stream = options;
362
+ options = {};
363
+ }
364
+
365
+ options = applyDefaults(object, options);
366
+
367
+ return typeHasher(options, stream).dispatch(object);
368
+ };
369
+
370
+ function typeHasher(options, writeTo, context){
371
+ context = context || [];
372
+ var write = function(str) {
373
+ if (writeTo.update) {
374
+ return writeTo.update(str, 'utf8');
375
+ } else {
376
+ return writeTo.write(str, 'utf8');
377
+ }
378
+ };
379
+
380
+ return {
381
+ dispatch: function(value){
382
+ if (options.replacer) {
383
+ value = options.replacer(value);
384
+ }
385
+
386
+ var type = typeof value;
387
+ if (value === null) {
388
+ type = 'null';
389
+ }
390
+
391
+ //console.log("[DEBUG] Dispatch: ", value, "->", type, " -> ", "_" + type);
392
+
393
+ return this['_' + type](value);
394
+ },
395
+ _object: function(object) {
396
+ var pattern = (/\[object (.*)\]/i);
397
+ var objString = Object.prototype.toString.call(object);
398
+ var objType = pattern.exec(objString);
399
+ if (!objType) { // object type did not match [object ...]
400
+ objType = 'unknown:[' + objString + ']';
401
+ } else {
402
+ objType = objType[1]; // take only the class name
403
+ }
404
+
405
+ objType = objType.toLowerCase();
406
+
407
+ var objectNumber = null;
408
+
409
+ if ((objectNumber = context.indexOf(object)) >= 0) {
410
+ return this.dispatch('[CIRCULAR:' + objectNumber + ']');
411
+ } else {
412
+ context.push(object);
413
+ }
414
+
415
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(object)) {
416
+ write('buffer:');
417
+ return write(object);
418
+ }
419
+
420
+ if(objType !== 'object' && objType !== 'function') {
421
+ if(this['_' + objType]) {
422
+ this['_' + objType](object);
423
+ } else if (options.ignoreUnknown) {
424
+ return write('[' + objType + ']');
425
+ } else {
426
+ throw new Error('Unknown object type "' + objType + '"');
427
+ }
428
+ }else{
429
+ var keys = Object.keys(object);
430
+ if (options.unorderedObjects) {
431
+ keys = keys.sort();
432
+ }
433
+ // Make sure to incorporate special properties, so
434
+ // Types with different prototypes will produce
435
+ // a different hash and objects derived from
436
+ // different functions (`new Foo`, `new Bar`) will
437
+ // produce different hashes.
438
+ // We never do this for native functions since some
439
+ // seem to break because of that.
440
+ if (options.respectType !== false && !isNativeFunction(object)) {
441
+ keys.splice(0, 0, 'prototype', '__proto__', 'constructor');
442
+ }
443
+
444
+ if (options.excludeKeys) {
445
+ keys = keys.filter(function(key) { return !options.excludeKeys(key); });
446
+ }
447
+
448
+ write('object:' + keys.length + ':');
449
+ var self = this;
450
+ return keys.forEach(function(key){
451
+ self.dispatch(key);
452
+ write(':');
453
+ if(!options.excludeValues) {
454
+ self.dispatch(object[key]);
455
+ }
456
+ write(',');
457
+ });
458
+ }
459
+ },
460
+ _array: function(arr, unordered){
461
+ unordered = typeof unordered !== 'undefined' ? unordered :
462
+ options.unorderedArrays !== false; // default to options.unorderedArrays
463
+
464
+ var self = this;
465
+ write('array:' + arr.length + ':');
466
+ if (!unordered || arr.length <= 1) {
467
+ return arr.forEach(function(entry) {
468
+ return self.dispatch(entry);
469
+ });
470
+ }
471
+
472
+ // the unordered case is a little more complicated:
473
+ // since there is no canonical ordering on objects,
474
+ // i.e. {a:1} < {a:2} and {a:1} > {a:2} are both false,
475
+ // we first serialize each entry using a PassThrough stream
476
+ // before sorting.
477
+ // also: we can’t use the same context array for all entries
478
+ // since the order of hashing should *not* matter. instead,
479
+ // we keep track of the additions to a copy of the context array
480
+ // and add all of them to the global context array when we’re done
481
+ var contextAdditions = [];
482
+ var entries = arr.map(function(entry) {
483
+ var strm = new PassThrough();
484
+ var localContext = context.slice(); // make copy
485
+ var hasher = typeHasher(options, strm, localContext);
486
+ hasher.dispatch(entry);
487
+ // take only what was added to localContext and append it to contextAdditions
488
+ contextAdditions = contextAdditions.concat(localContext.slice(context.length));
489
+ return strm.read().toString();
490
+ });
491
+ context = context.concat(contextAdditions);
492
+ entries.sort();
493
+ return this._array(entries, false);
494
+ },
495
+ _date: function(date){
496
+ return write('date:' + date.toJSON());
497
+ },
498
+ _symbol: function(sym){
499
+ return write('symbol:' + sym.toString());
500
+ },
501
+ _error: function(err){
502
+ return write('error:' + err.toString());
503
+ },
504
+ _boolean: function(bool){
505
+ return write('bool:' + bool.toString());
506
+ },
507
+ _string: function(string){
508
+ write('string:' + string.length + ':');
509
+ write(string.toString());
510
+ },
511
+ _function: function(fn){
512
+ write('fn:');
513
+ if (isNativeFunction(fn)) {
514
+ this.dispatch('[native]');
515
+ } else {
516
+ this.dispatch(fn.toString());
517
+ }
518
+
519
+ if (options.respectFunctionNames !== false) {
520
+ // Make sure we can still distinguish native functions
521
+ // by their name, otherwise String and Function will
522
+ // have the same hash
523
+ this.dispatch("function-name:" + String(fn.name));
524
+ }
525
+
526
+ if (options.respectFunctionProperties) {
527
+ this._object(fn);
528
+ }
529
+ },
530
+ _number: function(number){
531
+ return write('number:' + number.toString());
532
+ },
533
+ _xml: function(xml){
534
+ return write('xml:' + xml.toString());
535
+ },
536
+ _null: function() {
537
+ return write('Null');
538
+ },
539
+ _undefined: function() {
540
+ return write('Undefined');
541
+ },
542
+ _regexp: function(regex){
543
+ return write('regex:' + regex.toString());
544
+ },
545
+ _uint8array: function(arr){
546
+ write('uint8array:');
547
+ return this.dispatch(Array.prototype.slice.call(arr));
548
+ },
549
+ _uint8clampedarray: function(arr){
550
+ write('uint8clampedarray:');
551
+ return this.dispatch(Array.prototype.slice.call(arr));
552
+ },
553
+ _int8array: function(arr){
554
+ write('uint8array:');
555
+ return this.dispatch(Array.prototype.slice.call(arr));
556
+ },
557
+ _uint16array: function(arr){
558
+ write('uint16array:');
559
+ return this.dispatch(Array.prototype.slice.call(arr));
560
+ },
561
+ _int16array: function(arr){
562
+ write('uint16array:');
563
+ return this.dispatch(Array.prototype.slice.call(arr));
564
+ },
565
+ _uint32array: function(arr){
566
+ write('uint32array:');
567
+ return this.dispatch(Array.prototype.slice.call(arr));
568
+ },
569
+ _int32array: function(arr){
570
+ write('uint32array:');
571
+ return this.dispatch(Array.prototype.slice.call(arr));
572
+ },
573
+ _float32array: function(arr){
574
+ write('float32array:');
575
+ return this.dispatch(Array.prototype.slice.call(arr));
576
+ },
577
+ _float64array: function(arr){
578
+ write('float64array:');
579
+ return this.dispatch(Array.prototype.slice.call(arr));
580
+ },
581
+ _arraybuffer: function(arr){
582
+ write('arraybuffer:');
583
+ return this.dispatch(new Uint8Array(arr));
584
+ },
585
+ _url: function(url) {
586
+ return write('url:' + url.toString(), 'utf8');
587
+ },
588
+ _map: function(map) {
589
+ write('map:');
590
+ var arr = Array.from(map);
591
+ return this._array(arr, options.unorderedSets !== false);
592
+ },
593
+ _set: function(set) {
594
+ write('set:');
595
+ var arr = Array.from(set);
596
+ return this._array(arr, options.unorderedSets !== false);
597
+ },
598
+ _blob: function() {
599
+ if (options.ignoreUnknown) {
600
+ return write('[blob]');
601
+ }
602
+
603
+ throw Error('Hashing Blob objects is currently not supported\n' +
604
+ '(see https://github.com/puleos/object-hash/issues/26)\n' +
605
+ 'Use "options.replacer" or "options.ignoreUnknown"\n');
606
+ },
607
+ _domwindow: function() { return write('domwindow'); },
608
+ /* Node.js standard native objects */
609
+ _process: function() { return write('process'); },
610
+ _timer: function() { return write('timer'); },
611
+ _pipe: function() { return write('pipe'); },
612
+ _tcp: function() { return write('tcp'); },
613
+ _udp: function() { return write('udp'); },
614
+ _tty: function() { return write('tty'); },
615
+ _statwatcher: function() { return write('statwatcher'); },
616
+ _securecontext: function() { return write('securecontext'); },
617
+ _connection: function() { return write('connection'); },
618
+ _zlib: function() { return write('zlib'); },
619
+ _context: function() { return write('context'); },
620
+ _nodescript: function() { return write('nodescript'); },
621
+ _httpparser: function() { return write('httpparser'); },
622
+ _dataview: function() { return write('dataview'); },
623
+ _signal: function() { return write('signal'); },
624
+ _fsevent: function() { return write('fsevent'); },
625
+ _tlswrap: function() { return write('tlswrap'); }
626
+ };
627
+ }
628
+
629
+ // Mini-implementation of stream.PassThrough
630
+ // We are far from having need for the full implementation, and we can
631
+ // make assumptions like "many writes, then only one final read"
632
+ // and we can ignore encoding specifics
633
+ function PassThrough() {
634
+ return {
635
+ buf: '',
636
+
637
+ write: function(b) {
638
+ this.buf += b;
639
+ },
640
+
641
+ end: function(b) {
642
+ this.buf += b;
643
+ },
644
+
645
+ read: function() {
646
+ return this.buf;
647
+ }
648
+ };
649
+ }
650
+
651
+
652
+ /***/ }),
653
+
654
+ /***/ "crypto":
655
+ /*!*************************!*\
656
+ !*** external "crypto" ***!
657
+ \*************************/
658
+ /*! no static exports found */
659
+ /***/ (function(module, exports) {
660
+
661
+ module.exports = require("crypto");
662
+
111
663
  /***/ })
112
664
 
113
665
  /******/ });
@@ -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;AAED,SAAgB,oBAAoB,CAAC,IAAc;IAEjD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC;AAHD,oDAGC;;;;;;;;;;;;;AClIY;;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\nexport function cacheKeysToChunkHash(keys: string[]): string\n{\n return hash(keys);\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
  {
@@ -49,3 +52,80 @@ export interface SplitBlock
49
52
  }
50
53
 
51
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
+ }
127
+
128
+ export function cacheKeysToChunkHash(keys: string[]): string
129
+ {
130
+ return hash(keys);
131
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/dra-types",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
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
  }