@hastehaul/common 3.8.0 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,13 +10,14 @@ export declare function generateIdentifier(messageContent: string): string;
10
10
  export declare function getValueFromSettings(settings: Setting[], key: string, envVar?: string, defaultValue?: any): any;
11
11
  export declare function loadAsset(relativePath: string): Promise<string | null>;
12
12
  export declare function loadAssetStream(relativePath: string): Promise<any>;
13
- export declare function isPointInGeoJSON(latLng: number[], fileName: string): Promise<{
13
+ export declare function isPointInGeoJSON(latLng: number[], cachedGeoJsonData: {
14
+ features: any;
15
+ }): Promise<{
14
16
  isInside: boolean;
15
17
  properties: any;
16
18
  } | {
17
19
  isInside: null;
18
20
  properties: null;
19
21
  }>;
20
- export declare function clearGeoJsonCache(): void;
21
22
  export declare function generateCode<T extends Document>(model: Model<T>, filterProperty: keyof T): Promise<string>;
22
23
  export {};
@@ -20,7 +20,6 @@ exports.getValueFromSettings = getValueFromSettings;
20
20
  exports.loadAsset = loadAsset;
21
21
  exports.loadAssetStream = loadAssetStream;
22
22
  exports.isPointInGeoJSON = isPointInGeoJSON;
23
- exports.clearGeoJsonCache = clearGeoJsonCache;
24
23
  exports.generateCode = generateCode;
25
24
  const fs_1 = __importDefault(require("fs"));
26
25
  const boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon"));
@@ -89,18 +88,11 @@ function loadAssetStream(relativePath) {
89
88
  });
90
89
  });
91
90
  }
92
- let cachedGeoJsonData = null;
93
- function isPointInGeoJSON(latLng, fileName) {
91
+ function isPointInGeoJSON(latLng, cachedGeoJsonData) {
94
92
  return __awaiter(this, void 0, void 0, function* () {
95
93
  try {
96
94
  if (!latLng || latLng.length === 0)
97
95
  return { isInside: false, properties: null };
98
- // Load and parse GeoJSON data only if not already cached
99
- if (!cachedGeoJsonData) {
100
- cachedGeoJsonData = yield loadAssetStream(fileName);
101
- console.log(cachedGeoJsonData);
102
- // cachedGeoJsonData = JSON.parse(geoJsonData!);
103
- }
104
96
  // !NB points take the form longitude, latitude
105
97
  const points = (0, helpers_1.point)([latLng[1], latLng[0]]);
106
98
  for (const feature of cachedGeoJsonData.features) {
@@ -134,9 +126,6 @@ function isPointInGeoJSON(latLng, fileName) {
134
126
  }
135
127
  });
136
128
  }
137
- function clearGeoJsonCache() {
138
- cachedGeoJsonData = null;
139
- }
140
129
  function generateCode(model, filterProperty) {
141
130
  return __awaiter(this, void 0, void 0, function* () {
142
131
  const batchSize = 10;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",