From 8b4b130c4c4650af53fded56ff21a6de3b175aea Mon Sep 17 00:00:00 2001 From: harryadel Date: Sun, 24 Dec 2023 17:35:05 +0200 Subject: [PATCH] Remove clean options --- README.md | 20 -------------------- package/collection2/collection2.js | 9 --------- tests/defaultCleanOptions.tests.js | 29 ----------------------------- 3 files changed, 58 deletions(-) delete mode 100644 tests/defaultCleanOptions.tests.js diff --git a/README.md b/README.md index b948fe8..215f56c 100644 --- a/README.md +++ b/README.md @@ -361,26 +361,6 @@ instance for a Mongo.Collection instance. For example: MyCollection.simpleSchema().validate(doc); ``` -## Schema Clean Options - -You can set the simpl-schema clean options globally in collection2. They are merged with any options defined on the schema level. - -```js -import Collection2 from 'meteor/aldeed:collection2' - -// The values shown are the default options used internally. Overwrite them if needed. -Collection2.cleanOptions = { - filter: true, - autoConvert: true, - removeEmptyStrings: true, - trimStrings: true, - removeNullsFromArrays: true, -} - -// Or you can update individual options. -Collection2.cleanOptions.filter = false; -``` - ## Passing Options In Meteor, the `update` function accepts an options argument. Collection2 changes the `insert` function signature to also accept options in the same way, as an optional second argument. Whenever this documentation says to "use X option", it's referring to this options argument. For example: diff --git a/package/collection2/collection2.js b/package/collection2/collection2.js index 7910cd6..abb4314 100644 --- a/package/collection2/collection2.js +++ b/package/collection2/collection2.js @@ -17,13 +17,6 @@ const SimpleSchema = require('simpl-schema').default; // Exported only for listening to events const Collection2 = new EventEmitter(); -Collection2.cleanOptions = { - filter: true, - autoConvert: true, - removeEmptyStrings: true, - trimStrings: true, - removeNullsFromArrays: false -}; /** * Mongo.Collection.prototype.attachSchema @@ -472,8 +465,6 @@ function doValidate(collection, type, args, getAutoValues, userId, isFromTrusted schema.clean(doc, { mutate: true, // Clean the doc/modifier in place isModifier: !isInsertType(type), - // Start with some Collection2 defaults, which will usually be overwritten - ...Collection2.cleanOptions, // The extent with the schema-level defaults (from SimpleSchema constructor options) ...(schema._cleanOptions || {}), // Finally, options for this specific operation should take precedence diff --git a/tests/defaultCleanOptions.tests.js b/tests/defaultCleanOptions.tests.js deleted file mode 100644 index 30b797e..0000000 --- a/tests/defaultCleanOptions.tests.js +++ /dev/null @@ -1,29 +0,0 @@ -import expect from 'expect'; -import Collection2 from 'meteor/aldeed:collection2'; - -/* global it describe */ - -describe('cleanOptions', function () { - it('comes preloaded with default values', function () { - expect(Collection2.cleanOptions).toEqual({ - filter: true, - autoConvert: true, - removeEmptyStrings: true, - trimStrings: true, - removeNullsFromArrays: false - }); - }); - - it('allows setting cleanOptions', function () { - const cleanOptions = { - filter: false, - autoConvert: false, - removeEmptyStrings: false, - trimStrings: false, - removeNullsFromArrays: false - }; - - Collection2.cleanOptions = cleanOptions; - expect(Collection2.cleanOptions).toEqual(cleanOptions); - }); -});