@bedrockio/model 0.1.22 → 0.1.23

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.
@@ -0,0 +1 @@
1
+ module.exports = require('@bedrockio/prettier-config');
@@ -74,11 +74,15 @@ function addValidators(schemas) {
74
74
  }
75
75
  function applyValidation(schema, definition) {
76
76
  const hasUnique = (0, _softDelete.hasUniqueConstraints)(schema);
77
- schema.static('getCreateValidation', function getCreateValidation(appendSchema) {
77
+ schema.static('getCreateValidation', function getCreateValidation(options = {}) {
78
+ const {
79
+ allowInclude,
80
+ ...appendSchema
81
+ } = options;
78
82
  return getSchemaFromMongoose(schema, {
79
83
  model: this,
80
84
  appendSchema,
81
- allowIncludes: true,
85
+ allowInclude,
82
86
  stripDeleted: true,
83
87
  stripTimestamps: true,
84
88
  allowExpandedRefs: true,
@@ -91,10 +95,15 @@ function applyValidation(schema, definition) {
91
95
  })
92
96
  });
93
97
  });
94
- schema.static('getUpdateValidation', function getUpdateValidation(appendSchema) {
98
+ schema.static('getUpdateValidation', function getUpdateValidation(options = {}) {
99
+ const {
100
+ allowInclude,
101
+ ...appendSchema
102
+ } = options;
95
103
  return getSchemaFromMongoose(schema, {
96
104
  model: this,
97
105
  appendSchema,
106
+ allowInclude,
98
107
  skipRequired: true,
99
108
  stripUnknown: true,
100
109
  stripDeleted: true,
@@ -119,7 +128,7 @@ function applyValidation(schema, definition) {
119
128
  model: this,
120
129
  allowSearch: true,
121
130
  skipRequired: true,
122
- allowIncludes: true,
131
+ allowInclude: true,
123
132
  expandDotSyntax: true,
124
133
  unwindArrayFields: true,
125
134
  requireReadAccess: true,
@@ -167,7 +176,7 @@ function getValidationSchema(attributes, options = {}) {
167
176
  const {
168
177
  appendSchema,
169
178
  assertUniqueOptions,
170
- allowIncludes
179
+ allowInclude
171
180
  } = options;
172
181
  let schema = getObjectSchema(attributes, options);
173
182
  if (assertUniqueOptions) {
@@ -183,7 +192,7 @@ function getValidationSchema(attributes, options = {}) {
183
192
  if (appendSchema) {
184
193
  schema = schema.append(appendSchema);
185
194
  }
186
- if (allowIncludes) {
195
+ if (allowInclude) {
187
196
  schema = schema.append(_include.INCLUDE_FIELD_SCHEMA);
188
197
  }
189
198
  return schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/validation.js CHANGED
@@ -88,11 +88,12 @@ export function applyValidation(schema, definition) {
88
88
 
89
89
  schema.static(
90
90
  'getCreateValidation',
91
- function getCreateValidation(appendSchema) {
91
+ function getCreateValidation(options = {}) {
92
+ const { allowInclude, ...appendSchema } = options;
92
93
  return getSchemaFromMongoose(schema, {
93
94
  model: this,
94
95
  appendSchema,
95
- allowIncludes: true,
96
+ allowInclude,
96
97
  stripDeleted: true,
97
98
  stripTimestamps: true,
98
99
  allowExpandedRefs: true,
@@ -109,10 +110,12 @@ export function applyValidation(schema, definition) {
109
110
 
110
111
  schema.static(
111
112
  'getUpdateValidation',
112
- function getUpdateValidation(appendSchema) {
113
+ function getUpdateValidation(options = {}) {
114
+ const { allowInclude, ...appendSchema } = options;
113
115
  return getSchemaFromMongoose(schema, {
114
116
  model: this,
115
117
  appendSchema,
118
+ allowInclude,
116
119
  skipRequired: true,
117
120
  stripUnknown: true,
118
121
  stripDeleted: true,
@@ -138,7 +141,7 @@ export function applyValidation(schema, definition) {
138
141
  model: this,
139
142
  allowSearch: true,
140
143
  skipRequired: true,
141
- allowIncludes: true,
144
+ allowInclude: true,
142
145
  expandDotSyntax: true,
143
146
  unwindArrayFields: true,
144
147
  requireReadAccess: true,
@@ -184,7 +187,7 @@ function getMongooseFields(schema, options) {
184
187
 
185
188
  // Exported for testing
186
189
  export function getValidationSchema(attributes, options = {}) {
187
- const { appendSchema, assertUniqueOptions, allowIncludes } = options;
190
+ const { appendSchema, assertUniqueOptions, allowInclude } = options;
188
191
  let schema = getObjectSchema(attributes, options);
189
192
  if (assertUniqueOptions) {
190
193
  schema = schema.custom(async (obj, { root }) => {
@@ -197,7 +200,7 @@ export function getValidationSchema(attributes, options = {}) {
197
200
  if (appendSchema) {
198
201
  schema = schema.append(appendSchema);
199
202
  }
200
- if (allowIncludes) {
203
+ if (allowInclude) {
201
204
  schema = schema.append(INCLUDE_FIELD_SCHEMA);
202
205
  }
203
206
  return schema;
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,oEA8EC;AAsBD,wEAkBC;AA6QD;;;EAEC;AAED;;;EAOC;AAjdD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,oEAiFC;AAsBD,wEAkBC;AA6QD;;;EAEC;AAED;;;EAOC;AApdD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}