Updated cors, mongo

This commit is contained in:
thomashii 2022-02-27 09:19:15 +08:00
parent f0255b3cd6
commit f5c2598cbd
8 changed files with 42 additions and 40 deletions

View file

@ -4,7 +4,7 @@ description: Angel3 CORS middleware. Ported from expressjs/cors to Angel3 framew
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/cors
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
angel3_framework: ^6.0.0
dev_dependencies:

View file

@ -1,5 +1,17 @@
# Change Log
## 6.0.0
* Updated to min SDK 2.15.x
## 5.0.0
* No release. Skipped
## 4.0.0
* No release. Skipped
## 3.1.0
* Updated to use `package:belatuk_merge_map`

View file

@ -13,7 +13,7 @@ Add the following to your `pubspec.yaml`:
```yaml
dependencies:
angel3_mongo: ^3.1.0
angel3_mongo: ^6.0.0
```
## Usage

View file

@ -1,14 +0,0 @@
library angel3_mongo.model;
/// Use the `Model` class defined in `package:angel_framework/common.dart` instead.
@deprecated
class Model {
/// This instance's ID.
String? id;
/// The time at which this instance was created.
DateTime? createdAt;
/// The time at which this instance was last updated.
DateTime? updatedAt;
}

View file

@ -12,12 +12,8 @@ class MongoService extends Service<String, Map<String, dynamic>> {
/// If set to `true`, parameters in `req.query` are applied to the database query.
final bool allowQuery;
/// No longer used. Will be removed by `2.1.0`.
@deprecated
final bool debug;
MongoService(this.collection,
{this.allowRemoveAll = false, this.allowQuery = true, this.debug = true})
{this.allowRemoveAll = false, this.allowQuery = true})
: super();
SelectorBuilder? _makeQuery([Map<String, dynamic>? params_]) {
@ -58,7 +54,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
query?.forEach((key, v) {
var value = v is Map<String, dynamic> ? _filterNoQuery(v) : v;
if (!_NO_QUERY.contains(key) &&
if (!_noQuery.contains(key) &&
value is! RequestContext &&
value is! ResponseContext) {
result = result.and(where.eq(key as String, value));
@ -94,7 +90,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
.toList();
}
static const String _NONCE_KEY = '__angel__mongo__nonce__key__';
static const String _nonceKey = '__angel__mongo__nonce__key__';
@override
Future<Map<String, dynamic>> create(Map<String, dynamic> data,
@ -104,13 +100,13 @@ class MongoService extends Service<String, Map<String, dynamic>> {
try {
var nonce = (await collection.db.getNonce())['nonce'] as String?;
var result = await (collection.findAndModify(
query: where.eq(_NONCE_KEY, nonce),
query: where.eq(_nonceKey, nonce),
update: item,
returnNew: true,
upsert: true) as FutureOr<Map<String, dynamic>>);
return _jsonify(result);
} catch (e, st) {
throw AngelHttpException(e, stackTrace: st);
throw AngelHttpException(stackTrace: st);
}
}
@ -179,7 +175,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
return result;
} catch (e, st) {
//printDebug(e, st, 'MODIFY');
throw AngelHttpException(e, stackTrace: st);
throw AngelHttpException(stackTrace: st);
}
}
@ -207,7 +203,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
return result;
} catch (e, st) {
//printDebug(e, st, 'UPDATE');
throw AngelHttpException(e, stackTrace: st);
throw AngelHttpException(stackTrace: st);
}
}
@ -235,7 +231,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
return _jsonify(result);
} catch (e, st) {
//printDebug(e, st, 'REMOVE');
throw AngelHttpException(e, stackTrace: st);
throw AngelHttpException(stackTrace: st);
}
}
}

View file

@ -37,13 +37,13 @@ Map<String, dynamic> _removeSensitive(Map<String, dynamic> data) {
.fold({}, (map, key) => map..[key] = data[key]);
}
const List<String> _NO_QUERY = ['__requestctx', '__responsectx'];
const List<String> _noQuery = ['__requestctx', '__responsectx'];
Map<String, dynamic> _filterNoQuery(Map<String, dynamic> data) {
return data.keys.fold({}, (map, key) {
var value = data[key];
if (_NO_QUERY.contains(key) ||
if (_noQuery.contains(key) ||
value is RequestContext ||
value is ResponseContext) return map;
if (key is! Map) return map..[key] = value;

View file

@ -1,12 +1,12 @@
name: angel3_mongo
version: 3.1.0
description: MongoDB-enabled services for the Angel framework. Well-tested.
version: 6.0.0
description: MongoDB-enabled services for the Angel3 framework. Well-tested.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/mongo
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
angel3_framework: ^4.2.0
angel3_framework: ^6.0.0
belatuk_json_serializer: ^5.0.0
belatuk_merge_map: ^3.0.0
mongo_dart: ^0.7.0
@ -14,8 +14,16 @@ dev_dependencies:
http: ^0.13.0
test: ^1.17.5
lints: ^1.0.0
#dependency_overrides:
# angel3_framework:
# path: ../framework
# angel3_route:
# path: ../route
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

View file

@ -39,7 +39,7 @@ void main() {
// Delete anything before we start
await testData.remove(<String, dynamic>{});
var service = MongoService(testData, debug: true);
var service = MongoService(testData);
greetingService = HookedService(service);
wireHooked(greetingService!);