Published sembast

This commit is contained in:
thomashii 2021-06-21 14:16:06 +08:00
parent ec2190162d
commit 0cccae9cd4
10 changed files with 116 additions and 95 deletions

View file

@ -1,9 +1,12 @@
# 4.0.0 (NNBD) # Change Log
## 4.0.0 (NNBD)
* Published all packages with `angel3_` prefix * Published all packages with `angel3_` prefix
* Changed Dart SDK requirements for all packages to ">=2.12.0 <3.0.0" to support NNBD. * Changed Dart SDK requirements for all packages to ">=2.12.0 <3.0.0" to support NNBD.
* Migrated pretty_logging to 3.0.0 (0/0 tests passed) * Migrated pretty_logging to 3.0.0 (0/0 tests passed)
* Migrated angel_http_exception to 3.0.0 (0/0 tests passed) * Migrated angel_http_exception to 3.0.0 (0/0 tests passed)
* Moved angel_cli to https://github.com/dukefirehawk/cli (Not migrated yet) * Moved angel_cli to <https://github.com/dukefirehawk/cli> (Not migrated yet)
* Added code_buffer and migrated to 2.0.0 (16/16 tests passed) * Added code_buffer and migrated to 2.0.0 (16/16 tests passed)
* Added combinator and migrated to 2.0.0 (16/16 tests passed) * Added combinator and migrated to 2.0.0 (16/16 tests passed)
* Migrated angel_route to 5.0.0 (35/35 tests passed) * Migrated angel_route to 5.0.0 (35/35 tests passed)
@ -35,7 +38,7 @@
* Migrated angel_orm to 3.0.0 (0/0 tests passed) * Migrated angel_orm to 3.0.0 (0/0 tests passed)
* Migrated angel_migration to 3.0.0 (0/0 tests passed) * Migrated angel_migration to 3.0.0 (0/0 tests passed)
* Added inflection2 and migrated to 1.0.0 (28/32 tests passed) * Added inflection2 and migrated to 1.0.0 (28/32 tests passed)
* Migrated angel_orm_generator to 4.0.0 (0/0 tests passed) * Migrated angel_orm_generator to 4.0.0 (0/0 tests passed)
* Migrated angel_migration_runner to 3.0.0 (0/0 tests passed) * Migrated angel_migration_runner to 3.0.0 (0/0 tests passed)
* Migrated angel_orm_test to 3.0.0 (0/0 tests passed) * Migrated angel_orm_test to 3.0.0 (0/0 tests passed)
* Migrated angel_orm_postgres to 3.0.0 (51/54 tests passed) * Migrated angel_orm_postgres to 3.0.0 (51/54 tests passed)
@ -74,7 +77,8 @@
* Migrated user_agent to 2.0.0 (0/0 tests passed) * Migrated user_agent to 2.0.0 (0/0 tests passed)
* Migrated angel_user_agent to 2.0.0 (0/0 tests passed) * Migrated angel_user_agent to 2.0.0 (0/0 tests passed)
# 3.0.0 (Non NNBD) ## 3.0.0 (Non NNBD)
* Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0" * Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0"
* Updated pretty_logging to 2.0.0 (0/0 tests passed) * Updated pretty_logging to 2.0.0 (0/0 tests passed)
* Updated angel_http_exception to 2.0.0 (0/0 tests passed) * Updated angel_http_exception to 2.0.0 (0/0 tests passed)
@ -116,12 +120,13 @@
* Updated angel_eventsource to 2.0.0 (use a fork of eventsource) * Updated angel_eventsource to 2.0.0 (use a fork of eventsource)
* Updated angel_auth_twitter to 3.0.0 (use a fork of twitter and oauth) * Updated angel_auth_twitter to 3.0.0 (use a fork of twitter and oauth)
# 2.2.0 ## 2.2.0
* Changed Dart SDK requirements for all packages to ">=2.10.0 <2.12.0" * Changed Dart SDK requirements for all packages to ">=2.10.0 <2.12.0"
* Upgraded 3rd party libraries to the latest version prior to dart 2.12 * Upgraded 3rd party libraries to the latest version prior to dart 2.12
* Fixed broken code due to 3rd party libraries update * Fixed broken code due to 3rd party libraries update
* Revert packages/validate from version 3.0 to version 2.2 * Revert packages/validate from version 3.0 to version 2.2
# 2.1.x and below ## 2.1.x and below
* Refer to the orginal repo before the fork
* Refer to the orginal repo before the fork

View file

@ -1,8 +1,13 @@
# 2.0.0 # Change Log
## 2.0.0
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD
# 1.0.1 ## 1.0.1
* Fix flaw where clients could remove all records, even if `allowRemoveAll` were `false`. * Fix flaw where clients could remove all records, even if `allowRemoveAll` were `false`.
# 1.0.0 ## 1.0.0
* First release.
* First release.

