Updated validate

This commit is contained in:
thomashii@dukefirehawk.com 2023-10-27 23:52:29 +08:00
parent e78f68487d
commit 6506a3e0de
8 changed files with 36 additions and 40 deletions

View file

@ -1,5 +1,10 @@
# Change Log
## 8.0.0
* Require Dart >= 3.0
* Updated `oauth1` to `belatuk_oauth1`
## 7.0.0
* Require Dart >= 2.17

View file

@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2021, dukefirehawk.com
Copyright (c) 2023, dukefirehawk.com
All rights reserved.
Redistribution and use in source and binary forms, with or without

View file

@ -6,29 +6,28 @@ repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth_twit
publish_to: none
environment:
sdk: ">=3.0.0 <4.0.0"
published_to: none
dependencies:
angel3_auth: ^8.0.0
angel3_framework: ^8.0.0
http: ^1.0.0
path: ^1.0.0
oauth1: ^2.0.0
belatuk_oauth1: ^3.0.0
dart_twitter_api: ^0.5.6+1
dev_dependencies:
logging: ^1.2.0
lints: ^2.1.0
dependency_overrides:
angel3_container:
path: ../container/angel_container
angel3_framework:
path: ../framework
angel3_http_exception:
path: ../http_exception
angel3_model:
path: ../model
angel3_route:
path: ../route
angel3_mock_request:
path: ../mock_request
angel3_auth:
path: ../auth
# dependency_overrides:
# angel3_container:
# path: ../container/angel_container
# angel3_framework:
# path: ../framework
# angel3_http_exception:
# path: ../http_exception
# angel3_model:
# path: ../model
# angel3_route:
# path: ../route
# angel3_mock_request:
# path: ../mock_request
# angel3_auth:
# path: ../auth

View file

@ -1,11 +1,11 @@
# Angel3 Testing Library
# Angel3 Test
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_test?include_prereleases)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/test/LICENSE)
Testing utility library for the Angel3 framework.
Testing utility library for Angel3 framework.
## TestClient
@ -51,7 +51,7 @@ void test('error', () async {
```dart
test('validate response', () async {
var res = await client.get('/bar');
expect(res, hasValidBody(new Validator({
expect(res, hasValidBody(Validator({
'foo': isBoolean,
'bar': [isString, equals('baz')],
'age*': [],

View file

@ -1,17 +1,15 @@
# Angel3 Request Validator
# Angel3 Validate
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_validate?include_prereleases)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/validate/LICENSE)
Validation library based on the `matcher` library, with Angel3 support. Why re-invent the wheel, when you can use the same validators you already use for tests?
This library runs both on the server, and on the client. Thus, you can use the same validation rules for forms on the server, and on the frontend.
This validator library is based on the `matcher` library and comes with build in support for Angel3 framework. It can be run on both server and client side. Thus, the same validation rules apply to forms on both backend and frontend code.
For convenience's sake, this library also exports `matcher`.
- [Angel3 Request Validator](#angel3-request-validator)
- [Angel3 Validate](#angel3-validate)
- [Examples](#examples)
- [Creating a Validator](#creating-a-validator)
- [Validating data](#validating-data)
@ -25,7 +23,7 @@ For convenience's sake, this library also exports `matcher`.
- [Extending Validators](#extending-validators)
- [Bundled Matchers](#bundled-matchers)
- [Nested Validators](#nested-validators)
- [Use with Angel](#use-with-angel)
- [Use with Angel3](#use-with-angel3)
## Examples
@ -82,9 +80,7 @@ main() {
### Required Fields
Fields are optional by default.
Suffix a field name with a `'*'` to mark it as required, and to throw an error if it is not present.
Fields are optional by default. Suffix a field name with a `'*'` to mark it as required, and to throw an error if it is not present.
```dart
main() {
@ -118,9 +114,7 @@ Default values can also be parameterless, *synchronous* functions that return a
### Custom Validator Functions
Creating a whole `Matcher` class is sometimes cumbersome, but if you pass a function to the constructor, it will be wrapped in a `Matcher` instance.
(It simply returns the value of calling [`predicate`](https://pub.dev/documentation/matcher/latest/matcher/predicate.html).)
Creating a whole `Matcher` class is sometimes cumbersome, but if you pass a function to the constructor, it will be wrapped in a `Matcher` instance. (It simply returns the value of calling [`predicate`](https://pub.dev/documentation/matcher/latest/matcher/predicate.html).)
The function must *synchronously* return a `bool`.
@ -151,8 +145,7 @@ The string `{{value}}` will be replaced inside your error message automatically.
### autoParse
Oftentimes, fields that we want to validate as numbers are passed as strings.
Calling `autoParse` will correct this before validation.
Oftentimes, fields that we want to validate as numbers are passed as strings. Calling `autoParse` will correct this before validation.
```dart
main() {
@ -263,7 +256,7 @@ main() {
}
```
### Use with Angel
### Use with Angel3
`server.dart` exposes seven helper middleware:

View file

@ -1,5 +1,5 @@
name: angel3_validate
description: Cross-platform request body validation library based on `matcher`.
description: Cross-platform HTTP request body validator library based on `matcher`.
version: 8.0.0
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/validate

View file

@ -31,8 +31,7 @@ void main() {
expect(() {
todoSchema
.enforce({'id': 'fool', 'text': 'Hello, world!', 'completed': 4});
// ignore: deprecated_member_use
}, throwsA(isInstanceOf<ValidationException>()));
}, throwsA(isA<ValidationException>()));
});
test('filter', () {

View file

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>angel_validate</title>
<title>angel3_validate</title>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<style>