@orion-js/schema 3.1.6 → 3.2.0
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/lib/clean/index.d.ts +2 -2
- package/lib/clean/index.js +3 -1
- package/lib/clean/index.test.js +12 -12
- package/lib/types/schema.d.ts +3 -0
- package/package.json +2 -2
package/lib/clean/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CurrentNodeInfoOptions, Schema } from '../types/schema';
|
|
2
|
-
export default function clean(schema: Schema | Function, doc
|
|
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>;
|
package/lib/clean/index.js
CHANGED
|
@@ -11,7 +11,9 @@ const defaultOptions = {
|
|
|
11
11
|
trimStrings: true,
|
|
12
12
|
removeEmptyStrings: false
|
|
13
13
|
};
|
|
14
|
-
async function clean(schema, doc
|
|
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 = {
|
package/lib/clean/index.test.js
CHANGED
|
@@ -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(
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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(
|
|
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
|
-
//
|
|
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(
|
|
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(
|
|
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
|
|
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
|
-
//
|
|
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(
|
|
475
|
+
async clean() {
|
|
476
476
|
return { hello: 'world' };
|
|
477
477
|
}
|
|
478
478
|
}
|
package/lib/types/schema.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "3.2.0",
|
|
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": "
|
|
39
|
+
"gitHead": "683cc5a018d45654ddf1299ea28e291fc7367dee"
|
|
40
40
|
}
|