@dra2020/dra-types 1.0.8 → 1.0.11

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.
@@ -35,3 +35,7 @@ export declare type DistrictToSplitBlock = {
35
35
  export declare function vgeoidToGeoid(vgeoid: string): string;
36
36
  export declare function vgeoidToChunk(vgeoid: string): string;
37
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
@@ -124,6 +124,16 @@ __export(__webpack_require__(/*! ./dra-types */ "./lib/dra-types.ts"));
124
124
  "use strict";
125
125
 
126
126
  Object.defineProperty(exports, "__esModule", { value: true });
127
+ // Public libraries
128
+ const Hash = __webpack_require__(/*! object-hash */ "object-hash");
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
+ }
127
137
  function vgeoidToGeoid(vgeoid) {
128
138
  let re = /vfeature_([^_]*)_.*/;
129
139
  let a = re.exec(vgeoid);
@@ -150,7 +160,47 @@ function isVfeature(geoid) {
150
160
  return geoid.indexOf('vfeature') === 0;
151
161
  }
152
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
+ /***/ "object-hash":
197
+ /*!******************************!*\
198
+ !*** external "object-hash" ***!
199
+ \******************************/
200
+ /*! no static exports found */
201
+ /***/ (function(module, exports) {
153
202
 
203
+ module.exports = require("object-hash");
154
204
 
155
205
  /***/ })
156
206
 
@@ -1 +1 @@
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"],"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;;;;;;;;;;;;;;;;;;AClFA,uEAA4B;;;;;;;;;;;;;;;ACoD5B,SAAgB,aAAa,CAAC,MAAc;IAE1C,IAAI,EAAE,GAAG,qBAAqB,CAAC;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC;QAC5B,OAAO,EAAE,CAAC;;QAEV,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAChB,CAAC;AARD,sCAQC;AAED,SAAgB,aAAa,CAAC,MAAc;IAE1C,gEAAgE;IAChE,0EAA0E;IAC1E,6CAA6C;IAC7C,IAAI,EAAE,GAAG,+BAA+B,CAAC;IACzC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxB,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC;QACpB,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;;QAElC,MAAM,GAAG,IAAI,CAAC;IAEhB,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,sCAaC;AAED,SAAgB,UAAU,CAAC,KAAa;IAEtC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAHD,gCAGC","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","// 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\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"],"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/external \"object-hash\""],"names":[],"mappings":"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","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","module.exports = require(\"object-hash\");"],"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
  {
@@ -50,6 +53,17 @@ export interface SplitBlock
50
53
 
51
54
  export type DistrictToSplitBlock = { [nDistrict: number]: SplitBlock[] };
52
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
+
53
67
  export function vgeoidToGeoid(vgeoid: string): string
54
68
  {
55
69
  let re = /vfeature_([^_]*)_.*/;
@@ -79,3 +93,39 @@ export function isVfeature(geoid: string): boolean
79
93
  {
80
94
  return geoid.indexOf('vfeature') === 0;
81
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.8",
3
+ "version": "1.0.11",
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
  }
package/webpack.config.js CHANGED
@@ -1,3 +1,15 @@
1
+ var path = require('path');
2
+ var fs = require('fs');
3
+
4
+ var nodeModules = {};
5
+ fs.readdirSync('node_modules')
6
+ .filter(function(x) {
7
+ return ['.bin'].indexOf(x) === -1;
8
+ })
9
+ .forEach(function(mod) {
10
+ nodeModules[mod] = 'commonjs ' + mod;
11
+ });
12
+
1
13
  var libConfig = {
2
14
  entry: {
3
15
  library: './lib/all.ts'
@@ -14,9 +26,7 @@ var libConfig = {
14
26
  // Enable source maps
15
27
  devtool: "source-map",
16
28
 
17
- externals: {
18
- },
19
-
29
+ externals: nodeModules,
20
30
 
21
31
  module: {
22
32
  rules: [