Skip to content

Commit

Permalink
Issue #3: Support validation function output wrapped in a JSON string
Browse files Browse the repository at this point in the history
Specified as either `--json-string` or `-j`, this command line option has the `make-validation-function` script output the validation function in a double-quoted string that is suitable for use as the value of a design document's `validate_doc_update` property.
  • Loading branch information
OldSneerJaw committed Mar 6, 2018
1 parent 629ec60 commit e759b49
Show file tree
Hide file tree
Showing 11 changed files with 1,298 additions and 95 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). All notable c
## [Unreleased]
### Added
- [#2](https://github.com/OldSneerJaw/couchster/issues/2): Option to allow any database member to write revisions for a specific document type
- [#3](https://github.com/OldSneerJaw/couchster/issues/3): Option to output a generated validation function as a single-line JSON string
- [#4](https://github.com/OldSneerJaw/couchster/issues/4): Allow a document with an unknown type to be deleted by an admin

## [0.1.0] - 2018-02-28
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ Or as a custom [script](https://docs.npmjs.com/misc/scripts) in your project's `
}
```

This will take the sync document definitions that are defined in `/path/to/my-document-definitions.js` and build a new validation function that is output to `/path/to/my-generated-validation-function.js`. The generated validation function contents can then be inserted into a CouchDB [design document](http://docs.couchdb.org/en/latest/ddocs/ddocs.html).
This will take the document definitions that are defined in `/path/to/my-document-definitions.js` and build a new validation function that is output to `/path/to/my-generated-validation-function.js`. Generated validation functions are compatible with all CouchDB 2.x versions.

Generated validation functions are compatible with all CouchDB 2.x versions.
Also, for convenience, the validation function can instead be output as a single line string to make it easier to insert it directly as the value of the `validate_doc_update` property in a CouchDB [design document](http://docs.couchdb.org/en/latest/ddocs/ddocs.html). For example:

```
node_modules/.bin/couchster --single-line /path/to/my-document-definitions.js /path/to/my-generated-validation-function-string.txt
```

### Validating

Expand Down Expand Up @@ -652,9 +656,9 @@ As you can see, the fragments can also reference functions (e.g. `myDocTypeFilte

### Helper functions

Custom code (e.g. type filters, custom validation functions, custom actions) within document definitions have access to some predefined functions for common operations:
Custom code (e.g. type filters, custom validation functions, custom actions) within document definitions have access to CouchDB's built in [utility functions](http://docs.couchdb.org/en/latest/query-server/javascript.html). In addition, couchster provides some predefined functions for common operations:

* `isDocumentMissingOrDeleted(candidate)`: Determines whether the given `candidate` document is either missing (i.e. `null` or `undefined`) or deleted (i.e. its `_deleted` property is `true`). Useful in cases where, for example, the old document (i.e. `oldDoc` parameter) is non-existant or deleted and you want to treat both cases as equivalent.
* `isDocumentMissingOrDeleted(candidate)`: Determines whether the given `candidate` document is either missing (i.e. `null` or `undefined`) or deleted (i.e. its `_deleted` property is `true`). A useful alternative to testing the value of the new document's `_deleted` property or whether the old document is `null`.
* `isValueNullOrUndefined(value)`: Determines whether the given `value` parameter is either `null` or `undefined`. In many cases, it is useful to treat both states the same.

# Testing
Expand Down
22 changes: 22 additions & 0 deletions lib/commander/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions lib/commander/REPOSITORY
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/tj/commander.js
1 change: 1 addition & 0 deletions lib/commander/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.14.1
Loading

0 comments on commit e759b49

Please sign in to comment.