@bedrockio/model 0.1.22 → 0.1.24
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/.prettierrc.cjs +1 -0
- package/dist/cjs/schema.js +12 -4
- package/dist/cjs/validation.js +15 -6
- package/package.json +1 -1
- package/src/schema.js +12 -4
- package/src/validation.js +9 -6
- package/types/validation.d.ts.map +1 -1
package/.prettierrc.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@bedrockio/prettier-config');
|
package/dist/cjs/schema.js
CHANGED
|
@@ -221,10 +221,18 @@ function applyScopeExtension(scope, definition) {
|
|
|
221
221
|
...options
|
|
222
222
|
} = scope;
|
|
223
223
|
for (let [key, val] of Object.entries(normalizeAttributes(attributes))) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
if ((0, _utils.isSchemaTypedef)(val)) {
|
|
225
|
+
definition[key] = {
|
|
226
|
+
...val,
|
|
227
|
+
...options
|
|
228
|
+
};
|
|
229
|
+
} else {
|
|
230
|
+
definition[key] = {
|
|
231
|
+
type: 'Object',
|
|
232
|
+
attributes: val,
|
|
233
|
+
...options
|
|
234
|
+
};
|
|
235
|
+
}
|
|
228
236
|
}
|
|
229
237
|
}
|
|
230
238
|
|
package/dist/cjs/validation.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
195
|
+
if (allowInclude) {
|
|
187
196
|
schema = schema.append(_include.INCLUDE_FIELD_SCHEMA);
|
|
188
197
|
}
|
|
189
198
|
return schema;
|
package/package.json
CHANGED
package/src/schema.js
CHANGED
|
@@ -230,10 +230,18 @@ function isScopeExtension(obj) {
|
|
|
230
230
|
function applyScopeExtension(scope, definition) {
|
|
231
231
|
const { type, attributes, ...options } = scope;
|
|
232
232
|
for (let [key, val] of Object.entries(normalizeAttributes(attributes))) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
if (isSchemaTypedef(val)) {
|
|
234
|
+
definition[key] = {
|
|
235
|
+
...val,
|
|
236
|
+
...options,
|
|
237
|
+
};
|
|
238
|
+
} else {
|
|
239
|
+
definition[key] = {
|
|
240
|
+
type: 'Object',
|
|
241
|
+
attributes: val,
|
|
242
|
+
...options,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
237
245
|
}
|
|
238
246
|
}
|
|
239
247
|
|
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(
|
|
91
|
+
function getCreateValidation(options = {}) {
|
|
92
|
+
const { allowInclude, ...appendSchema } = options;
|
|
92
93
|
return getSchemaFromMongoose(schema, {
|
|
93
94
|
model: this,
|
|
94
95
|
appendSchema,
|
|
95
|
-
|
|
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(
|
|
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
|
-
|
|
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,
|
|
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 (
|
|
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,
|
|
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"}
|