Updated file_service
This commit is contained in:
parent
16be2e8f94
commit
7287bf12c1
10 changed files with 67 additions and 64 deletions
21
packages/cache/test/pattern_test.dart
vendored
21
packages/cache/test/pattern_test.dart
vendored
|
@ -1,21 +0,0 @@
|
|||
import 'package:glob/glob.dart';
|
||||
import 'package:glob/list_local_fs.dart';
|
||||
|
||||
void main() {
|
||||
/*
|
||||
var filePat = Glob('**.txt');
|
||||
for (var entity in filePat.listSync()) {
|
||||
print(entity.path);
|
||||
}
|
||||
|
||||
var result = filePat.allMatches(path);
|
||||
|
||||
*/
|
||||
|
||||
var path = "ababa99.txt";
|
||||
//var regPat = RegExp('\w+\.txt');
|
||||
var regPat = RegExp('^/?\\w+\\.txt');
|
||||
var result = regPat.allMatches(path);
|
||||
|
||||
print(result.length);
|
||||
}
|
|
@ -1,33 +1,50 @@
|
|||
# 4.0.1
|
||||
# Change Log
|
||||
|
||||
## 4.0.2
|
||||
|
||||
* Updated README
|
||||
* Removed redundant code
|
||||
|
||||
## 4.0.1
|
||||
|
||||
* Updated package description
|
||||
|
||||
# 4.0.0
|
||||
## 4.0.0
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
|
||||
# 3.0.0
|
||||
## 3.0.0
|
||||
|
||||
* Migrated to work with Dart SDK 2.12.x Non NNBD
|
||||
|
||||
# 2.0.1
|
||||
## 2.0.1
|
||||
|
||||
* Pass everything through `_jsonifyToSD` when returning responses.
|
||||
|
||||
# 2.0.0
|
||||
## 2.0.0
|
||||
|
||||
* Dart/Angel 2 update.
|
||||
* Remove `package:dart2_constant`
|
||||
* Update `package:file` to `^5.0.0`.
|
||||
|
||||
# 1.1.2
|
||||
## 1.1.2
|
||||
|
||||
* Added tests, because tests.
|
||||
|
||||
# 1.1.1
|
||||
## 1.1.1
|
||||
|
||||
* Dart 2 fixes.
|
||||
|
||||
# 1.1.0+2
|
||||
## 1.1.0+2
|
||||
|
||||
* `create` now uses the underlying store, instead of manually patching
|
||||
|
||||
# 1.1.0+1
|
||||
## 1.1.0+1
|
||||
|
||||
* Analyzer nitpick for pana
|
||||
|
||||
# 1.1.0
|
||||
## 1.1.0
|
||||
|
||||
* Updated to framework v1.1.x
|
||||
* Use `package:file`
|
||||
* Allow a custom `store`
|
||||
* Allow a custom `store`
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# angel3_file_service
|
||||
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_file_service)
|
||||
# File Service for Angel3
|
||||
|
||||
[![version](https://img.shields.io/badge/pub-v4.0.2-brightgreen)](https://pub.dartlang.org/packages/angel3_file_service)
|
||||
[![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)
|
||||
|
||||
|
@ -20,7 +21,8 @@ if possible, or one with very low load.
|
|||
|
||||
While not necessarily *slow*, this package makes no promises about performance.
|
||||
|
||||
# Usage
|
||||
## Usage
|
||||
|
||||
```dart
|
||||
configureServer(Angel app) async {
|
||||
// Just like a normal service
|
||||
|
@ -31,4 +33,4 @@ configureServer(Angel app) async {
|
|||
),
|
||||
);
|
||||
}
|
||||
```
|
||||
```
|
||||
|
|
|
@ -2,10 +2,10 @@ import 'package:angel3_file_service/angel3_file_service.dart';
|
|||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:file/local.dart';
|
||||
|
||||
configureServer(Angel app) async {
|
||||
void configureServer(Angel app) async {
|
||||
// Just like a normal service
|
||||
app.use(
|
||||
'/api/todos',
|
||||
new JsonFileService(const LocalFileSystem().file('todos_db.json')),
|
||||
JsonFileService(const LocalFileSystem().file('todos_db.json')),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,14 +7,16 @@ import 'package:pool/pool.dart';
|
|||
/// Persists in-memory changes to a file on disk.
|
||||
class JsonFileService extends Service<String, Map<String, dynamic>> {
|
||||
FileStat? _lastStat;
|
||||
final Pool _mutex = new Pool(1);
|
||||
final Pool _mutex = Pool(1);
|
||||
late MapService _store;
|
||||
final File file;
|
||||
|
||||
JsonFileService(this.file,
|
||||
{bool allowRemoveAll: false, bool allowQuery: true, MapService? store}) {
|
||||
{bool allowRemoveAll = false,
|
||||
bool allowQuery = true,
|
||||
MapService? store}) {
|
||||
_store = store ??
|
||||
new MapService(
|
||||
MapService(
|
||||
allowRemoveAll: allowRemoveAll == true,
|
||||
allowQuery: allowQuery != false);
|
||||
}
|
||||
|
@ -45,7 +47,7 @@ class JsonFileService extends Service<String, Map<String, dynamic>> {
|
|||
});
|
||||
}
|
||||
|
||||
_save() {
|
||||
Future<File> _save() {
|
||||
return _mutex.withResource(() {
|
||||
return file
|
||||
.writeAsString(json.encode(_store.items.map(_jsonify).toList()));
|
||||
|
@ -105,17 +107,18 @@ class JsonFileService extends Service<String, Map<String, dynamic>> {
|
|||
}
|
||||
}
|
||||
|
||||
_safeForJson(x) {
|
||||
if (x is DateTime)
|
||||
dynamic _safeForJson(x) {
|
||||
if (x is DateTime) {
|
||||
return x.toIso8601String();
|
||||
else if (x is Map)
|
||||
} else if (x is Map) {
|
||||
return _jsonify(x);
|
||||
else if (x is num || x is String || x is bool || x == null)
|
||||
} else if (x is num || x is String || x is bool || x == null) {
|
||||
return x;
|
||||
else if (x is Iterable)
|
||||
} else if (x is Iterable) {
|
||||
return x.map(_safeForJson).toList();
|
||||
else
|
||||
} else {
|
||||
return x.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Map _jsonify(Map map) {
|
||||
|
@ -129,14 +132,15 @@ dynamic _revive(x) {
|
|||
if (x is Map) {
|
||||
return x.keys.fold<Map<String, dynamic>>(
|
||||
{}, (out, k) => out..[k.toString()] = _revive(x[k]));
|
||||
} else if (x is Iterable)
|
||||
} else if (x is Iterable) {
|
||||
return x.map(_revive).toList();
|
||||
else if (x is String) {
|
||||
} else if (x is String) {
|
||||
try {
|
||||
return DateTime.parse(x);
|
||||
} catch (e) {
|
||||
return x;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel3_file_service
|
||||
version: 4.0.1
|
||||
version: 4.0.2
|
||||
description: Angel service that persists data to a file on disk, stored as a JSON list.
|
||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/file_service
|
||||
environment:
|
||||
|
|
|
@ -9,9 +9,9 @@ void main() {
|
|||
late JsonFileService service;
|
||||
|
||||
setUp(() async {
|
||||
fs = new MemoryFileSystem();
|
||||
fs = MemoryFileSystem();
|
||||
dbFile = fs.file('db.json');
|
||||
service = new JsonFileService(dbFile);
|
||||
service = JsonFileService(dbFile);
|
||||
|
||||
await dbFile.writeAsString('''
|
||||
[
|
||||
|
@ -26,9 +26,9 @@ void main() {
|
|||
|
||||
test('index no params', () async {
|
||||
expect(await service.index(), [
|
||||
{"id": "0", "foo": "bar"},
|
||||
{"id": "1", "foo": "baz"},
|
||||
{"id": "2", "foo": "quux"}
|
||||
{'id': '0', 'foo': 'bar'},
|
||||
{'id': '1', 'foo': 'baz'},
|
||||
{'id': '2', 'foo': 'quux'}
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -38,7 +38,7 @@ void main() {
|
|||
'query': {'foo': 'bar'}
|
||||
}),
|
||||
[
|
||||
{"id": "0", "foo": "bar"}
|
||||
{'id': '0', 'foo': 'bar'}
|
||||
],
|
||||
);
|
||||
});
|
||||
|
@ -46,7 +46,7 @@ void main() {
|
|||
test('read', () async {
|
||||
expect(
|
||||
await service.read('2'),
|
||||
{"id": "2", "foo": "quux"},
|
||||
{'id': '2', 'foo': 'quux'},
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -64,8 +64,8 @@ void main() {
|
|||
test('delete', () async {
|
||||
await service.remove('2');
|
||||
expect(await service.index(), [
|
||||
{"id": "0", "foo": "bar"},
|
||||
{"id": "1", "foo": "baz"}
|
||||
{'id': '0', 'foo': 'bar'},
|
||||
{'id': '1', 'foo': 'baz'}
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,4 +6,5 @@
|
|||
|
||||
## 2.0.0
|
||||
|
||||
* Dart2 + Angel2 update.
|
||||
* Dart2 + Angel2 update.
|
||||
|
|
@ -16,4 +16,4 @@
|
|||
## 2.0.0-alpha
|
||||
|
||||
* Angel 2 updates. Remove previous functionality.
|
||||
* Add `CookieSigner`, `RateLimiter`/`InMemoryRateLimiter`/`ServiceRateLimiter`.
|
||||
* Add `CookieSigner`, `RateLimiter`/`InMemoryRateLimiter`/`ServiceRateLimiter`
|
||||
|
|
|
@ -9,4 +9,4 @@
|
|||
Angel3 middleware designed to enhance application security by patching common Web security
|
||||
holes.
|
||||
|
||||
**This package is currently going through a major overhaul, for version 2.**
|
||||
**This package is currently going through a major overhaul, for version 2.**
|
||||
|
|
Loading…
Reference in a new issue