Utility to make building sync functions for Sync Gateway easier

Hot on the heels of the last release less than two weeks ago comes version 2.2.0 with several handy new features and enhancements:

  • Pass the --json-string or -j option to the command line utility to have synctos output the generated sync function enclosed in a single-line JSON-compatible string rather than as a long, multi-line JavaScript block. This results in a more compact representation that does not rely on the non-standard backtick character for multi-line strings in JSON and that reduces the clutter in a Sync Gateway configuration file.
  • Enforce an explicit document ID format for each document type as a regular expression via the documentIdRegexPattern constraint. For example, set the constraint to /^contact-info\.[a-zA-Z0-9_-]+$/ to ensure that new documents of the contactInfo type always have an ID that starts with contact-info, followed by a dot and an ID token.
  • The test-helper module has been deprecated in favour of the newly-introduced test-fixture-maker module, which does a better job of isolating test cases from each other while providing all the same features. Refer to the Testing section of the README for help getting started with it. The test-helper module will be removed in the next major release of synctos (i.e. 3.0.0).
  • While previous releases of synctos already generate sync functions that are fully compatible with Sync Gateway 2.0, this release improves that compatibility in some small ways. Most notably, because SG 2.0 uses a more recent version of the otto JavaScript engine, the jsonStringify helper function now simply acts as an alias for JSON.stringify when used in SG 2.0. The jsonStringify function continues to use a custom polyfill function for SG 1.x to maintain backward compatibility, however. In either case, the choice of which implementation to use is automatic and completely invisible to the user.

See the changelog for complete details.

Yesterday’s release of synctos introduced a showstopper bug for users of Sync Gateway 1.x. It has been corrected by today’s patch release of 2.2.1. Refer to the changelog for more information.

1 Like

A new release of synctos (2.3.0) earlier today brought several improvements and bug fixes. Some highlights:

  • There are a number of inconsistencies in the handling of dates by the JavaScript engine used by Sync Gateway (otto). This version drops the Date object in favour of new custom date validation and comparison logic for the date and datetime validation types. The new implementation is compliant with the ECMAScript specification for Date Time String Format and is validated by a comprehensive suite of tests.
  • Added a sync-function-writer module to the API to make it more feasible to invoke synctos programmatically, rather than via the command line
  • Meaningful stack traces are now produced when a test case that makes use of the test-fixture-maker module fails unexpectedly
  • It’s now possible to reset a test fixture (via the resetTestEnvironment function) to its pristine original state without having to completely reinstantiate it. This may seem like a small improvement, but it can make a JavaScript code editor’s autocompletion functionality more useful when a test fixture is instantiated at the same point at which it is declared. For example:
describe('My new sync function', function() {
  var testFixture = testFixtureMaker.initFromDocumentDefinitions('/path/to/my-doc-definitions.js');

  afterEach(function() {
    testFixture.resetTestEnvironment();
  });

  ...
});

Review the new release’s changelog for complete details.

1 Like

Today’s release notes for synctos 2.4.0 are short and sweet:

  • Support for Sync Gateway 2.0’s document expiry feature. Specify when documents will expire either as an absolute point in time (i.e. Unix timestamp, ISO 8601 date/time string or JavaScript Date object) or as a relative offset (i.e. number of seconds in the future).

You’ll find the changelog in the usual place.

A few handy new features were introduced in today’s release of synctos 2.5.0:

  • Ignore differences in letter case for values of the string validation type by using the mustEqualIgnoreCase constraint
  • Control the format of document attachment filenames by using the document-wide attachmentConstraints.filenameRegexPattern constraint and the attachmentReference validation type’s regexPattern constraint

Review the release’s changelog for details.

1 Like

Today’s release of synctos 2.6.0 is a big one. It consists of three powerful new features:

  • An option to skip validation of a property or element if its value has not changed since the document’s last revision. This can greatly ease the burden of migrating schema changes; no longer is there strictly a need to bulk update existing documents to accommodate breaking changes.
  • A new validation type that matches any JSON data type: string, number, boolean, array or object. May be useful, for example, in cases where an array is allowed to hold an arbitrary mix of data types.
  • A new validation type that matches one of any number of candidate validation types based on arbitrary conditions. For example, the following document definitions snippet allows hashtable element values of either UUID or integer types:
identifiers: {
  type: 'hashtable',
  hashtableValuesValidator: {
    type: 'conditional',
    required: true,
    validationCandidates: [
      {
        condition: function(doc, oldDoc, currentItemEntry, validationItemStack) {
          return typeof currentItemEntry.itemValue === 'string';
        },
        { type: 'uuid' }
      },
      {
        condition: function(doc, oldDoc, currentItemEntry, validationItemStack) {
          return typeof currentItemEntry.itemValue === 'number';
        },
        {
          type: 'integer',
          minimumValue: 1
        }
      }
    ]
  }
}

As always, refer to the changelog and README for more details.

1 Like

Apologies. There are a pair of mistakes in the code snippet from the announcement of 2.6.0. The corrected code follows:

identifiers: {
  type: 'hashtable',
  hashtableValuesValidator: {
    type: 'conditional',
    required: true,
    validationCandidates: [
      {
        condition: function(doc, oldDoc, currentItemEntry, validationItemStack) {
          return typeof currentItemEntry.itemValue === 'string';
        },
        validator: { type: 'uuid' }
      },
      {
        condition: function(doc, oldDoc, currentItemEntry, validationItemStack) {
          return typeof currentItemEntry.itemValue === 'number';
        },
        validator: {
          type: 'integer',
          minimumValue: 1
        }
      }
    ]
  }
}

There is a relatively small update (2.7.0) today to add support in synctos test fixtures for the requireAdmin function that was quietly introduced in Sync Gateway 2.1.0. In addition, several hyperlinks have been updated to point to the updated resources in the reorganized Couchbase documentation site.

Peruse the changelog for the details.

1 Like

A small patch release today (v2.7.1). It does not introduce any functional changes, but it does fix a low severity security vulnerability in a development dependency (lodash). This should have no impact whatsoever on clients of the synctos package since it is not a transitive dependency.

Of greater interest may be that the mustNotBeNull and mustNotBeMissing constraints have been deprecated since they do not behave as expected due to limitations in the Sync Gateway sync function API (they were backported from couchster but not sufficiently tested). The synctos-validate command will produce a warning message and a non-zero exit status if it encounters either mustNotBeNull or mustNotBeMissing in document definitions.

For more info, refer to the changelog.

1 Like