wilt 4.0.4

Wilt - both a browser and server based CouchDB client library #

Wilt is based on the lightweight SAG PHP CouchDB library available here. Users of this library should recognise the structure of Wilt easily. A common processing body is specialised by the use of browser(dart:html) or server(dart:io) HTTP adapters to allow operation in the browser or the server.

Wilt implements the document/attachment/database storage and manipulation interfaces of SAG along with the utility functions such as get session information etc. It does not directly implement the manipulation of design documents, clients however can manipulate these items by constructing their own URL's and using the basic httpRequest method.

Authentication is provided using the Basic HTML method, cookie authentication is not supported.

Wilt is a fully functional standalone library, however it is envisaged that higher level client specific application layers will be wrapped around Wilt to add specific CouchDB response parsing as Wilt returns JSON Objects(or strings) to the client. It has no knowledge of correct/incorrect responses such as conflict errors for instance, i.e it has no real CouchDB intelligence other than supplying success or error responses from its HTTP interface adapter.

Note that the Wilt methods that previously returned Json Objects(JsonObjectLite) now return the dynamic type, this is a JsonObjectLite and can be used as such. This change was necessitated as part of the Dart 2.0 updates.

Current version supports both CouchDb 2.2.0 and 1.6.

4.0.4 #

Linter updates

4.0.3 #

Pub analysis fixes for Dart 2.6.1, general tidy up

4.0.2 #

Pub analysis fixes for Dart 2.4.1

4.0.1 #

Pub analysis fixes

4.0.0 #

Update to Dart 2.0, issue 25

3.4.1 #

Correct the SDK version constraint for Flutter

3.4.0 #

Strong mode updates, switch to json_object_lite. Major test refactor Wilt now compiles under the dev compiler, tests factored into common and platform specific.

3.3.0 #

Update to latest packages/Dart environment. Retire the completion tests.

3.2.0 #

Issues 15, 21, 22 and 23.

3.1.2 #

Update to latest HTTP package

3.1.1 #

Issue 17, CouchDb 1.6.1 updates

3.1.0 #

Updates for Issues 13, 11 and 14

3.0.1 #

Updates for Dart V1.5.3, all tests running.

3.0.0 #

Issues 8 and 9, this makes Wilt both Browser and Server capable

2.3.0 #

Issue 7 fixed

2.2.2 #

Issue 6 fixed

2.2.1 #

Issue 5 fixed

2.2.0 #

Issues 3 and 4 fixed.

2.1.0 #

Standalone attachments added Change notification interface added

2.0.0 #

Updated for Dart 1.0 release Unit tests now use expectAsync0(() Native adapter success/error response hardening Various bugs NOTE - No API changes.

1.2.0 #

API docs generated

Updated to use dart:convert

example/wilt.dart

/*
 * Package : WiltServerClient
 * Author : S. Hamblett <steve.hamblett@linux.com>
 * Date   : 03/09/2018
 * Copyright :  S.Hamblett
 */

import 'package:wilt/wilt.dart';
import 'package:wilt/wilt_server_client.dart'; // Comment out for browser.
//import 'package:wilt/wilt_browser_client.dart'; Uncomment for browser
import 'package:json_object_lite/json_object_lite.dart' as jsonobject;
// ignore: avoid_relative_lib_imports
import '../test/lib/wilt_test_config.dart';

// ignore_for_file: omit_local_variable_types
// ignore_for_file: unnecessary_final
// ignore_for_file: cascade_invocations
// ignore_for_file: avoid_print

/// A simple Wilt client example.
/// Please adjust the settings in wilt_test_config to suite your CouchDb setup.
/// If you are using the browser test please check your CORS settings
/// in CouchDB.
/// For more detailed examples of the API see the test suite.
///
// ignore: avoid_void_async
void main() async {
  /// Create a test client
  final WiltServerClient wilting =
      WiltServerClient(hostName, serverPort, scheme);

  /// Or for the browser
  /// final WiltBrowserClient wilting =
  //  new WiltBrowserClient(hostName, port, scheme);

  // Login if we are using authentication. If you are using authentication
  // try the example with this commented out, you should see all
  // the operations fail with 'not authorised'.
  if (userName != null) {
    wilting.login(userName, userPassword);
  }

  /// Create an example database
  dynamic res = await wilting.createDatabase('wilt_example');
  if (!res.error) {
    final dynamic successResponse = res.jsonCouchResponse;
    if (successResponse.ok) {
      print('EXAMPLE:: Example database created OK');
    } else {
      print('EXAMPLE:: Example database creation failed');
    }
  } else {
    print('EXAMPLE:: Example database creation failed');
  }

  /// Create a test document
  wilting.db = 'wilt_example';
  String returnedDocRev;
  const String putId = 'exampletestid';
  final dynamic document = jsonobject.JsonObjectLite<dynamic>();
  document.title = 'Created by a Put Request';
  document.version = 1;
  document.author = 'SJH';
  res = await wilting.putDocument(putId, document);
  if (!res.error) {
    final dynamic successResponse = res.jsonCouchResponse;
    if (successResponse.ok) {
      returnedDocRev = WiltUserUtils.getDocumentRev(successResponse);
      print(
          'EXAMPLE:: Example document created OK, revision is $returnedDocRev');
    } else {
      print('EXAMPLE:: Example document creation failed');
    }
  } else {
    print('EXAMPLE:: Example document creation failed');
  }

  /// Update the document to version 2, note we now supply the returned
  /// document revision from above.
  document.version = 2;
  res = await wilting.putDocument(putId, document, returnedDocRev);
  if (!res.error) {
    final dynamic successResponse = res.jsonCouchResponse;
    if (successResponse.ok) {
      returnedDocRev = WiltUserUtils.getDocumentRev(successResponse);
      print(
          'EXAMPLE:: Example document updated OK, revision is $returnedDocRev');
    } else {
      print('EXAMPLE:: Example document update failed');
    }
  } else {
    print('EXAMPLE:: Example document update failed');
  }

  /// Read it back
  res = await wilting.getDocument(putId);
  if (!res.error) {
    final dynamic successResponse = res.jsonCouchResponse;
    returnedDocRev = WiltUserUtils.getDocumentRev(successResponse);
    print('EXAMPLE:: Example document read OK, revision is $returnedDocRev');
    print('EXAMPLE:: Example document read OK, title is '
        '${successResponse.title}');
    print('EXAMPLE:: Example document read OK, version is '
        '${successResponse.version}');
    print('EXAMPLE:: Example document read OK, author is '
        '${successResponse.author}');
  } else {
    print('EXAMPLE:: Example document read failed');
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  wilt: ^4.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:wilt/wilt.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
72
Learn more about scoring.

We analyzed this package on Feb 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
crypto ^2.1.3 2.1.4
http ^0.12.0+2 0.12.0+4
json_object_lite ^2.1.0 2.1.1
Transitive dependencies
async 2.4.0
charcode 1.1.3
collection 1.14.12
convert 2.1.1
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
build_runner ^1.7.2
build_test ^0.10.10
build_web_compilers ^2.7.1
test ^1.9.4