@servicetitan/acquisition-functions 0.10.0 → 0.12.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
  });
@@ -44,31 +44,31 @@ describe('property-assessorlastsaledate-converter', () => {
44
44
  zipcode: '90001',
45
45
  propertyusegroup: [
46
46
  {
47
- name: 'COMMERCIAL',
47
+ name: 'Commercial',
48
48
  count: 2,
49
49
  },
50
50
  ],
51
51
  propertyusestandardized: [
52
52
  {
53
- name: 'APARTMENT HOUSE (5+ UNITS)',
54
- groupName: 'COMMERCIAL',
53
+ name: 'Apartment house (5+ units)',
54
+ groupName: 'Commercial',
55
55
  count: 1,
56
56
  },
57
57
  {
58
- name: 'AUTO REPAIR, GARAGE',
59
- groupName: 'COMMERCIAL',
58
+ name: 'Auto repair, garage',
59
+ groupName: 'Commercial',
60
60
  count: 1,
61
61
  },
62
62
  ],
63
63
  hvaccoolingdetail: [
64
64
  {
65
- name: 'YES',
65
+ name: 'Yes',
66
66
  count: 1,
67
67
  },
68
68
  ],
69
69
  hvacheatingdetail: [
70
70
  {
71
- name: 'NONE',
71
+ name: 'None',
72
72
  count: 2,
73
73
  },
74
74
  ],
@@ -83,8 +83,8 @@ describe('property-assessorlastsaledate-converter', () => {
83
83
  });
84
84
  (0, globals_1.expect)(result).not.toBe(null);
85
85
  (0, globals_1.expect)(result?.propertyusegroup.length).toBe(1);
86
- (0, globals_1.expect)(result?.propertyusegroup[0].name).toBe('COMMERCIAL');
87
- (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();
88
88
  });
89
89
  afterAll(async () => {
90
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
  });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.closeConnection = exports.openConnection = exports.setupProperties = void 0;
3
+ exports.closeConnection = exports.openConnection = void 0;
4
+ exports.setupProperties = setupProperties;
4
5
  const mongodb_1 = require("mongodb");
5
6
  const mock_1 = require("./mock");
6
7
  async function setupProperties(base) {
@@ -24,12 +25,9 @@ async function setupProperties(base) {
24
25
  // ignore
25
26
  }
26
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 () => {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFilterFetcherProcessor = void 0;
3
+ exports.getFilterFetcherProcessor = getFilterFetcherProcessor;
4
4
  const calc_filter_count_1 = require("./calc-filter-count");
5
5
  function getFilterFetcherProcessor(db) {
6
6
  let invalidFilters;
@@ -38,7 +38,7 @@ function getFilterFetcherProcessor(db) {
38
38
  utilitieswatersource: 1,
39
39
  utilitiessewageusage: 1,
40
40
  flooringmaterialprimary: 1,
41
- _id: 0, // eslint-disable-line
41
+ _id: 0,
42
42
  },
43
43
  })
44
44
  .toArray();
@@ -103,4 +103,3 @@ function getFilterFetcherProcessor(db) {
103
103
  return meta;
104
104
  };
105
105
  }
106
- exports.getFilterFetcherProcessor = getFilterFetcherProcessor;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertyUseGroupProcessorAggregate = exports.getPropertyUseGroupProcessor = void 0;
3
+ exports.getPropertyUseGroupProcessor = getPropertyUseGroupProcessor;
4
+ exports.propertyUseGroupProcessorAggregate = propertyUseGroupProcessorAggregate;
4
5
  const utils_1 = require("../utils/utils");
5
6
  const getPropertiesCollection = async (db) => {
6
7
  return db.collection('properties');
@@ -25,12 +26,11 @@ function getPropertyUseGroupProcessor(db) {
25
26
  const collection = await getPropertiesCollection(db);
26
27
  const propQuery = properties.map(({ _id, ...p }) => ({
27
28
  updateOne: {
28
- // eslint-disable-next-line @typescript-eslint/naming-convention
29
29
  filter: { _id },
30
30
  update: { $set: p },
31
31
  },
32
32
  }));
33
- return collection.bulkWrite(propQuery, { ordered: true, w: 1 });
33
+ return collection.bulkWrite(propQuery, { ordered: true, writeConcern: { w: 1 } });
34
34
  };
35
35
  const getProperties = (zip) => {
36
36
  return db
@@ -74,7 +74,6 @@ function getPropertyUseGroupProcessor(db) {
74
74
  return meta;
75
75
  };
76
76
  }
77
- exports.getPropertyUseGroupProcessor = getPropertyUseGroupProcessor;
78
77
  async function propertyUseGroupProcessorAggregate(db) {
79
78
  const collection = await getPropertiesCollection(db);
80
79
  const aggCursor = await collection.aggregate([
@@ -103,4 +102,3 @@ async function propertyUseGroupProcessorAggregate(db) {
103
102
  result = await aggCursor.next(); // eslint-disable-line no-await-in-loop
104
103
  } while (result);
105
104
  }
106
- exports.propertyUseGroupProcessorAggregate = propertyUseGroupProcessorAggregate;
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.configureProcessor = void 0;
17
+ exports.configureProcessor = configureProcessor;
18
18
  const filter_fetcher_1 = require("./filter-fetcher");
19
19
  const fix_property_use_1 = require("./fix-property-use");
20
20
  const property_assessorlastsaledate_converter_1 = require("./property-assessorlastsaledate-converter");
@@ -25,7 +25,6 @@ function configureProcessor(config) {
25
25
  const propertyUseGroupProcessor = (0, zip_processor_1.zipProcessor)(config.workers, (0, fix_property_use_1.getPropertyUseGroupProcessor)(config.mongoDb));
26
26
  return { filterFetcher, assessorLastSaleDateProcessor, propertyUseGroupProcessor };
27
27
  }
28
- exports.configureProcessor = configureProcessor;
29
28
  __exportStar(require("./fix-property-use"), exports);
30
29
  __exportStar(require("./property-assessorlastsaledate-converter"), exports);
31
30
  __exportStar(require("./filter-fetcher"), exports);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertiesAssessorLastSaleDateAggregate = exports.getAssessorLastSaleDateProcessor = void 0;
3
+ exports.getAssessorLastSaleDateProcessor = getAssessorLastSaleDateProcessor;
4
+ exports.propertiesAssessorLastSaleDateAggregate = propertiesAssessorLastSaleDateAggregate;
4
5
  const utils_1 = require("../utils/utils");
5
6
  const getPropertiesCollection = async (db) => {
6
7
  return db.collection('properties');
@@ -26,12 +27,11 @@ function getAssessorLastSaleDateProcessor(db) {
26
27
  const collection = await getPropertiesCollection(db);
27
28
  const propQuery = properties.map(({ _id, ...p }) => ({
28
29
  updateOne: {
29
- // eslint-disable-next-line @typescript-eslint/naming-convention
30
30
  filter: { _id },
31
31
  update: { $set: p },
32
32
  },
33
33
  }));
34
- return collection.bulkWrite(propQuery, { ordered: true, w: 1 });
34
+ return collection.bulkWrite(propQuery, { ordered: true, writeConcern: { w: 1 } });
35
35
  };
36
36
  return async function processZip(zip, errors) {
37
37
  const meta = {
@@ -65,7 +65,6 @@ function getAssessorLastSaleDateProcessor(db) {
65
65
  return meta;
66
66
  };
67
67
  }
68
- exports.getAssessorLastSaleDateProcessor = getAssessorLastSaleDateProcessor;
69
68
  async function propertiesAssessorLastSaleDateAggregate(db) {
70
69
  const collection = await getPropertiesCollection(db);
71
70
  const aggCursor = collection.aggregate([
@@ -104,4 +103,3 @@ async function propertiesAssessorLastSaleDateAggregate(db) {
104
103
  result = await aggCursor.next(); // eslint-disable-line no-await-in-loop
105
104
  } while (result);
106
105
  }
107
- exports.propertiesAssessorLastSaleDateAggregate = propertiesAssessorLastSaleDateAggregate;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { WithId } from 'mongodb';
2
- export declare type Property = WithId<{
2
+ export type Property = WithId<{
3
3
  attomid: number;
4
4
  fulladdress: string;
5
5
  addressstreet: string;
@@ -232,7 +232,7 @@ export interface Group {
232
232
  export interface GroupNamed extends Group {
233
233
  groupName: string;
234
234
  }
235
- export declare type Filter = WithId<{
235
+ export type Filter = WithId<{
236
236
  zipcode: string;
237
237
  propertyusegroup: Group[];
238
238
  propertyusestandardized: GroupNamed[];
@@ -10,13 +10,13 @@ export declare const convertStringToDate: (props: Property[], propName: keyof Pr
10
10
  addressunit: string;
11
11
  primarynumber: number;
12
12
  streetname: string;
13
- streetpredirection?: string | undefined;
14
- streetpostdirection?: string | undefined;
13
+ streetpredirection?: string;
14
+ streetpostdirection?: string;
15
15
  streetsuffix: string;
16
- secondarynumber?: number | undefined;
16
+ secondarynumber?: number;
17
17
  secondarydesignator: string;
18
- extrasecondarynumber?: number | undefined;
19
- extrasecondarydesignator?: string | undefined;
18
+ extrasecondarynumber?: number;
19
+ extrasecondarydesignator?: string;
20
20
  cityname: string;
21
21
  stateabbreviation: string;
22
22
  zipcode: string;
@@ -228,7 +228,7 @@ export declare const convertStringToDate: (props: Property[], propName: keyof Pr
228
228
  buildingscount: number;
229
229
  modifiedon: string;
230
230
  location: string;
231
- _id: import("bson").ObjectID;
231
+ _id: import("bson").ObjectId;
232
232
  }[];
233
233
  export declare function FilterNameValidator(filtersToIgnore: string[], unknownCharacter: string): {
234
234
  isValidFilterName(filterName: string, checkIgnoredFilters?: boolean): boolean;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalizeFirstLetter = exports.FilterNameValidator = exports.convertStringToDate = exports.convertToZipString = exports.isEmptyField = exports.UNKNOWN = exports.SEPARATOR_CHARACTER = void 0;
3
+ exports.convertStringToDate = exports.convertToZipString = exports.isEmptyField = exports.UNKNOWN = exports.SEPARATOR_CHARACTER = void 0;
4
+ exports.FilterNameValidator = FilterNameValidator;
5
+ exports.capitalizeFirstLetter = capitalizeFirstLetter;
4
6
  exports.SEPARATOR_CHARACTER = '___';
5
7
  exports.UNKNOWN = 'unknown';
6
8
  const isEmptyField = (field) => {
@@ -29,11 +31,9 @@ function FilterNameValidator(filtersToIgnore, unknownCharacter) {
29
31
  },
30
32
  };
31
33
  }
32
- exports.FilterNameValidator = FilterNameValidator;
33
34
  function capitalizeFirstLetter(val) {
34
35
  if (!val) {
35
36
  return val;
36
37
  }
37
38
  return val[0].toUpperCase() + val.slice(1).toLowerCase();
38
39
  }
39
- exports.capitalizeFirstLetter = capitalizeFirstLetter;
@@ -4,7 +4,7 @@ export interface ResultsMeta {
4
4
  errors: number;
5
5
  filters?: number;
6
6
  }
7
- declare type ProcessInput = [from: string, to: string] | string;
7
+ type ProcessInput = [from: string, to: string] | string;
8
8
  export declare function zipProcessor(workers: number, processorFn: (zip: string, errors: Set<string>) => Promise<ResultsMeta>): {
9
9
  getProcessor: () => AsyncGenerator<ResultsMeta | ResultsMeta[], void, unknown> | null;
10
10
  start: (zips: ProcessInput) => Promise<Required<ResultsMeta>>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable no-await-in-loop, require-atomic-updates */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.zipProcessor = void 0;
4
+ exports.zipProcessor = zipProcessor;
5
5
  const utils_1 = require("./utils/utils");
6
6
  function zipProcessor(workers, processorFn) {
7
7
  let processor = null;
@@ -85,4 +85,3 @@ function zipProcessor(workers, processorFn) {
85
85
  clear,
86
86
  };
87
87
  }
88
- exports.zipProcessor = zipProcessor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/acquisition-functions",
3
- "version": "0.10.0",
3
+ "version": "0.12.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": "5e7083d61a148b1b76b265f7d85caf476c3e8b26"
30
+ "gitHead": "a80589bd64eb965e97ae60aa28232ea60b5ed19c"
32
31
  }