Updated cors, mongo
This commit is contained in:
parent
f0255b3cd6
commit
f5c2598cbd
8 changed files with 42 additions and 40 deletions
|
@ -4,7 +4,7 @@ description: Angel3 CORS middleware. Ported from expressjs/cors to Angel3 framew
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dukefirehawk/angel/tree/master/packages/cors
|
repository: https://github.com/dukefirehawk/angel/tree/master/packages/cors
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.15.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
angel3_framework: ^6.0.0
|
angel3_framework: ^6.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
# Change Log
|
# 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
|
## 3.1.0
|
||||||
|
|
||||||
* Updated to use `package:belatuk_merge_map`
|
* Updated to use `package:belatuk_merge_map`
|
||||||
|
|
|
@ -13,7 +13,7 @@ Add the following to your `pubspec.yaml`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
dependencies:
|
dependencies:
|
||||||
angel3_mongo: ^3.1.0
|
angel3_mongo: ^6.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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.
|
/// If set to `true`, parameters in `req.query` are applied to the database query.
|
||||||
final bool allowQuery;
|
final bool allowQuery;
|
||||||
|
|
||||||
/// No longer used. Will be removed by `2.1.0`.
|
|
||||||
@deprecated
|
|
||||||
final bool debug;
|
|
||||||
|
|
||||||
MongoService(this.collection,
|
MongoService(this.collection,
|
||||||
{this.allowRemoveAll = false, this.allowQuery = true, this.debug = true})
|
{this.allowRemoveAll = false, this.allowQuery = true})
|
||||||
: super();
|
: super();
|
||||||
|
|
||||||
SelectorBuilder? _makeQuery([Map<String, dynamic>? params_]) {
|
SelectorBuilder? _makeQuery([Map<String, dynamic>? params_]) {
|
||||||
|
@ -58,7 +54,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
|
||||||
query?.forEach((key, v) {
|
query?.forEach((key, v) {
|
||||||
var value = v is Map<String, dynamic> ? _filterNoQuery(v) : 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! RequestContext &&
|
||||||
value is! ResponseContext) {
|
value is! ResponseContext) {
|
||||||
result = result.and(where.eq(key as String, value));
|
result = result.and(where.eq(key as String, value));
|
||||||
|
@ -94,7 +90,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const String _NONCE_KEY = '__angel__mongo__nonce__key__';
|
static const String _nonceKey = '__angel__mongo__nonce__key__';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Map<String, dynamic>> create(Map<String, dynamic> data,
|
Future<Map<String, dynamic>> create(Map<String, dynamic> data,
|
||||||
|
@ -104,13 +100,13 @@ class MongoService extends Service<String, Map<String, dynamic>> {
|
||||||
try {
|
try {
|
||||||
var nonce = (await collection.db.getNonce())['nonce'] as String?;
|
var nonce = (await collection.db.getNonce())['nonce'] as String?;
|
||||||
var result = await (collection.findAndModify(
|
var result = await (collection.findAndModify(
|
||||||
query: where.eq(_NONCE_KEY, nonce),
|
query: where.eq(_nonceKey, nonce),
|
||||||
update: item,
|
update: item,
|
||||||
returnNew: true,
|
returnNew: true,
|
||||||
upsert: true) as FutureOr<Map<String, dynamic>>);
|
upsert: true) as FutureOr<Map<String, dynamic>>);
|
||||||
return _jsonify(result);
|
return _jsonify(result);
|
||||||
} catch (e, st) {
|
} 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;
|
return result;
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
//printDebug(e, st, 'MODIFY');
|
//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;
|
return result;
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
//printDebug(e, st, 'UPDATE');
|
//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);
|
return _jsonify(result);
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
//printDebug(e, st, 'REMOVE');
|
//printDebug(e, st, 'REMOVE');
|
||||||
throw AngelHttpException(e, stackTrace: st);
|
throw AngelHttpException(stackTrace: st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,13 @@ Map<String, dynamic> _removeSensitive(Map<String, dynamic> data) {
|
||||||
.fold({}, (map, key) => map..[key] = data[key]);
|
.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) {
|
Map<String, dynamic> _filterNoQuery(Map<String, dynamic> data) {
|
||||||
return data.keys.fold({}, (map, key) {
|
return data.keys.fold({}, (map, key) {
|
||||||
var value = data[key];
|
var value = data[key];
|
||||||
|
|
||||||
if (_NO_QUERY.contains(key) ||
|
if (_noQuery.contains(key) ||
|
||||||
value is RequestContext ||
|
value is RequestContext ||
|
||||||
value is ResponseContext) return map;
|
value is ResponseContext) return map;
|
||||||
if (key is! Map) return map..[key] = value;
|
if (key is! Map) return map..[key] = value;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
name: angel3_mongo
|
name: angel3_mongo
|
||||||
version: 3.1.0
|
version: 6.0.0
|
||||||
description: MongoDB-enabled services for the Angel framework. Well-tested.
|
description: MongoDB-enabled services for the Angel3 framework. Well-tested.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dukefirehawk/angel/tree/master/packages/mongo
|
repository: https://github.com/dukefirehawk/angel/tree/master/packages/mongo
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.15.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
angel3_framework: ^4.2.0
|
angel3_framework: ^6.0.0
|
||||||
belatuk_json_serializer: ^5.0.0
|
belatuk_json_serializer: ^5.0.0
|
||||||
belatuk_merge_map: ^3.0.0
|
belatuk_merge_map: ^3.0.0
|
||||||
mongo_dart: ^0.7.0
|
mongo_dart: ^0.7.0
|
||||||
|
@ -14,8 +14,16 @@ dev_dependencies:
|
||||||
http: ^0.13.0
|
http: ^0.13.0
|
||||||
test: ^1.17.5
|
test: ^1.17.5
|
||||||
lints: ^1.0.0
|
lints: ^1.0.0
|
||||||
#dependency_overrides:
|
dependency_overrides:
|
||||||
# angel3_framework:
|
angel3_container:
|
||||||
# path: ../framework
|
path: ../container/angel_container
|
||||||
# angel3_route:
|
angel3_framework:
|
||||||
# path: ../route
|
path: ../framework
|
||||||
|
angel3_http_exception:
|
||||||
|
path: ../http_exception
|
||||||
|
angel3_model:
|
||||||
|
path: ../model
|
||||||
|
angel3_route:
|
||||||
|
path: ../route
|
||||||
|
angel3_mock_request:
|
||||||
|
path: ../mock_request
|
|
@ -39,7 +39,7 @@ void main() {
|
||||||
// Delete anything before we start
|
// Delete anything before we start
|
||||||
await testData.remove(<String, dynamic>{});
|
await testData.remove(<String, dynamic>{});
|
||||||
|
|
||||||
var service = MongoService(testData, debug: true);
|
var service = MongoService(testData);
|
||||||
greetingService = HookedService(service);
|
greetingService = HookedService(service);
|
||||||
wireHooked(greetingService!);
|
wireHooked(greetingService!);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue