@aeriajs/validation 0.0.134 → 0.0.135

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.
@@ -9,7 +9,7 @@ export type ValidateOptions = {
9
9
  };
10
10
  export declare const makeValidationError: <TValidationError extends ValidationError>(error: TValidationError) => TValidationError;
11
11
  export declare const validateProperty: <TWhat>(what: TWhat, property: Property | undefined, options?: ValidateOptions) => Result.Either<PropertyValidationError | ValidationError, unknown>;
12
- export declare const validateRefs: <TWhat>(what: TWhat, property: Property | undefined, descriptions?: Record<string, Description>) => Promise<Result.Either<PropertyValidationError | ValidationError, unknown>>;
12
+ export declare const validateRefs: <TWhat>(what: TWhat, property: Property | Description, descriptions?: Record<string, Description>) => Promise<Result.Either<PropertyValidationError | ValidationError, unknown>>;
13
13
  export declare const validateWholeness: (what: Record<string, unknown>, schema: Omit<JsonSchema, "$id">) => {
14
14
  code: ValidationErrorCode.MissingProperties;
15
15
  errors: {
package/dist/validate.js CHANGED
@@ -190,53 +190,51 @@ const validateProperty = (what, property, options = {}) => {
190
190
  };
191
191
  exports.validateProperty = validateProperty;
192
192
  const validateRefs = async (what, property, descriptions) => {
193
- if (property) {
194
- if ('$ref' in property) {
195
- let description;
196
- if (descriptions) {
197
- description = descriptions[property.$ref];
198
- }
199
- else {
200
- const collection = await (0, entrypoint_1.getCollection)(property.$ref);
201
- if (!collection) {
202
- throw new Error;
203
- }
204
- description = collection.description;
205
- }
206
- if (typeof what !== 'object') {
207
- return types_1.Result.error(makePropertyError(types_2.PropertyValidationErrorCode.Unmatching, {
208
- expected: 'object',
209
- got: typeof what,
210
- }));
211
- }
212
- return (0, exports.validate)(what, description);
193
+ if ('$ref' in property) {
194
+ let description;
195
+ if (descriptions) {
196
+ description = descriptions[property.$ref];
213
197
  }
214
- else if ('items' in property) {
215
- if (!Array.isArray(what)) {
198
+ else {
199
+ const collection = await (0, entrypoint_1.getCollection)(property.$ref);
200
+ if (!collection) {
216
201
  throw new Error;
217
202
  }
218
- for (const elem of what) {
219
- const { error } = await (0, exports.validateRefs)(elem, property.items, descriptions);
220
- if (error) {
221
- return types_1.Result.error(error);
222
- }
223
- }
203
+ description = collection.description;
224
204
  }
225
- else if ('properties' in property) {
226
- const errors = {};
227
- for (const propName in what) {
228
- const { error } = await (0, exports.validateRefs)(what[propName], property.properties[propName], descriptions);
229
- if (error) {
230
- errors[propName] = error;
231
- }
205
+ if (typeof what !== 'object') {
206
+ return types_1.Result.error(makePropertyError(types_2.PropertyValidationErrorCode.Unmatching, {
207
+ expected: 'object',
208
+ got: typeof what,
209
+ }));
210
+ }
211
+ return (0, exports.validate)(what, description);
212
+ }
213
+ else if ('items' in property) {
214
+ if (!Array.isArray(what)) {
215
+ throw new Error;
216
+ }
217
+ for (const elem of what) {
218
+ const { error } = await (0, exports.validateRefs)(elem, property.items, descriptions);
219
+ if (error) {
220
+ return types_1.Result.error(error);
232
221
  }
233
- if (Object.keys(errors).length > 0) {
234
- return types_1.Result.error((0, exports.makeValidationError)({
235
- code: types_2.ValidationErrorCode.InvalidProperties,
236
- errors,
237
- }));
222
+ }
223
+ }
224
+ else if ('properties' in property) {
225
+ const errors = {};
226
+ for (const propName in what) {
227
+ const { error } = await (0, exports.validateRefs)(what[propName], property.properties[propName], descriptions);
228
+ if (error) {
229
+ errors[propName] = error;
238
230
  }
239
231
  }
232
+ if (Object.keys(errors).length > 0) {
233
+ return types_1.Result.error((0, exports.makeValidationError)({
234
+ code: types_2.ValidationErrorCode.InvalidProperties,
235
+ errors,
236
+ }));
237
+ }
240
238
  }
241
239
  return types_1.Result.result({});
242
240
  };
package/dist/validate.mjs CHANGED
@@ -178,50 +178,48 @@ export const validateProperty = (what, property, options = {}) => {
178
178
  return Result.result(what);
179
179
  };
180
180
  export const validateRefs = async (what, property, descriptions) => {
181
- if (property) {
182
- if ("$ref" in property) {
183
- let description;
184
- if (descriptions) {
185
- description = descriptions[property.$ref];
186
- } else {
187
- const collection = await getCollection(property.$ref);
188
- if (!collection) {
189
- throw new Error();
190
- }
191
- description = collection.description;
192
- }
193
- if (typeof what !== "object") {
194
- return Result.error(makePropertyError(PropertyValidationErrorCode.Unmatching, {
195
- expected: "object",
196
- got: typeof what
197
- }));
198
- }
199
- return validate(what, description);
200
- } else if ("items" in property) {
201
- if (!Array.isArray(what)) {
181
+ if ("$ref" in property) {
182
+ let description;
183
+ if (descriptions) {
184
+ description = descriptions[property.$ref];
185
+ } else {
186
+ const collection = await getCollection(property.$ref);
187
+ if (!collection) {
202
188
  throw new Error();
203
189
  }
204
- for (const elem of what) {
205
- const { error } = await validateRefs(elem, property.items, descriptions);
206
- if (error) {
207
- return Result.error(error);
208
- }
209
- }
210
- } else if ("properties" in property) {
211
- const errors = {};
212
- for (const propName in what) {
213
- const { error } = await validateRefs(what[propName], property.properties[propName], descriptions);
214
- if (error) {
215
- errors[propName] = error;
216
- }
190
+ description = collection.description;
191
+ }
192
+ if (typeof what !== "object") {
193
+ return Result.error(makePropertyError(PropertyValidationErrorCode.Unmatching, {
194
+ expected: "object",
195
+ got: typeof what
196
+ }));
197
+ }
198
+ return validate(what, description);
199
+ } else if ("items" in property) {
200
+ if (!Array.isArray(what)) {
201
+ throw new Error();
202
+ }
203
+ for (const elem of what) {
204
+ const { error } = await validateRefs(elem, property.items, descriptions);
205
+ if (error) {
206
+ return Result.error(error);
217
207
  }
218
- if (Object.keys(errors).length > 0) {
219
- return Result.error(makeValidationError({
220
- code: ValidationErrorCode.InvalidProperties,
221
- errors
222
- }));
208
+ }
209
+ } else if ("properties" in property) {
210
+ const errors = {};
211
+ for (const propName in what) {
212
+ const { error } = await validateRefs(what[propName], property.properties[propName], descriptions);
213
+ if (error) {
214
+ errors[propName] = error;
223
215
  }
224
216
  }
217
+ if (Object.keys(errors).length > 0) {
218
+ return Result.error(makeValidationError({
219
+ code: ValidationErrorCode.InvalidProperties,
220
+ errors
221
+ }));
222
+ }
225
223
  }
226
224
  return Result.result({});
227
225
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/validation",
3
- "version": "0.0.134",
3
+ "version": "0.0.135",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",