@aeriajs/validation 0.0.176 → 0.0.178

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/dist/validate.js CHANGED
@@ -116,19 +116,34 @@ const validateProperty = (what, property, options = {}) => {
116
116
  if ('type' in property) {
117
117
  switch (property.type) {
118
118
  case 'string': {
119
- if (typeof what !== 'string') {
120
- return types_1.Result.error(makePropertyError(types_1.PropertyValidationErrorCode.Unmatching, {
121
- expected: expectedType,
122
- got: actualType,
123
- }));
124
- }
125
- if ((property.format === 'objectid' && !isValidObjectId(what))
126
- || (typeof property.minLength === 'number' && property.minLength > what.length)
127
- || (typeof property.maxLength === 'number' && property.maxLength < what.length)) {
128
- return types_1.Result.error(makePropertyError(types_1.PropertyValidationErrorCode.StringConstraint, {
129
- expected: 'string',
130
- got: 'invalid_string',
131
- }));
119
+ switch (property.format) {
120
+ case 'objectid': {
121
+ if (!options.objectIdConstructor) {
122
+ throw new Error;
123
+ }
124
+ if (!(what instanceof options.objectIdConstructor)) {
125
+ return types_1.Result.error(makePropertyError(types_1.PropertyValidationErrorCode.StringConstraint, {
126
+ expected: 'objectid',
127
+ got: 'invalid_objectid',
128
+ }));
129
+ }
130
+ break;
131
+ }
132
+ default: {
133
+ if (typeof what !== 'string') {
134
+ return types_1.Result.error(makePropertyError(types_1.PropertyValidationErrorCode.Unmatching, {
135
+ expected: expectedType,
136
+ got: actualType,
137
+ }));
138
+ }
139
+ if ((typeof property.minLength === 'number' && property.minLength > what.length)
140
+ || (typeof property.maxLength === 'number' && property.maxLength < what.length)) {
141
+ return types_1.Result.error(makePropertyError(types_1.PropertyValidationErrorCode.StringConstraint, {
142
+ expected: 'string',
143
+ got: 'invalid_string',
144
+ }));
145
+ }
146
+ }
132
147
  }
133
148
  break;
134
149
  }
package/dist/validate.mjs CHANGED
@@ -108,17 +108,33 @@ export const validateProperty = (what, property, options = {}) => {
108
108
  if ("type" in property) {
109
109
  switch (property.type) {
110
110
  case "string": {
111
- if (typeof what !== "string") {
112
- return Result.error(makePropertyError(PropertyValidationErrorCode.Unmatching, {
113
- expected: expectedType,
114
- got: actualType
115
- }));
116
- }
117
- if (property.format === "objectid" && !isValidObjectId(what) || typeof property.minLength === "number" && property.minLength > what.length || typeof property.maxLength === "number" && property.maxLength < what.length) {
118
- return Result.error(makePropertyError(PropertyValidationErrorCode.StringConstraint, {
119
- expected: "string",
120
- got: "invalid_string"
121
- }));
111
+ switch (property.format) {
112
+ case "objectid": {
113
+ if (!options.objectIdConstructor) {
114
+ throw new Error();
115
+ }
116
+ if (!(what instanceof options.objectIdConstructor)) {
117
+ return Result.error(makePropertyError(PropertyValidationErrorCode.StringConstraint, {
118
+ expected: "objectid",
119
+ got: "invalid_objectid"
120
+ }));
121
+ }
122
+ break;
123
+ }
124
+ default: {
125
+ if (typeof what !== "string") {
126
+ return Result.error(makePropertyError(PropertyValidationErrorCode.Unmatching, {
127
+ expected: expectedType,
128
+ got: actualType
129
+ }));
130
+ }
131
+ if (typeof property.minLength === "number" && property.minLength > what.length || typeof property.maxLength === "number" && property.maxLength < what.length) {
132
+ return Result.error(makePropertyError(PropertyValidationErrorCode.StringConstraint, {
133
+ expected: "string",
134
+ got: "invalid_string"
135
+ }));
136
+ }
137
+ }
122
138
  }
123
139
  break;
124
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/validation",
3
- "version": "0.0.176",
3
+ "version": "0.0.178",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -28,9 +28,9 @@
28
28
  "mongodb": "^6.17.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@aeriajs/common": "^0.0.156",
32
- "@aeriajs/entrypoint": "^0.0.162",
33
- "@aeriajs/types": "^0.0.134",
31
+ "@aeriajs/common": "^0.0.157",
32
+ "@aeriajs/entrypoint": "^0.0.163",
33
+ "@aeriajs/types": "^0.0.135",
34
34
  "mongodb": "^6.17.0"
35
35
  },
36
36
  "scripts": {