@orion-js/schema 3.1.1 → 3.1.27

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Orionjs Team
3
+ Copyright (c) 2022 Orionjs Team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,2 +1,2 @@
1
- import { CurrentNodeInfoOptions, Schema } from '../types/schema';
2
- export default function clean(schema: Schema | Function, doc?: {}, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<Schema>;
1
+ import { Blackbox, CurrentNodeInfoOptions, Schema } from '../types/schema';
2
+ export default function clean<TDoc = Blackbox>(schema: Schema | Function, doc: TDoc, opts?: CurrentNodeInfoOptions, ...args: any[]): Promise<TDoc>;
@@ -11,7 +11,9 @@ const defaultOptions = {
11
11
  trimStrings: true,
12
12
  removeEmptyStrings: false
13
13
  };
14
- async function clean(schema, doc = {}, opts = {}, ...args) {
14
+ async function clean(schema, doc, opts = {}, ...args) {
15
+ if (!doc)
16
+ return doc;
15
17
  schema = (0, getSchemaFromTypedModel_1.getSchemaFromTypedModel)(schema);
16
18
  const options = { ...defaultOptions, ...opts };
17
19
  const params = {
@@ -143,7 +143,7 @@ test('run autovalue when field is not present', async () => {
143
143
  const schema = {
144
144
  text: {
145
145
  type: String,
146
- autoValue(values) {
146
+ autoValue() {
147
147
  return 'a value';
148
148
  }
149
149
  }
@@ -266,7 +266,7 @@ test('perform custom cleaning', async () => {
266
266
  type: [person]
267
267
  }
268
268
  };
269
- // @ts-ignore TODO: Check why the __clean method is being used here instead of clean
269
+ // TODO: Check why the __clean method is being used here instead of clean
270
270
  const cleaned = await (0, index_1.default)(schema, {
271
271
  persons: [{ name: 'Nicolás' }, { name: 'Joaquin' }]
272
272
  });
@@ -288,7 +288,7 @@ test('perform non deep custom cleaning', async () => {
288
288
  }
289
289
  }
290
290
  };
291
- // @ts-ignore TODO: Check why the __clean method is being used here instead of clean
291
+ // TODO: Check why the __clean method is being used here instead of clean
292
292
  const cleaned = await (0, index_1.default)(schema, { name: 'Joaquin' });
293
293
  expect(cleaned).toEqual({ name: 'Roberto' });
294
294
  });
@@ -296,7 +296,7 @@ test('Handle errors while cleaning', async () => {
296
296
  const schema = {
297
297
  name: {
298
298
  type: String,
299
- async autoValue(value) {
299
+ async autoValue() {
300
300
  throw new Error('an error');
301
301
  }
302
302
  }
@@ -347,7 +347,7 @@ test('omit undefined items in array', async () => {
347
347
  type: [item]
348
348
  }
349
349
  };
350
- // @ts-ignore TODO: Check why the __clean method is being used here instead of clean
350
+ // TODO: Check why the __clean method is being used here instead of clean
351
351
  const result = await (0, index_1.default)(schema, doc);
352
352
  expect(result).toEqual({ items: [] });
353
353
  });
@@ -372,14 +372,14 @@ test('throws error when cleaning field with no type', async () => {
372
372
  const schema = {
373
373
  name: {
374
374
  type: null,
375
- autoValue(name, info, arg1, arg2) {
375
+ autoValue() {
376
376
  return 'Nicolás';
377
377
  }
378
378
  }
379
379
  };
380
380
  expect.assertions(1);
381
381
  try {
382
- await (0, index_1.default)(schema);
382
+ await (0, index_1.default)(schema, {});
383
383
  }
384
384
  catch (error) {
385
385
  expect(error.message).toBe('Error cleaning field name, error: Cleaning field with no type');
@@ -389,12 +389,12 @@ test('cleans when no argument is passed', async () => {
389
389
  const schema = {
390
390
  name: {
391
391
  type: String,
392
- autoValue(name, info, arg1, arg2) {
392
+ autoValue() {
393
393
  return 'Nicolás';
394
394
  }
395
395
  }
396
396
  };
397
- const result = await (0, index_1.default)(schema);
397
+ const result = await (0, index_1.default)(schema, {});
398
398
  expect(result).toEqual({ name: 'Nicolás' });
399
399
  });
400
400
  test('pass currentDoc cleaning complex schemas', async () => {
@@ -428,7 +428,7 @@ test('pass currentDoc cleaning complex schemas', async () => {
428
428
  },
429
429
  car: {
430
430
  type: car,
431
- async autoValue(value, { currentDoc, doc }) {
431
+ async autoValue(value, { currentDoc }) {
432
432
  expect(value).toEqual(aMom.car);
433
433
  expect(currentDoc).toEqual(aMom);
434
434
  return value;
@@ -464,7 +464,7 @@ test('pass currentDoc cleaning complex schemas', async () => {
464
464
  }
465
465
  };
466
466
  expect.assertions(14);
467
- // @ts-ignore TODO: Check why the __clean method is being used here instead of clean
467
+ // TODO: Check why the __clean method is being used here instead of clean
468
468
  await (0, index_1.default)(schema, doc);
469
469
  });
470
470
  test('On blackbox allow use of custom clean', async () => {
@@ -472,7 +472,7 @@ test('On blackbox allow use of custom clean', async () => {
472
472
  info: {
473
473
  type: 'blackbox',
474
474
  optional: true,
475
- async clean(info, { doc }) {
475
+ async clean() {
476
476
  return { hello: 'world' };
477
477
  }
478
478
  }
@@ -1,5 +1,8 @@
1
1
  import { FieldType } from '../fieldType';
2
2
  export declare type Constructor<T> = new (...args: any[]) => T;
3
+ export declare type Blackbox = {
4
+ [name: string]: any;
5
+ };
3
6
  export declare type FieldTypesList = 'string' | 'date' | 'integer' | 'number' | 'ID' | 'boolean' | 'email' | 'blackbox';
4
7
  export declare type TypedModelOnSchema = Function;
5
8
  export declare type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/schema",
3
- "version": "3.1.1",
3
+ "version": "3.1.27",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "776fc314f67ab21707912ebeadc9ed8b525cbaee"
39
+ "gitHead": "c06da218f6f386d088a36f0a34f2a8194e065ac0"
40
40
  }