@aeriajs/validation 0.0.135 → 0.0.137

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 | Description, descriptions?: Record<string, Description>) => Promise<Result.Either<PropertyValidationError | ValidationError, unknown>>;
12
+ export declare const validateRefs: <TWhat>(what: TWhat, property: Property | Description | undefined, options?: ValidateOptions, 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
@@ -189,51 +189,53 @@ const validateProperty = (what, property, options = {}) => {
189
189
  return types_1.Result.result(what);
190
190
  };
191
191
  exports.validateProperty = validateProperty;
192
- const validateRefs = async (what, property, descriptions) => {
193
- if ('$ref' in property) {
194
- let description;
195
- if (descriptions) {
196
- description = descriptions[property.$ref];
192
+ const validateRefs = async (what, property, options, 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);
197
213
  }
198
- else {
199
- const collection = await (0, entrypoint_1.getCollection)(property.$ref);
200
- if (!collection) {
214
+ else if ('items' in property) {
215
+ if (!Array.isArray(what)) {
201
216
  throw new Error;
202
217
  }
203
- description = collection.description;
204
- }
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);
218
+ for (const elem of what) {
219
+ const { error } = await (0, exports.validateRefs)(elem, property.items, options, descriptions);
220
+ if (error) {
221
+ return types_1.Result.error(error);
222
+ }
221
223
  }
222
224
  }
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;
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], options, descriptions);
229
+ if (error) {
230
+ errors[propName] = error;
231
+ }
232
+ }
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
+ }));
230
238
  }
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
239
  }
238
240
  }
239
241
  return types_1.Result.result({});
package/dist/validate.mjs CHANGED
@@ -177,48 +177,50 @@ export const validateProperty = (what, property, options = {}) => {
177
177
  }
178
178
  return Result.result(what);
179
179
  };
180
- export const validateRefs = async (what, property, descriptions) => {
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) {
180
+ export const validateRefs = async (what, property, options, 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)) {
188
202
  throw new Error();
189
203
  }
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);
204
+ for (const elem of what) {
205
+ const { error } = await validateRefs(elem, property.items, options, descriptions);
206
+ if (error) {
207
+ return Result.error(error);
208
+ }
207
209
  }
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;
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], options, descriptions);
214
+ if (error) {
215
+ errors[propName] = error;
216
+ }
217
+ }
218
+ if (Object.keys(errors).length > 0) {
219
+ return Result.error(makeValidationError({
220
+ code: ValidationErrorCode.InvalidProperties,
221
+ errors
222
+ }));
215
223
  }
216
- }
217
- if (Object.keys(errors).length > 0) {
218
- return Result.error(makeValidationError({
219
- code: ValidationErrorCode.InvalidProperties,
220
- errors
221
- }));
222
224
  }
223
225
  }
224
226
  return Result.result({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/validation",
3
- "version": "0.0.135",
3
+ "version": "0.0.137",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",