@servicetitan/acquisition-functions 0.5.0 → 0.6.0
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.
- package/dist/__tests__/filter-fetcher.test.js +1 -7
- package/dist/__tests__/property-fix-use-group.test.js +0 -1
- package/dist/__tests__/setup.js +1 -30
- package/dist/filter-fetcher/index.js +20 -2
- package/dist/fix-property-use/index.js +13 -2
- package/dist/index.js +21 -8
- package/dist/property-assessorlastsaledate-converter/index.js +1 -0
- package/dist/zip-processor.js +2 -2
- package/package.json +3 -3
|
@@ -10,15 +10,9 @@ describe('property-assessorlastsaledate-converter', () => {
|
|
|
10
10
|
const client = await (0, setup_1.openConnection)();
|
|
11
11
|
base = client.db('test');
|
|
12
12
|
await (0, setup_1.setupProperties)(base);
|
|
13
|
-
const { filterFetcher } = (0, index_1.configureProcessor)({
|
|
13
|
+
const { filterFetcher, propertyUseGroupProcessor } = (0, index_1.configureProcessor)({
|
|
14
14
|
workers: 10,
|
|
15
15
|
mongoDb: base,
|
|
16
|
-
fetchProperties: (0, setup_1.getFetchPropertiesForFilters)(base),
|
|
17
|
-
});
|
|
18
|
-
const { propertyUseGroupProcessor } = (0, index_1.configureProcessor)({
|
|
19
|
-
workers: 10,
|
|
20
|
-
mongoDb: base,
|
|
21
|
-
fetchProperties: (0, setup_1.getFetchPropertiesForFix)(base),
|
|
22
16
|
});
|
|
23
17
|
await propertyUseGroupProcessor.start(['90001', '90002']);
|
|
24
18
|
metadata = await filterFetcher.start(['90001', '90002']);
|
|
@@ -17,7 +17,6 @@ describe('property-use-group-converter', () => {
|
|
|
17
17
|
processor = (0, index_1.configureProcessor)({
|
|
18
18
|
workers: 1,
|
|
19
19
|
mongoDb: base,
|
|
20
|
-
fetchProperties: (0, setup_1.getFetchPropertiesForFix)(base),
|
|
21
20
|
});
|
|
22
21
|
const { propertyUseGroupProcessor } = processor;
|
|
23
22
|
metadata = await propertyUseGroupProcessor.start('90001');
|
package/dist/__tests__/setup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.closeConnection = exports.openConnection = exports.setupProperties = void 0;
|
|
4
4
|
const mongodb_1 = require("mongodb");
|
|
5
5
|
const mock_1 = require("./mock");
|
|
6
6
|
async function setupProperties(base) {
|
|
@@ -39,32 +39,3 @@ const openConnection = async () => {
|
|
|
39
39
|
exports.openConnection = openConnection;
|
|
40
40
|
const closeConnection = () => connectedMongoClient?.close();
|
|
41
41
|
exports.closeConnection = closeConnection;
|
|
42
|
-
const getFetchPropertiesForFilters = (base) => async (zip) => {
|
|
43
|
-
return base
|
|
44
|
-
.collection('properties')
|
|
45
|
-
.find({ zipcode: zip }, {
|
|
46
|
-
projection: {
|
|
47
|
-
zipcode: 1,
|
|
48
|
-
propertyusegroup: 1,
|
|
49
|
-
propertyusestandardized: 1,
|
|
50
|
-
hvaccoolingdetail: 1,
|
|
51
|
-
hvacheatingdetail: 1,
|
|
52
|
-
utilitieswatersource: 1,
|
|
53
|
-
flooringmaterialprimary: 1,
|
|
54
|
-
_id: 0, // eslint-disable-line
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
.toArray();
|
|
58
|
-
};
|
|
59
|
-
exports.getFetchPropertiesForFilters = getFetchPropertiesForFilters;
|
|
60
|
-
const getFetchPropertiesForFix = (base) => async (zip) => {
|
|
61
|
-
return base
|
|
62
|
-
.collection('properties')
|
|
63
|
-
.find({ zipcode: zip }, {
|
|
64
|
-
projection: {
|
|
65
|
-
propertyusegroup: 1,
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
.toArray();
|
|
69
|
-
};
|
|
70
|
-
exports.getFetchPropertiesForFix = getFetchPropertiesForFix;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFilterFetcherProcessor = void 0;
|
|
4
4
|
const calc_filter_count_1 = require("./calc-filter-count");
|
|
5
|
-
function getFilterFetcherProcessor(
|
|
5
|
+
function getFilterFetcherProcessor(db) {
|
|
6
6
|
const getFiltersCollection = async () => {
|
|
7
7
|
return db.collection('filters');
|
|
8
8
|
};
|
|
@@ -22,6 +22,23 @@ function getFilterFetcherProcessor({ mongoDb: db, fetchProperties }) {
|
|
|
22
22
|
flooringmaterialprimary: flooringmaterialprimaryCounts,
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
+
const getProperties = (zip) => {
|
|
26
|
+
return db
|
|
27
|
+
.collection('properties')
|
|
28
|
+
.find({ zipcode: zip }, {
|
|
29
|
+
projection: {
|
|
30
|
+
zipcode: 1,
|
|
31
|
+
propertyusegroup: 1,
|
|
32
|
+
propertyusestandardized: 1,
|
|
33
|
+
hvaccoolingdetail: 1,
|
|
34
|
+
hvacheatingdetail: 1,
|
|
35
|
+
utilitieswatersource: 1,
|
|
36
|
+
flooringmaterialprimary: 1,
|
|
37
|
+
_id: 0, // eslint-disable-line
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
.toArray();
|
|
41
|
+
};
|
|
25
42
|
return async function processZip(zip, errors) {
|
|
26
43
|
const meta = {
|
|
27
44
|
requests: 0,
|
|
@@ -33,7 +50,7 @@ function getFilterFetcherProcessor({ mongoDb: db, fetchProperties }) {
|
|
|
33
50
|
return meta;
|
|
34
51
|
}
|
|
35
52
|
try {
|
|
36
|
-
const properties = await
|
|
53
|
+
const properties = await getProperties(zip);
|
|
37
54
|
meta.requests += 1;
|
|
38
55
|
meta.properties += properties.length;
|
|
39
56
|
const filters = (0, calc_filter_count_1.calculateFilterCount)(properties);
|
|
@@ -50,6 +67,7 @@ function getFilterFetcherProcessor({ mongoDb: db, fetchProperties }) {
|
|
|
50
67
|
console.error(e);
|
|
51
68
|
errors.add(zip);
|
|
52
69
|
meta.errors += 1;
|
|
70
|
+
throw e;
|
|
53
71
|
}
|
|
54
72
|
return meta;
|
|
55
73
|
};
|
|
@@ -8,7 +8,7 @@ const getPropertiesCollection = async (db) => {
|
|
|
8
8
|
function fixPropertyName(propertyName) {
|
|
9
9
|
return propertyName ? propertyName.toUpperCase() : '';
|
|
10
10
|
}
|
|
11
|
-
function getPropertyUseGroupProcessor(
|
|
11
|
+
function getPropertyUseGroupProcessor(db) {
|
|
12
12
|
function fixPropertyNames(properties) {
|
|
13
13
|
return properties
|
|
14
14
|
.filter(p => p.propertyusegroup &&
|
|
@@ -32,6 +32,16 @@ function getPropertyUseGroupProcessor({ mongoDb: db, fetchProperties }) {
|
|
|
32
32
|
}));
|
|
33
33
|
return collection.bulkWrite(propQuery, { ordered: true, w: 1 });
|
|
34
34
|
};
|
|
35
|
+
const getProperties = (zip) => {
|
|
36
|
+
return db
|
|
37
|
+
.collection('properties')
|
|
38
|
+
.find({ zipcode: zip }, {
|
|
39
|
+
projection: {
|
|
40
|
+
propertyusegroup: 1,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
.toArray();
|
|
44
|
+
};
|
|
35
45
|
return async function processZip(zip, errors) {
|
|
36
46
|
const meta = {
|
|
37
47
|
requests: 0,
|
|
@@ -42,7 +52,7 @@ function getPropertyUseGroupProcessor({ mongoDb: db, fetchProperties }) {
|
|
|
42
52
|
return meta;
|
|
43
53
|
}
|
|
44
54
|
try {
|
|
45
|
-
const properties = await
|
|
55
|
+
const properties = await getProperties(zip);
|
|
46
56
|
meta.requests += 1;
|
|
47
57
|
if (!properties?.length) {
|
|
48
58
|
return meta;
|
|
@@ -59,6 +69,7 @@ function getPropertyUseGroupProcessor({ mongoDb: db, fetchProperties }) {
|
|
|
59
69
|
console.error(e);
|
|
60
70
|
errors.add(zip);
|
|
61
71
|
meta.errors += 1;
|
|
72
|
+
throw e;
|
|
62
73
|
}
|
|
63
74
|
return meta;
|
|
64
75
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
17
|
+
exports.configureProcessor = void 0;
|
|
4
18
|
const filter_fetcher_1 = require("./filter-fetcher");
|
|
5
19
|
const fix_property_use_1 = require("./fix-property-use");
|
|
6
20
|
const property_assessorlastsaledate_converter_1 = require("./property-assessorlastsaledate-converter");
|
|
7
21
|
const zip_processor_1 = require("./zip-processor");
|
|
8
22
|
function configureProcessor(config) {
|
|
9
|
-
const filterFetcher = (0, zip_processor_1.zipProcessor)(config, (0, filter_fetcher_1.getFilterFetcherProcessor)(config));
|
|
10
|
-
const assessorLastSaleDateProcessor = (0, zip_processor_1.zipProcessor)(config, (0, property_assessorlastsaledate_converter_1.getAssessorLastSaleDateProcessor)(config.mongoDb));
|
|
11
|
-
const propertyUseGroupProcessor = (0, zip_processor_1.zipProcessor)(config, (0, fix_property_use_1.getPropertyUseGroupProcessor)(config));
|
|
23
|
+
const filterFetcher = (0, zip_processor_1.zipProcessor)(config.workers, (0, filter_fetcher_1.getFilterFetcherProcessor)(config.mongoDb));
|
|
24
|
+
const assessorLastSaleDateProcessor = (0, zip_processor_1.zipProcessor)(config.workers, (0, property_assessorlastsaledate_converter_1.getAssessorLastSaleDateProcessor)(config.mongoDb));
|
|
25
|
+
const propertyUseGroupProcessor = (0, zip_processor_1.zipProcessor)(config.workers, (0, fix_property_use_1.getPropertyUseGroupProcessor)(config.mongoDb));
|
|
12
26
|
return { filterFetcher, assessorLastSaleDateProcessor, propertyUseGroupProcessor };
|
|
13
27
|
}
|
|
14
28
|
exports.configureProcessor = configureProcessor;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Object.defineProperty(exports, "propertiesAssessorLastSaleDateAggregate", { enumerable: true, get: function () { return property_assessorlastsaledate_converter_2.propertiesAssessorLastSaleDateAggregate; } });
|
|
29
|
+
__exportStar(require("./fix-property-use"), exports);
|
|
30
|
+
__exportStar(require("./property-assessorlastsaledate-converter"), exports);
|
|
31
|
+
__exportStar(require("./filter-fetcher"), exports);
|
package/dist/zip-processor.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.zipProcessor = void 0;
|
|
5
5
|
const utils_1 = require("./utils/utils");
|
|
6
|
-
function zipProcessor(
|
|
6
|
+
function zipProcessor(workers, processorFn) {
|
|
7
7
|
let processor = null;
|
|
8
8
|
let erroredZips = new Set();
|
|
9
9
|
async function* processZips(zips) {
|
|
@@ -18,7 +18,7 @@ function zipProcessor(config, processorFn) {
|
|
|
18
18
|
}
|
|
19
19
|
for (let zipNum = startZipNum; zipNum <= endZipNum;) {
|
|
20
20
|
const processes = [];
|
|
21
|
-
const processZipEnd = zipNum +
|
|
21
|
+
const processZipEnd = zipNum + workers - 1;
|
|
22
22
|
for (; zipNum <= endZipNum && zipNum <= processZipEnd; zipNum++) {
|
|
23
23
|
const zip = (0, utils_1.convertToZipString)(zipNum);
|
|
24
24
|
processes.push(processorFn(zip, erroredZips));
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/acquisition-functions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p .",
|
|
9
|
+
"build-test": "tsc -p tsconfig.test.json",
|
|
9
10
|
"test": "jest --runInBand"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
@@ -13,7 +14,6 @@
|
|
|
13
14
|
],
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"@jest/globals": "29.1.2",
|
|
16
|
-
"@tsconfig/node16": "^1.0.3",
|
|
17
17
|
"@types/jest": "^29.1.0",
|
|
18
18
|
"@types/mongodb": "^3.6.20",
|
|
19
19
|
"@types/node": "^18.6.3",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"cli": {
|
|
29
29
|
"webpack": false
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "8fcc659c203e83d450a38df825ffac26c16e960f"
|
|
32
32
|
}
|