@servicetitan/acquisition-functions 0.9.1 → 0.11.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.
@@ -22,29 +22,23 @@ describe('property-assessorlastsaledate-converter', () => {
22
22
  metadata = await assessorLastSaleDateProcessor.start('90001');
23
23
  });
24
24
  (0, globals_1.test)('should convert existing field to date', async () => {
25
- const result = await new Promise(resolve => {
26
- base.collection('properties')
27
- .find({
28
- assessorlastsaledate: {
29
- $exists: true,
30
- },
31
- })
32
- .toArray((err, res) => {
33
- resolve(res);
34
- });
35
- });
25
+ const result = await base
26
+ .collection('properties')
27
+ .find({
28
+ assessorlastsaledate: {
29
+ $exists: true,
30
+ },
31
+ })
32
+ .toArray();
36
33
  (0, globals_1.expect)(result[0].assessorlastsaledate).toBeInstanceOf(Date);
37
34
  });
38
35
  (0, globals_1.test)('should not touch nulls', async () => {
39
- const result = await new Promise(resolve => {
40
- base.collection('properties')
41
- .find({
42
- assessorlastsaledate: null,
43
- })
44
- .toArray((err, res) => {
45
- resolve(res);
46
- });
47
- });
36
+ const result = await base
37
+ .collection('properties')
38
+ .find({
39
+ assessorlastsaledate: null,
40
+ })
41
+ .toArray();
48
42
  (0, globals_1.expect)(result[0].assessorlastsaledate).toBe(null);
49
43
  });
50
44
  (0, globals_1.test)('should return metadata', async () => {
@@ -59,29 +53,23 @@ describe('property-assessorlastsaledate-converter', () => {
59
53
  await (0, index_1.propertiesAssessorLastSaleDateAggregate)(base);
60
54
  });
61
55
  (0, globals_1.test)('should convert existing field to date', async () => {
62
- const result = await new Promise(resolve => {
63
- base.collection('properties')
64
- .find({
65
- assessorlastsaledate: {
66
- $exists: true,
67
- },
68
- })
69
- .toArray((err, res) => {
70
- resolve(res);
71
- });
72
- });
56
+ const result = await base
57
+ .collection('properties')
58
+ .find({
59
+ assessorlastsaledate: {
60
+ $exists: true,
61
+ },
62
+ })
63
+ .toArray();
73
64
  (0, globals_1.expect)(result[0].assessorlastsaledate).toBeInstanceOf(Date);
74
65
  });
75
66
  (0, globals_1.test)('should not touch nulls', async () => {
76
- const result = await new Promise(resolve => {
77
- base.collection('properties')
78
- .find({
79
- assessorlastsaledate: null,
80
- })
81
- .toArray((err, res) => {
82
- resolve(res);
83
- });
84
- });
67
+ const result = await base
68
+ .collection('properties')
69
+ .find({
70
+ assessorlastsaledate: null,
71
+ })
72
+ .toArray();
85
73
  (0, globals_1.expect)(result[0].assessorlastsaledate).toBe(null);
86
74
  });
87
75
  });
@@ -28,6 +28,7 @@ describe('property-assessorlastsaledate-converter', () => {
28
28
  (0, globals_1.expect)(result?.hvacheatingdetail.length).toBe(0);
29
29
  (0, globals_1.expect)(result?.propertyusestandardized.length).toBe(0);
30
30
  (0, globals_1.expect)(result?.utilitieswatersource.length).toBe(0);
31
+ (0, globals_1.expect)(result?.utilitiessewageusage.length).toBe(0);
31
32
  });
32
33
  (0, globals_1.test)('should return metadata', async () => {
33
34
  (0, globals_1.expect)(metadata.errors).toBe(0);
@@ -43,35 +44,36 @@ describe('property-assessorlastsaledate-converter', () => {
43
44
  zipcode: '90001',
44
45
  propertyusegroup: [
45
46
  {
46
- name: 'COMMERCIAL',
47
+ name: 'Commercial',
47
48
  count: 2,
48
49
  },
49
50
  ],
50
51
  propertyusestandardized: [
51
52
  {
52
- name: 'APARTMENT HOUSE (5+ UNITS)',
53
- groupName: 'COMMERCIAL',
53
+ name: 'Apartment house (5+ units)',
54
+ groupName: 'Commercial',
54
55
  count: 1,
55
56
  },
56
57
  {
57
- name: 'AUTO REPAIR, GARAGE',
58
- groupName: 'COMMERCIAL',
58
+ name: 'Auto repair, garage',
59
+ groupName: 'Commercial',
59
60
  count: 1,
60
61
  },
61
62
  ],
62
63
  hvaccoolingdetail: [
63
64
  {
64
- name: 'YES',
65
+ name: 'Yes',
65
66
  count: 1,
66
67
  },
67
68
  ],
68
69
  hvacheatingdetail: [
69
70
  {
70
- name: 'NONE',
71
+ name: 'None',
71
72
  count: 2,
72
73
  },
73
74
  ],
74
75
  utilitieswatersource: [],
76
+ utilitiessewageusage: [],
75
77
  flooringmaterialprimary: [],
76
78
  });
77
79
  });
