@bedrockio/model 0.7.2 → 0.7.4

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/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ ## 0.7.0
2
+
3
+ - Handling null fields in search queries.
4
+
5
+ ## 0.6.0
6
+
7
+ - Added upsert module with `findOrCreate`.
8
+ - Added mechanism to sync cached fields when referenced document is saved.
9
+ - Renamed `syncSearchFields` to `syncCacheFields`.
10
+ - Simplified cache fields and search definition.
11
+
12
+ ## 0.5.0
13
+
14
+ - Refactored include module to use ^ operator for exclusion.
15
+
16
+ ## 0.4.0
17
+
18
+ - Added `hydrate` patch method.
@@ -192,7 +192,7 @@ function buildRegexQuery(keyword, fields) {
192
192
  const regexKeyword = (0, _lodash.escapeRegExp)(keyword);
193
193
  return {
194
194
  [field]: {
195
- $regex: `${regexKeyword}`,
195
+ $regex: regexKeyword,
196
196
  $options: 'i'
197
197
  }
198
198
  };
@@ -40,7 +40,7 @@ A 24 character hexadecimal string representing a Mongo [ObjectId](https://bit.ly
40
40
  An object with an \`id\` field may also be passed, which will be converted into a string.
41
41
  `.trim()
42
42
  });
43
- const namedSchemas = {
43
+ const NAMED_SCHEMAS = {
44
44
  // Email is special as we are assuming that in
45
45
  // all cases lowercase should be allowed but coerced.
46
46
  email: _yada.default.string().lowercase().email(),
@@ -61,6 +61,8 @@ const namedSchemas = {
61
61
  locale: _yada.default.string().locale(),
62
62
  md5: _yada.default.string().md5(),
63
63
  phone: _yada.default.string().phone(),
64
+ 'phone:US': _yada.default.string().phone('US'),
65
+ 'phone:NANP': _yada.default.string().phone('NANP'),
64
66
  postalCode: _yada.default.string().postalCode(),
65
67
  zipcode: _yada.default.string().zipcode(),
66
68
  sha1: _yada.default.string().sha1(),
@@ -70,7 +72,7 @@ const namedSchemas = {
70
72
  uuid: _yada.default.string().uuid()
71
73
  };
72
74
  function addValidators(schemas) {
73
- Object.assign(namedSchemas, schemas);
75
+ Object.assign(NAMED_SCHEMAS, schemas);
74
76
  }
75
77
  function applyValidation(schema, definition) {
76
78
  const hasUnique = (0, _softDelete.hasUniqueConstraints)(schema);
@@ -555,7 +557,7 @@ function wrapMongooseValidator(validator) {
555
557
  };
556
558
  }
557
559
  function getNamedSchema(name) {
558
- const schema = namedSchemas[name];
560
+ const schema = NAMED_SCHEMAS[name];
559
561
  if (!schema) {
560
562
  throw new Error(`Cannot find schema for "${name}".`);
561
563
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -9,7 +9,8 @@
9
9
  "lint": "eslint",
10
10
  "build": "scripts/build",
11
11
  "eject": "scripts/eject.js",
12
- "prepublishOnly": "yarn build && yarn types"
12
+ "prepublish": "yarn build && yarn types",
13
+ "postpublish": "scripts/tag"
13
14
  },
14
15
  "main": "dist/cjs/index.js",
15
16
  "module": "src/index.js",
@@ -30,7 +31,7 @@
30
31
  "lodash": "^4.17.21"
31
32
  },
32
33
  "peerDependencies": {
33
- "@bedrockio/yada": "^1.2.2",
34
+ "@bedrockio/yada": "^1.2.3",
34
35
  "mongoose": "^8.6.2"
35
36
  },
36
37
  "devDependencies": {
@@ -38,7 +39,7 @@
38
39
  "@babel/core": "^7.20.12",
39
40
  "@babel/preset-env": "^7.20.2",
40
41
  "@bedrockio/prettier-config": "^1.0.2",
41
- "@bedrockio/yada": "^1.2.2",
42
+ "@bedrockio/yada": "^1.2.3",
42
43
  "@shelf/jest-mongodb": "^4.3.2",
43
44
  "eslint": "^8.33.0",
44
45
  "eslint-plugin-bedrock": "^1.0.26",
package/src/search.js CHANGED
@@ -196,7 +196,7 @@ function buildRegexQuery(keyword, fields) {
196
196
  const regexKeyword = escapeRegExp(keyword);
197
197
  return {
198
198
  [field]: {
199
- $regex: `${regexKeyword}`,
199
+ $regex: regexKeyword,
200
200
  $options: 'i',
201
201
  },
202
202
  };
package/src/validation.js CHANGED
@@ -49,7 +49,7 @@ An object with an \`id\` field may also be passed, which will be converted into
49
49
  `.trim(),
50
50
  });
51
51
 
52
- const namedSchemas = {
52
+ const NAMED_SCHEMAS = {
53
53
  // Email is special as we are assuming that in
54
54
  // all cases lowercase should be allowed but coerced.
55
55
  email: yd.string().lowercase().email(),
@@ -71,6 +71,8 @@ const namedSchemas = {
71
71
  locale: yd.string().locale(),
72
72
  md5: yd.string().md5(),
73
73
  phone: yd.string().phone(),
74
+ 'phone:US': yd.string().phone('US'),
75
+ 'phone:NANP': yd.string().phone('NANP'),
74
76
  postalCode: yd.string().postalCode(),
75
77
  zipcode: yd.string().zipcode(),
76
78
  sha1: yd.string().sha1(),
@@ -81,7 +83,7 @@ const namedSchemas = {
81
83
  };
82
84
 
83
85
  export function addValidators(schemas) {
84
- Object.assign(namedSchemas, schemas);
86
+ Object.assign(NAMED_SCHEMAS, schemas);
85
87
  }
86
88
 
87
89
  export function applyValidation(schema, definition) {
@@ -611,7 +613,7 @@ function wrapMongooseValidator(validator) {
611
613
  }
612
614
 
613
615
  function getNamedSchema(name) {
614
- const schema = namedSchemas[name];
616
+ const schema = NAMED_SCHEMAS[name];
615
617
  if (!schema) {
616
618
  throw new Error(`Cannot find schema for "${name}".`);
617
619
  }
@@ -19,7 +19,7 @@ export const OBJECT_ID_SCHEMA: {
19
19
  uppercase(assert?: boolean): any;
20
20
  match(reg: RegExp): any;
21
21
  email(): any;
22
- phone(): any;
22
+ phone(code: any): any;
23
23
  hex(): any;
24
24
  md5(): any;
25
25
  sha1(): any;
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAkFA,kDAEC;AAED,oEAgGC;AAsBD,wEA2BC;AAkVD;;;EAEC;AAED;;;EAOC;AAljBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAoFA,kDAEC;AAED,oEAgGC;AAsBD,wEA2BC;AAkVD;;;EAEC;AAED;;;EAOC;AApjBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}