@bedrockio/model 0.1.21 → 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.
- package/.prettierrc.cjs +1 -0
- package/dist/cjs/schema.js +10 -0
- package/dist/cjs/validation.js +15 -6
- package/package.json +1 -1
- package/src/schema.js +8 -0
- 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
|
@@ -180,6 +180,7 @@ function applyExtensions(typedef) {
|
|
|
180
180
|
applySyntaxExtensions(typedef);
|
|
181
181
|
applyUniqueExtension(typedef);
|
|
182
182
|
applyTupleExtension(typedef);
|
|
183
|
+
applyDateExtension(typedef);
|
|
183
184
|
}
|
|
184
185
|
function applySyntaxExtensions(typedef) {
|
|
185
186
|
const {
|
|
@@ -242,6 +243,15 @@ function applyTupleExtension(typedef) {
|
|
|
242
243
|
typedef.validate = (0, _validation.getTupleValidator)(type);
|
|
243
244
|
}
|
|
244
245
|
}
|
|
246
|
+
function applyDateExtension(typedef) {
|
|
247
|
+
const {
|
|
248
|
+
type,
|
|
249
|
+
default: defaultValue
|
|
250
|
+
} = typedef;
|
|
251
|
+
if (type === 'Date' && defaultValue === 'now') {
|
|
252
|
+
typedef.default = Date.now;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
245
255
|
|
|
246
256
|
// Intercepts "unique" options and changes to "softUnique".
|
|
247
257
|
function applyUniqueExtension(typedef) {
|
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
|
@@ -195,6 +195,7 @@ function applyExtensions(typedef) {
|
|
|
195
195
|
applySyntaxExtensions(typedef);
|
|
196
196
|
applyUniqueExtension(typedef);
|
|
197
197
|
applyTupleExtension(typedef);
|
|
198
|
+
applyDateExtension(typedef);
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
function applySyntaxExtensions(typedef) {
|
|
@@ -250,6 +251,13 @@ function applyTupleExtension(typedef) {
|
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
|
|
254
|
+
function applyDateExtension(typedef) {
|
|
255
|
+
const { type, default: defaultValue } = typedef;
|
|
256
|
+
if (type === 'Date' && defaultValue === 'now') {
|
|
257
|
+
typedef.default = Date.now;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
253
261
|
// Intercepts "unique" options and changes to "softUnique".
|
|
254
262
|
function applyUniqueExtension(typedef) {
|
|
255
263
|
if (typedef.unique === true) {
|
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"}
|