@@ -81,8 +83,8 @@ describe('property-assessorlastsaledate-converter', () => {
81
83
  });
82
84
  (0, globals_1.expect)(result).not.toBe(null);
83
85
  (0, globals_1.expect)(result?.propertyusegroup.length).toBe(1);
84
- (0, globals_1.expect)(result?.propertyusegroup[0].name).toBe('COMMERCIAL');
85
- (0, globals_1.expect)(result?.propertyusestandardized.every(({ groupName }) => groupName === 'COMMERCIAL')).toBeTruthy();
86
+ (0, globals_1.expect)(result?.propertyusegroup[0].name).toBe('Commercial');
87
+ (0, globals_1.expect)(result?.propertyusestandardized.every(({ groupName }) => groupName === 'Commercial')).toBeTruthy();
86
88
  });
87
89
  afterAll(async () => {
88
90
  await (0, setup_1.closeConnection)();
@@ -26,18 +26,15 @@ describe('property-use-group-converter', () => {
26
26
  (0, globals_1.expect)(metadata.properties).toBe(2);
27
27
  (0, globals_1.expect)(metadata.requests).toBe(2);
28
28
  });
29
- (0, globals_1.test)('should convert existing field to captial-case', async () => {
30
- const result = await new Promise(resolve => {
31
- base.collection('properties')
32
- .find({
33
- propertyusegroup: {
34
- $exists: true,
35
- },
36
- })
37
- .toArray((err, res) => {
38
- resolve(res);
39
- });
40
- });
29
+ (0, globals_1.test)('should convert existing field to capital-case', async () => {
30
+ const result = await base
31
+ .collection('properties')
32
+ .find({
33
+ propertyusegroup: {
34
+ $exists: true,
35
+ },
36
+ })
37
+ .toArray();
41
38
  (0, globals_1.expect)(result[0].propertyusegroup).toBe('COMMERCIAL');
42
39
  (0, globals_1.expect)(result[1].propertyusegroup).toBe('COMMERCIAL');
43
40
  });
@@ -46,19 +43,16 @@ describe('property-use-group-converter', () => {
46
43
  (0, globals_1.beforeAll)(async () => {
47
44
  await (0, setup_1.setupProperties)(base);
48
45
  });
49
- (0, globals_1.test)('should convert existing field to captial-case', async () => {
46
+ (0, globals_1.test)('should convert existing field to capital-case', async () => {
50
47
  await (0, index_1.propertyUseGroupProcessorAggregate)(base);
51
- const result = await new Promise(resolve => {
52
- base.collection('properties')
53
- .find({
54
- propertyusegroup: {
55
- $exists: true,
56
- },
57
- })
58
- .toArray((err, res) => {
59
- resolve(res);
60
- });
61
- });
48
+ const result = await base
49
+ .collection('properties')
50
+ .find({
51
+ propertyusegroup: {
52
+ $exists: true,
53
+ },
54
+ })
55
+ .toArray();
62
56
  (0, globals_1.expect)(result[0].propertyusegroup).toBe('COMMERCIAL');
63
57
  (0, globals_1.expect)(result[1].propertyusegroup).toBe('COMMERCIAL');
64
58
  });
@@ -27,9 +27,7 @@ async function setupProperties(base) {
27
27
  exports.setupProperties = setupProperties;
28
28
  const url = `mongodb://${process.env.MONGO_HOSTNAME ?? 'localhost'}:27017`;
29
29
  const mongoClient = new mongodb_1.MongoClient(url, {
30
- useNewUrlParser: true,
31
- useUnifiedTopology: true,
32
- poolSize: 60,
30
+ maxPoolSize: 60,
33
31
  });
34
32
  let connectedMongoClient;
35
33
  const openConnection = async () => {
@@ -21,6 +21,10 @@ export declare const calculateFilterCount: (properties: Property[], filtersToIgn
21
21
  name: string;
22
22
  count: number;
23
23
  }[];
24
+ utilitiessewageusageCounts: {
25
+ name: string;
26
+ count: number;
27
+ }[];
24
28
  flooringmaterialprimaryCounts: {
25
29
  name: string;
26
30
  count: number;
@@ -9,6 +9,7 @@ const calculateFilterCount = (properties, filtersToIgnore) => {
9
9
  hvaccoolingdetail: {},
10
10
  hvacheatingdetail: {},
11
11
  utilitieswatersource: {},
12
+ utilitiessewageusage: {},
12
13
  flooringmaterialprimary: {},
13
14
  };
14
15
  const { isValidFilterName } = (0, utils_1.FilterNameValidator)(filtersToIgnore, utils_1.UNKNOWN);
@@ -20,6 +21,7 @@ const calculateFilterCount = (properties, filtersToIgnore) => {
20
21
  hvaccoolingdetail: (0, utils_1.capitalizeFirstLetter)(p.hvaccoolingdetail),
21
22
  hvacheatingdetail: (0, utils_1.capitalizeFirstLetter)(p.hvacheatingdetail),
22
23
  utilitieswatersource: (0, utils_1.capitalizeFirstLetter)(p.utilitieswatersource),
24
+ utilitiessewageusage: (0, utils_1.capitalizeFirstLetter)(p.utilitiessewageusage),
23
25
  flooringmaterialprimary: (0, utils_1.capitalizeFirstLetter)(p.flooringmaterialprimary),
24
26
  }))
25
27
  .forEach(p => {
@@ -48,6 +50,11 @@ const calculateFilterCount = (properties, filtersToIgnore) => {
48
50
  filterCount.utilitieswatersource[p.utilitieswatersource] || 0;
49
51
  filterCount.utilitieswatersource[p.utilitieswatersource] += 1;
50
52
  }
53
+ if (isValidFilterName(p.utilitiessewageusage.toLowerCase())) {
54
+ filterCount.utilitiessewageusage[p.utilitiessewageusage] =
55
+ filterCount.utilitiessewageusage[p.utilitiessewageusage] || 0;
56
+ filterCount.utilitiessewageusage[p.utilitiessewageusage] += 1;
57
+ }
51
58
  if (isValidFilterName(p.flooringmaterialprimary.toLowerCase())) {
52
59
  filterCount.flooringmaterialprimary[p.flooringmaterialprimary] =
53
60
  filterCount.flooringmaterialprimary[p.flooringmaterialprimary] || 0;
@@ -82,12 +89,17 @@ const calculateFilterCount = (properties, filtersToIgnore) => {
82
89
  name,
83
90
  count: filterCount.utilitieswatersource[name],
84
91
  }));
92
+ const utilitiessewageusageCounts = Object.keys(filterCount.utilitiessewageusage).map(name => ({
93
+ name,
94
+ count: filterCount.utilitiessewageusage[name],
95
+ }));
85
96
  return {
86
97
  propertyusegroupCounts,
87
98
  propertyusestandardizedCounts,
88
99
  hvaccoolingdetailCounts,
89
100
  hvacheatingdetailCounts,
90
101
  utilitieswatersourceCounts,
102
+ utilitiessewageusageCounts,
91
103
  flooringmaterialprimaryCounts,
92
104
  };
93
105
  };
@@ -12,7 +12,7 @@ function getFilterFetcherProcessor(db) {
12
12
  const collection = await getFiltersCollection();
13
13
  return collection.deleteOne({ zipcode: zip });
14
14
  };
15
- const addZipFilters = async ({ zip, propertyusegroupCounts, propertyusestandardizedCounts, hvaccoolingdetailCounts, hvacheatingdetailCounts, utilitieswatersourceCounts, flooringmaterialprimaryCounts, }) => {
15
+ const addZipFilters = async ({ zip, propertyusegroupCounts, propertyusestandardizedCounts, hvaccoolingdetailCounts, hvacheatingdetailCounts, utilitieswatersourceCounts, utilitiessewageusageCounts, flooringmaterialprimaryCounts, }) => {
16
16
  const collection = await getFiltersCollection();
17
17
  return collection.insertOne({
18
18
  zipcode: zip,
@@ -21,6 +21,7 @@ function getFilterFetcherProcessor(db) {
21
21
  hvaccoolingdetail: hvaccoolingdetailCounts,
22
22
  hvacheatingdetail: hvacheatingdetailCounts,
23
23
  utilitieswatersource: utilitieswatersourceCounts,
24
+ utilitiessewageusage: utilitiessewageusageCounts,
24
25
  flooringmaterialprimary: flooringmaterialprimaryCounts,
25
26
  });
26
27
  };
@@ -35,8 +36,9 @@ function getFilterFetcherProcessor(db) {
35
36
  hvaccoolingdetail: 1,
36
37
  hvacheatingdetail: 1,
37
38
  utilitieswatersource: 1,
39
+ utilitiessewageusage: 1,
38
40
  flooringmaterialprimary: 1,
39
- _id: 0, // eslint-disable-line
41
+ _id: 0,
40
42
  },
41
43
  })
42
44
  .toArray();
@@ -25,12 +25,11 @@ function getPropertyUseGroupProcessor(db) {
25
25
  const collection = await getPropertiesCollection(db);
26
26
  const propQuery = properties.map(({ _id, ...p }) => ({
27
27
  updateOne: {
28
- // eslint-disable-next-line @typescript-eslint/naming-convention
29
28
  filter: { _id },
30
29
  update: { $set: p },
31
30
  },
32
31
  }));
33
- return collection.bulkWrite(propQuery, { ordered: true, w: 1 });
32
+ return collection.bulkWrite(propQuery, { ordered: true, writeConcern: { w: 1 } });
34
33
  };
35
34
  const getProperties = (zip) => {
36
35
  return db
@@ -26,12 +26,11 @@ function getAssessorLastSaleDateProcessor(db) {
26
26
  const collection = await getPropertiesCollection(db);
27
27
  const propQuery = properties.map(({ _id, ...p }) => ({
28
28
  updateOne: {
29
- // eslint-disable-next-line @typescript-eslint/naming-convention
30
29
  filter: { _id },
31
30
  update: { $set: p },
32
31
  },
33
32
  }));
34
- return collection.bulkWrite(propQuery, { ordered: true, w: 1 });
33
+ return collection.bulkWrite(propQuery, { ordered: true, writeConcern: { w: 1 } });
35
34
  };
36
35
  return async function processZip(zip, errors) {
37
36
  const meta = {
package/dist/types.d.ts CHANGED
@@ -239,5 +239,6 @@ export declare type Filter = WithId<{
239
239
  hvaccoolingdetail: Group[];
240
240
  hvacheatingdetail: Group[];
241
241
  utilitieswatersource: Group[];
242
+ utilitiessewageusage: Group[];
242
243
  flooringmaterialprimary: Group[];
243
244
  }>;
@@ -1,20 +1,7 @@
1
1
  import { Property } from '../types';
2
2
  export declare const SEPARATOR_CHARACTER = "___";
3
3
  export declare const UNKNOWN = "unknown";
4
- export declare const isNotFullProperty: (property: Property) => boolean;
5
4
  export declare const isEmptyField: (field: string) => boolean;
6
- export declare const extractUniqueFilterNames: (properties: Property[]) => {
7
- propertyUseObjects: {
8
- name: string;
9
- typeName: string;
10
- }[];
11
- propertyTypeNames: string[];
12
- hvacCoolingSystemNames: string[];
13
- hvacHeatingSystemNames: string[];
14
- waterSourceNames: string[];
15
- flooringMaterialsNames: string[];
16
- };
17
- export declare const convertObjectToArray: <T extends Record<string, unknown>>(obj: T) => T[keyof T][];
18
5
  export declare const convertToZipString: (zipNumber: number) => string;
19
6
  export declare const convertStringToDate: (props: Property[], propName: keyof Property) => {
20
7
  attomid: number;
@@ -241,7 +228,7 @@ export declare const convertStringToDate: (props: Property[], propName: keyof Pr
241
228
  buildingscount: number;
242
229
  modifiedon: string;
243
230
  location: string;
244
- _id: import("bson").ObjectID;
231
+ _id: import("bson").ObjectId;
245
232
  }[];
246
233
  export declare function FilterNameValidator(filtersToIgnore: string[], unknownCharacter: string): {
247
234
  isValidFilterName(filterName: string, checkIgnoredFilters?: boolean): boolean;
@@ -1,69 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalizeFirstLetter = exports.FilterNameValidator = exports.convertStringToDate = exports.convertToZipString = exports.convertObjectToArray = exports.extractUniqueFilterNames = exports.isEmptyField = exports.isNotFullProperty = exports.UNKNOWN = exports.SEPARATOR_CHARACTER = void 0;
3
+ exports.capitalizeFirstLetter = exports.FilterNameValidator = exports.convertStringToDate = exports.convertToZipString = exports.isEmptyField = exports.UNKNOWN = exports.SEPARATOR_CHARACTER = void 0;
4
4
  exports.SEPARATOR_CHARACTER = '___';
5
5
  exports.UNKNOWN = 'unknown';
6
- const isNotFullProperty = (property) => {
7
- if (!property.hvaccoolingdetail) {
8
- return true;
9
- }
10
- return ((0, exports.isEmptyField)(property.hvaccoolingdetail) ||
11
- (0, exports.isEmptyField)(property.hvacheatingdetail) ||
12
- (0, exports.isEmptyField)(property.utilitieswatersource) ||
13
- (0, exports.isEmptyField)(property.propertyusegroup) ||
14
- (0, exports.isEmptyField)(property.propertyusestandardized) ||
15
- (0, exports.isEmptyField)(property.flooringmaterialprimary));
16
- };
17
- exports.isNotFullProperty = isNotFullProperty;
18
6
  const isEmptyField = (field) => {
19
7
  return field.toLowerCase() === exports.UNKNOWN;
20
8
  };
21
9
  exports.isEmptyField = isEmptyField;
22
- const extractUniqueFilterNames = (properties) => {
23
- const hvaccoolingdetail = new Set();
24
- const hvacheatingdetail = new Set();
25
- const utilitieswatersource = new Set();
26
- const propertyusegroup = new Set();
27
- const propertyusestandardized = new Set();
28
- const flooringmaterialprimary = new Set();
29
- properties.forEach(property => {
30
- hvaccoolingdetail.add(property.hvaccoolingdetail);
31
- hvacheatingdetail.add(property.hvacheatingdetail);
32
- propertyusegroup.add(property.propertyusegroup);
33
- utilitieswatersource.add(property.utilitieswatersource);
34
- propertyusestandardized.add(property.propertyusestandardized + exports.SEPARATOR_CHARACTER + property.propertyusegroup);
35
- flooringmaterialprimary.add(property.flooringmaterialprimary);
36
- });
37
- const propertyUseObjects = Array.from(propertyusestandardized).map(filter => {
38
- const split = filter.split(exports.SEPARATOR_CHARACTER);
39
- return {
40
- name: split[0],
41
- typeName: split[1],
42
- };
43
- });
44
- const hvacCoolingSystemNames = Array.from(hvaccoolingdetail);
45
- const hvacHeatingSystemNames = Array.from(hvacheatingdetail);
46
- const propertyTypeNames = Array.from(propertyusegroup);
47
- const waterSourceNames = Array.from(utilitieswatersource);
48
- const flooringMaterialsNames = Array.from(flooringmaterialprimary);
49
- return {
50
- propertyUseObjects,
51
- propertyTypeNames,
52
- hvacCoolingSystemNames,
53
- hvacHeatingSystemNames,
54
- waterSourceNames,
55
- flooringMaterialsNames,
56
- };
57
- };
58
- exports.extractUniqueFilterNames = extractUniqueFilterNames;
59
- const convertObjectToArray = (obj) => {
60
- const array = [];
61
- for (const key in obj) {
62
- array.push(obj[key]);
63
- }
64
- return array;
65
- };
66
- exports.convertObjectToArray = convertObjectToArray;
67
10
  const ZIP_STRING_LENGTH = 5;
68
11
  const convertToZipString = (zipNumber) => {
69
12
  const zipString = zipNumber + '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/acquisition-functions",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -15,10 +15,9 @@
15
15
  "devDependencies": {
16
16
  "@jest/globals": "29.1.2",
17
17
  "@types/jest": "^29.1.0",
18
- "@types/mongodb": "^3.6.20",
19
18
  "@types/node": "^18.6.3",
20
19
  "jest": "29.1.2",
21
- "mongodb": "3.6.3",
20
+ "mongodb": "~6.6.2",
22
21
  "ts-jest": "29.0.3",
23
22
  "ts-node": "^10.9.1"
24
23
  },
@@ -28,5 +27,5 @@
28
27
  "cli": {
29
28
  "webpack": false
30
29
  },
31
- "gitHead": "4b8359e2b53e25f3148c33f2fbe7e3ea33c3ca5a"
30
+ "gitHead": "f9ea8fb7e8b10f8d969e7afa52ffb9bb76de07b7"
32
31
  }