@bedrockio/model 0.14.3 → 0.14.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 +4 -0
- package/dist/cjs/validation.js +7 -8
- package/package.json +1 -1
- package/src/validation.js +7 -8
- package/types/schema.d.ts +5 -8
- package/types/schema.d.ts.map +1 -1
- package/types/validation.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/validation.js
CHANGED
|
@@ -10,7 +10,6 @@ exports.getTupleValidator = getTupleValidator;
|
|
|
10
10
|
exports.getValidationSchema = getValidationSchema;
|
|
11
11
|
var _yada = _interopRequireDefault(require("@bedrockio/yada"));
|
|
12
12
|
var _lodash = require("lodash");
|
|
13
|
-
var _mongoose = _interopRequireDefault(require("mongoose"));
|
|
14
13
|
var _access = require("./access");
|
|
15
14
|
var _errors = require("./errors");
|
|
16
15
|
var _include = require("./include");
|
|
@@ -59,7 +58,7 @@ function addValidators(schemas) {
|
|
|
59
58
|
}
|
|
60
59
|
function applyValidation(schema, definition) {
|
|
61
60
|
schema.static('getCreateValidation', function getCreateValidation(options) {
|
|
62
|
-
return
|
|
61
|
+
return getSchemaForMongoose(schema, {
|
|
63
62
|
model: this,
|
|
64
63
|
stripEmpty: true,
|
|
65
64
|
applyUnique: true,
|
|
@@ -73,7 +72,7 @@ function applyValidation(schema, definition) {
|
|
|
73
72
|
});
|
|
74
73
|
});
|
|
75
74
|
schema.static('getUpdateValidation', function getUpdateValidation(options) {
|
|
76
|
-
return
|
|
75
|
+
return getSchemaForMongoose(schema, {
|
|
77
76
|
model: this,
|
|
78
77
|
allowNull: true,
|
|
79
78
|
applyUnique: true,
|
|
@@ -96,7 +95,7 @@ function applyValidation(schema, definition) {
|
|
|
96
95
|
formats,
|
|
97
96
|
...rest
|
|
98
97
|
} = options;
|
|
99
|
-
let validation =
|
|
98
|
+
let validation = getSchemaForMongoose(schema, {
|
|
100
99
|
model: this,
|
|
101
100
|
allowNull: true,
|
|
102
101
|
stripEmpty: true,
|
|
@@ -132,7 +131,7 @@ function applyValidation(schema, definition) {
|
|
|
132
131
|
return _include.INCLUDE_FIELD_SCHEMA;
|
|
133
132
|
});
|
|
134
133
|
schema.static('getBaseSchema', function getBaseSchema() {
|
|
135
|
-
return
|
|
134
|
+
return getSchemaForMongoose(schema, {
|
|
136
135
|
model: this,
|
|
137
136
|
stripDeleted: true,
|
|
138
137
|
requireReadAccess: true
|
|
@@ -142,7 +141,7 @@ function applyValidation(schema, definition) {
|
|
|
142
141
|
|
|
143
142
|
// Yada schemas
|
|
144
143
|
|
|
145
|
-
function
|
|
144
|
+
function getSchemaForMongoose(schema, options = {}) {
|
|
146
145
|
const fields = getMongooseFields(schema, options);
|
|
147
146
|
return getValidationSchema(fields, options);
|
|
148
147
|
}
|
|
@@ -182,7 +181,7 @@ function getValidationSchema(attributes, options = {}) {
|
|
|
182
181
|
function getObjectSchema(arg, options) {
|
|
183
182
|
if ((0, _utils.isSchemaTypedef)(arg)) {
|
|
184
183
|
return getSchemaForTypedef(arg, options);
|
|
185
|
-
} else if (
|
|
184
|
+
} else if ((0, _utils.isMongooseSchema)(arg)) {
|
|
186
185
|
return getObjectSchema(arg.obj, options);
|
|
187
186
|
} else if (Array.isArray(arg)) {
|
|
188
187
|
return getArraySchema(arg, options);
|
|
@@ -244,7 +243,7 @@ function getSchemaForTypedef(typedef, options = {}) {
|
|
|
244
243
|
} = typedef;
|
|
245
244
|
let schema;
|
|
246
245
|
if ((0, _utils.isMongooseSchema)(type)) {
|
|
247
|
-
schema =
|
|
246
|
+
schema = getObjectSchema(type, options);
|
|
248
247
|
} else if (Array.isArray(type)) {
|
|
249
248
|
schema = getArraySchema(type, options);
|
|
250
249
|
} else if (typeof type === 'object') {
|
package/package.json
CHANGED
package/src/validation.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import yd from '@bedrockio/yada';
|
|
2
2
|
import { get, lowerFirst, omit } from 'lodash';
|
|
3
|
-
import mongoose from 'mongoose';
|
|
4
3
|
|
|
5
4
|
import { hasAccess } from './access';
|
|
6
5
|
import { ImplementationError, PermissionsError } from './errors';
|
|
@@ -62,7 +61,7 @@ export function addValidators(schemas) {
|
|
|
62
61
|
|
|
63
62
|
export function applyValidation(schema, definition) {
|
|
64
63
|
schema.static('getCreateValidation', function getCreateValidation(options) {
|
|
65
|
-
return
|
|
64
|
+
return getSchemaForMongoose(schema, {
|
|
66
65
|
model: this,
|
|
67
66
|
stripEmpty: true,
|
|
68
67
|
applyUnique: true,
|
|
@@ -77,7 +76,7 @@ export function applyValidation(schema, definition) {
|
|
|
77
76
|
});
|
|
78
77
|
|
|
79
78
|
schema.static('getUpdateValidation', function getUpdateValidation(options) {
|
|
80
|
-
return
|
|
79
|
+
return getSchemaForMongoose(schema, {
|
|
81
80
|
model: this,
|
|
82
81
|
allowNull: true,
|
|
83
82
|
applyUnique: true,
|
|
@@ -99,7 +98,7 @@ export function applyValidation(schema, definition) {
|
|
|
99
98
|
function getSearchValidation(options = {}) {
|
|
100
99
|
const { allowExport, defaults, formats, ...rest } = options;
|
|
101
100
|
|
|
102
|
-
let validation =
|
|
101
|
+
let validation = getSchemaForMongoose(schema, {
|
|
103
102
|
model: this,
|
|
104
103
|
allowNull: true,
|
|
105
104
|
stripEmpty: true,
|
|
@@ -146,7 +145,7 @@ export function applyValidation(schema, definition) {
|
|
|
146
145
|
});
|
|
147
146
|
|
|
148
147
|
schema.static('getBaseSchema', function getBaseSchema() {
|
|
149
|
-
return
|
|
148
|
+
return getSchemaForMongoose(schema, {
|
|
150
149
|
model: this,
|
|
151
150
|
stripDeleted: true,
|
|
152
151
|
requireReadAccess: true,
|
|
@@ -156,7 +155,7 @@ export function applyValidation(schema, definition) {
|
|
|
156
155
|
|
|
157
156
|
// Yada schemas
|
|
158
157
|
|
|
159
|
-
function
|
|
158
|
+
function getSchemaForMongoose(schema, options = {}) {
|
|
160
159
|
const fields = getMongooseFields(schema, options);
|
|
161
160
|
return getValidationSchema(fields, options);
|
|
162
161
|
}
|
|
@@ -196,7 +195,7 @@ export function getValidationSchema(attributes, options = {}) {
|
|
|
196
195
|
function getObjectSchema(arg, options) {
|
|
197
196
|
if (isSchemaTypedef(arg)) {
|
|
198
197
|
return getSchemaForTypedef(arg, options);
|
|
199
|
-
} else if (arg
|
|
198
|
+
} else if (isMongooseSchema(arg)) {
|
|
200
199
|
return getObjectSchema(arg.obj, options);
|
|
201
200
|
} else if (Array.isArray(arg)) {
|
|
202
201
|
return getArraySchema(arg, options);
|
|
@@ -261,7 +260,7 @@ function getSchemaForTypedef(typedef, options = {}) {
|
|
|
261
260
|
let schema;
|
|
262
261
|
|
|
263
262
|
if (isMongooseSchema(type)) {
|
|
264
|
-
schema =
|
|
263
|
+
schema = getObjectSchema(type, options);
|
|
265
264
|
} else if (Array.isArray(type)) {
|
|
266
265
|
schema = getArraySchema(type, options);
|
|
267
266
|
} else if (typeof type === 'object') {
|
package/types/schema.d.ts
CHANGED
|
@@ -28,9 +28,7 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
|
|
|
28
28
|
id?: boolean;
|
|
29
29
|
_id?: boolean;
|
|
30
30
|
minimize?: boolean;
|
|
31
|
-
optimisticConcurrency?: boolean
|
|
32
|
-
exclude: string[];
|
|
33
|
-
};
|
|
31
|
+
optimisticConcurrency?: boolean;
|
|
34
32
|
pluginTags?: string[];
|
|
35
33
|
read?: string;
|
|
36
34
|
readConcern?: {
|
|
@@ -49,16 +47,16 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
|
|
|
49
47
|
getters: boolean;
|
|
50
48
|
versionKey: boolean;
|
|
51
49
|
transform: (doc: any, ret: any, options: any) => void;
|
|
52
|
-
} | mongoose.ToObjectOptions<any
|
|
50
|
+
} | mongoose.ToObjectOptions<any>;
|
|
53
51
|
toObject: {
|
|
54
52
|
getters: boolean;
|
|
55
53
|
versionKey: boolean;
|
|
56
54
|
transform: (doc: any, ret: any, options: any) => void;
|
|
57
|
-
} | mongoose.ToObjectOptions<any
|
|
55
|
+
} | mongoose.ToObjectOptions<any>;
|
|
58
56
|
typeKey?: string;
|
|
59
57
|
validateBeforeSave?: boolean;
|
|
60
58
|
validateModifiedOnly?: boolean;
|
|
61
|
-
versionKey?: string |
|
|
59
|
+
versionKey?: string | boolean;
|
|
62
60
|
selectPopulatedPaths?: boolean;
|
|
63
61
|
skipVersioning?: {
|
|
64
62
|
[key: string]: boolean;
|
|
@@ -66,13 +64,12 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
|
|
|
66
64
|
storeSubdocValidationError?: boolean;
|
|
67
65
|
timestamps: boolean | mongoose.SchemaTimestampsConfig;
|
|
68
66
|
suppressReservedKeysWarning?: boolean;
|
|
69
|
-
statics?: mongoose.AddThisParameter<any, mongoose.Model<any,
|
|
67
|
+
statics?: mongoose.AddThisParameter<any, mongoose.Model<any, {}, {}, {}, any, any>>;
|
|
70
68
|
methods?: mongoose.AddThisParameter<any, any> & mongoose.AnyObject;
|
|
71
69
|
query?: any;
|
|
72
70
|
castNonArrays?: boolean;
|
|
73
71
|
virtuals?: mongoose.SchemaOptionsVirtualsPropertyType<any, any, any>;
|
|
74
72
|
overwriteModels?: boolean;
|
|
75
|
-
encryptionType?: "csfle" | "queryableEncryption";
|
|
76
73
|
}, any, any>;
|
|
77
74
|
export function normalizeAttributes(arg: any, path?: any[]): any;
|
|
78
75
|
import mongoose from 'mongoose';
|
package/types/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAuBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAuBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,QAAQ,CAAC,aAAa;;;;;;;YA6CQ,CAAA;WACvC,CAAD;mBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;SAiHX,CAAC;gBAA4B,CAAA;SAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aApHpD;AAED,iEAsBC;qBA9FoB,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAyDA,kDAEC;AAED,oEA4FC;AAsBD,wEAiBC;AA8SD;;;EAEC;AAED;;;EAOC"}
|