View file

@ -1,6 +1,6 @@
MIT License MIT License (MIT)
Copyright (c) 2018 The Angel Framework Copyright (c) 2021 dukefirehawk.com
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -1,38 +1,44 @@
# sembast # Angel3 Sembast
[![Pub](https://img.shields.io/pub/v/angel_sembast.svg)](https://pub.dartlang.org/packages/angel_sembast)
[![build status](https://travis-ci.org/angel-dart/sembast.svg)](https://travis-ci.org/angel-dart/sembast)
package:sembast-powered CRUD services for the Angel framework. [![version](https://img.shields.io/badge/pub-v2.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_sembast)
[![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)
# Installation [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/sembast/LICENSE)
A sembast-powered CRUD services for the Angel3 framework.
## Installation
Add the following to your `pubspec.yaml`: Add the following to your `pubspec.yaml`:
```yaml ```yaml
dependencies: dependencies:
angel_sembast: ^1.0.0 angel3_sembast: ^2.0.0
``` ```
# Usage ## Usage
This library exposes one main class: `SembastService`. This library exposes one main class: `SembastService`.
## SembastService ### SembastService
This class interacts with a `Database` and `Store` (from `package:sembast`) and serializes data to and from Maps. This class interacts with a `Database` and `Store` (from `package:sembast`) and serializes data to and from Maps.
## Querying ### Querying
You can query these services as follows: You can query these services as follows:
/path/to/service?foo=bar ```dart
/path/to/service?foo=bar
```
The above will query the database to find records where 'foo' equals 'bar'. The above will query the database to find records where 'foo' equals 'bar'.
The former will sort result in ascending order of creation, and so will the latter. The former will sort result in ascending order of creation, and so will the latter.
```dart ```dart
List queried = await MyService.index({r"query": where.id(new Finder(filter: new Filter(...)))); List queried = await MyService.index({r"query": where.id(Finder(filter: Filter(...))));
``` ```
Of course, you can use `package:sembast` queries. Just pass it as `query` within `params`. Of course, you can use `package:sembast` queries. Just pass it as `query` within `params`.

View file

@ -1,6 +1,6 @@
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_framework/http.dart'; import 'package:angel3_framework/http.dart';
import 'package:angel_sembast/angel_sembast.dart'; import 'package:angel3_sembast/angel3_sembast.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:sembast/sembast_io.dart'; import 'package:sembast/sembast_io.dart';

View file

@ -1,5 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:sembast/sembast.dart'; import 'package:sembast/sembast.dart';
class SembastService extends Service<String, Map<String, dynamic>> { class SembastService extends Service<String, Map<String, dynamic>> {

View file

@ -1,23 +1,15 @@
name: angel_sembast name: angel3_sembast
version: 2.0.0 version: 2.0.0
description: package:sembast-powered CRUD services for the Angel framework. description: A sembast-powered CRUD services for the Angel3 framework.
homepage: https://github.com/angel-dart/sembast homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/sembast
publish_to: none publish_to: none
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
angel_framework: angel3_framework: ^4.0.0
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/framework
sembast: ^3.1.0+2 sembast: ^3.1.0+2
dev_dependencies: dev_dependencies:
angel_http_exception: angel3_http_exception: ^3.0.0
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/http_exception
logging: ^1.0.1 logging: ^1.0.1
pedantic: ^1.11.1 pedantic: ^1.11.1
test: ^1.17.8 test: ^1.17.8

View file

@ -1,7 +1,7 @@
import 'dart:collection'; import 'dart:collection';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_http_exception/angel_http_exception.dart'; import 'package:angel3_http_exception/angel3_http_exception.dart';
import 'package:angel_sembast/angel_sembast.dart'; import 'package:angel3_sembast/angel3_sembast.dart';
import 'package:sembast/sembast.dart'; import 'package:sembast/sembast.dart';
import 'package:sembast/sembast_io.dart'; import 'package:sembast/sembast_io.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
@ -82,13 +82,15 @@ void main() async {
throwsA(const TypeMatcher<AngelHttpException>())); throwsA(const TypeMatcher<AngelHttpException>()));
expect( expect(
() => service.remove(null, {'provider': Providers.rest}), () => service.remove(null, {'provider': Providers.rest}),
throwsA(predicate((dynamic x) => x is AngelHttpException && x.statusCode == 403, throwsA(predicate(
(dynamic x) => x is AngelHttpException && x.statusCode == 403,
'throws forbidden'))); 'throws forbidden')));
expect(() => service.remove('null', {'provider': Providers.rest}), expect(() => service.remove('null', {'provider': Providers.rest}),
throwsA(const TypeMatcher<AngelHttpException>())); throwsA(const TypeMatcher<AngelHttpException>()));
expect( expect(
() => service.remove('null', {'provider': Providers.rest}), () => service.remove('null', {'provider': Providers.rest}),
throwsA(predicate((dynamic x) => x is AngelHttpException && x.statusCode == 403, throwsA(predicate(
(dynamic x) => x is AngelHttpException && x.statusCode == 403,
'throws forbidden'))); 'throws forbidden')));
}); });

View file

@ -8,14 +8,13 @@ void main() async {
var app = Angel(); var app = Angel();
var http = AngelHttp(app); var http = AngelHttp(app);
// TODO: Commented out due to unknow class //TODO: To be reviewed
app.get( app.get(
'/', '/',
waterfall([ waterfall([
parseUserAgent, parseUserAgent,
(req, res) { (req, res) {
var ua = req.container.make<UserAgent>(); var ua = req.container.make<UserAgent>() as UserAgent;
return ua.isChrome return ua.isChrome
? 'Woohoo! You are running Chrome.' ? 'Woohoo! You are running Chrome.'
: 'Sorry, we only support Google Chrome.'; : 'Sorry, we only support Google Chrome.';

View file

@ -1,4 +1,5 @@
# angel3_validate # angel3_validate
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_validate) [![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_validate)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![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) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
@ -16,24 +17,25 @@ the same validation rules for forms on the server, and on the frontend.
For convenience's sake, this library also exports `matcher`. For convenience's sake, this library also exports `matcher`.
* [Examples](#examples) - [angel3_validate](#angel3_validate)
* [Creating a Validator](#creating-a-validator) - [Examples](#examples)
* [Validating Data](#validating-data) - [Creating a Validator](#creating-a-validator)
* [Required Fields](#required-fields) - [Validating data](#validating-data)
* [Forbidden Fields](#forbidden-fields) - [Required Fields](#required-fields)
* [Default Values](#default-values) - [Forbidden Fields](#forbidden-fields)
* [Custom Validator Functions](#custom-validator-functions) - [Default values](#default-values)
* [Auto-parsing Numbers](#autoparse) - [Custom Validator Functions](#custom-validator-functions)
* [Filtering Maps](#filter) - [Custom Error Messages](#custom-error-messages)
* [Custom Error Messages](#custom-error-messages) - [autoParse](#autoparse)
* [Extending Validators](#extending-validators) - [filter](#filter)
* [Bundled Matchers](#bundled-matchers) - [Extending Validators](#extending-validators)
* [Nested Validators](#nested-validators) - [Bundled Matchers](#bundled-matchers)
* [Use with Angel](#use-with-angel) - [Nested Validators](#nested-validators)
- [Use with Angel](#use-with-angel)
# Examples ## Examples
## Creating a Validator ### Creating a Validator
```dart ```dart
import 'package:angel3_validate/angel3_validate.dart'; import 'package:angel3_validate/angel3_validate.dart';
@ -54,7 +56,7 @@ main() {
} }
``` ```
## Validating data ### Validating data
The `Validator` will filter out fields that have no validation rules. The `Validator` will filter out fields that have no validation rules.
You can rest easy knowing that attackers cannot slip extra data into You can rest easy knowing that attackers cannot slip extra data into
@ -86,7 +88,8 @@ main() {
} }
``` ```
## Required Fields ### Required Fields
Fields are optional by default. Fields are optional by default.
Suffix a field name with a `'*'` to mark it as required, and Suffix a field name with a `'*'` to mark it as required, and
@ -103,12 +106,12 @@ main() {
} }
``` ```
## Forbidden Fields ### Forbidden Fields
To prevent a field from showing up in valid data, suffix it To prevent a field from showing up in valid data, suffix it
with a `'!'`. with a `'!'`.
### Default values
## Default values
If not present, default values will be filled in *before* validation. If not present, default values will be filled in *before* validation.
This means that they can still be used with required fields. This means that they can still be used with required fields.
@ -125,7 +128,8 @@ final Validator todo = Validator({
Default values can also be parameterless, *synchronous* functions Default values can also be parameterless, *synchronous* functions
that return a single value. that return a single value.
## Custom Validator Functions ### Custom Validator Functions
Creating a whole `Matcher` class is sometimes cumbersome, but if Creating a whole `Matcher` class is sometimes cumbersome, but if
you pass a function to the constructor, it will be wrapped in a you pass a function to the constructor, it will be wrapped in a
`Matcher` instance. `Matcher` instance.
@ -146,7 +150,8 @@ main() {
} }
``` ```
# Custom Error Messages ### Custom Error Messages
If these are not present, `angel3_validate` will *attempt* to generate If these are not present, `angel3_validate` will *attempt* to generate
a coherent error message on its own. a coherent error message on its own.
@ -157,9 +162,11 @@ Validator({
'age': 'You must be an adult to see this page.' 'age': 'You must be an adult to see this page.'
}); });
``` ```
The string `{{value}}` will be replaced inside your error message automatically. The string `{{value}}` will be replaced inside your error message automatically.
# autoParse ### autoParse
Oftentimes, fields that we want to validate as numbers are passed as strings. Oftentimes, fields that we want to validate as numbers are passed as strings.
Calling `autoParse` will correct this before validation. Calling `autoParse` will correct this before validation.
@ -176,7 +183,8 @@ main() {
You can also call `checkParsed` or `enforceParsed` as a shorthand. You can also call `checkParsed` or `enforceParsed` as a shorthand.
# filter ### filter
This is a helper function to extract only the desired keys from a `Map`. This is a helper function to extract only the desired keys from a `Map`.
```dart ```dart
@ -186,7 +194,8 @@ var only = filter(inputData, ['foo']);
print(only); // { foo: bar } print(only); // { foo: bar }
``` ```
# Extending Validators ### Extending Validators
You can add situation-specific rules within a child validator. You can add situation-specific rules within a child validator.
You can also use `extend` to mark fields as required or forbidden that originally You can also use `extend` to mark fields as required or forbidden that originally
were not. Default value and custom error message extension is also supported. were not. Default value and custom error message extension is also supported.
@ -225,24 +234,26 @@ register(Map userData) {
} }
``` ```
# Bundled Matchers ### Bundled Matchers
This library includes some `Matcher`s for common validations, This library includes some `Matcher`s for common validations,
including: including:
* `isAlphaDash`: Asserts that a `String` is alphanumeric, but also lets it contain dashes or underscores. - `isAlphaDash`: Asserts that a `String` is alphanumeric, but also lets it contain dashes or underscores.
* `isAlphaNum`: Asserts that a `String` is alphanumeric. - `isAlphaNum`: Asserts that a `String` is alphanumeric.
* `isBool`: Asserts that a value either equals `true` or `false`. - `isBool`: Asserts that a value either equals `true` or `false`.
* `isEmail`: Asserts that a `String` complies to the RFC 5322 e-mail standard. - `isEmail`: Asserts that a `String` complies to the RFC 5322 e-mail standard.
* `isInt`: Asserts that a value is an `int`. - `isInt`: Asserts that a value is an `int`.
* `isNum`: Asserts that a value is a `num`. - `isNum`: Asserts that a value is a `num`.
* `isString`: Asserts that a value is a `String`. - `isString`: Asserts that a value is a `String`.
* `isNonEmptyString`: Asserts that a value is a non-empty `String`. - `isNonEmptyString`: Asserts that a value is a non-empty `String`.
* `isUrl`: Asserts that a `String` is an HTTPS or HTTP URL. - `isUrl`: Asserts that a `String` is an HTTPS or HTTP URL.
The remaining functionality is The remaining functionality is
[effectively implemented by the `matcher` package](https://www.dartdocs.org/documentation/matcher/0.12.0%2B2/matcher/matcher-library.html). [effectively implemented by the `matcher` package](https://www.dartdocs.org/documentation/matcher/0.12.0%2B2/matcher/matcher-library.html).
# Nested Validators ### Nested Validators
Very often, the data we validate contains other data within. You can pass Very often, the data we validate contains other data within. You can pass
a `Validator` instance to the constructor, because it extends the a `Validator` instance to the constructor, because it extends the
`Matcher` class. `Matcher` class.
@ -277,16 +288,17 @@ main() {
} }
``` ```
# Use with Angel ### Use with Angel
`server.dart` exposes seven helper middleware: `server.dart` exposes seven helper middleware:
* `validate(validator)`: Validates and filters `req.bodyAsMap`, and throws an `AngelHttpException.BadRequest` if data is invalid.
* `validateEvent(validator)`: Sets `e.data` to the result of validation on a service event. - `validate(validator)`: Validates and filters `req.bodyAsMap`, and throws an `AngelHttpException.BadRequest` if data is invalid.
* `validateQuery(validator)`: Same as `validate`, but operates on `req.query`. - `validateEvent(validator)`: Sets `e.data` to the result of validation on a service event.
* `autoParseBody(fields)`: Auto-parses numbers in `req.bodyAsMap`. - `validateQuery(validator)`: Same as `validate`, but operates on `req.query`.
* `autoParseQuery(fields)`: Same as `autoParseBody`, but operates on `req.query`. - `autoParseBody(fields)`: Auto-parses numbers in `req.bodyAsMap`.
* `filterBody(only)`: Filters unwanted data out of `req.bodyAsMap`. - `autoParseQuery(fields)`: Same as `autoParseBody`, but operates on `req.query`.
* `filterQuery(only)`: Same as `filterBody`, but operates on `req.query`. - `filterBody(only)`: Filters unwanted data out of `req.bodyAsMap`.
- `filterQuery(only)`: Same as `filterBody`, but operates on `req.query`.
```dart ```dart
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';